Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Product.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Catalog\Model;
7 
19 
46 {
51  protected $linkRepository;
52 
57  const ENTITY = 'catalog_product';
58 
62  const CACHE_TAG = 'cat_p';
63 
67  const CACHE_PRODUCT_CATEGORY_TAG = 'cat_c_p';
68 
72  const STORE_ID = 'store_id';
73 
78 
82  protected $_eventPrefix = 'catalog_product';
83 
87  protected $_eventObject = 'product';
88 
92  protected $_canAffectOptions = false;
93 
99  protected $_typeInstance = null;
100 
106  protected $_linkInstance;
107 
113  protected $_customOptions = [];
114 
120  protected $_urlModel = null;
121 
126  protected $_resource;
127 
131  protected static $_url;
132 
136  protected $_errors = [];
137 
143  protected $optionFactory;
144 
150  protected $optionInstance;
151 
155  protected $_links = null;
156 
162  protected $_isDuplicable = true;
163 
169  protected $_calculatePrice = true;
170 
176  protected $_catalogProduct = null;
177 
181  protected $moduleManager;
182 
187 
194 
201 
208 
215 
222 
229 
235  protected $_filesystem;
236 
240  protected $indexerRegistry;
241 
246 
251 
256 
260  protected $_priceInfo;
261 
266 
273 
278 
283  protected $metadataService;
284 
289 
293  protected $linkProvider;
294 
299 
304 
308  protected $dataObjectHelper;
309 
313  protected $_productIdCached;
314 
323 
327  protected $joinProcessor;
328 
335 
341 
346  protected $linkTypeProvider;
347 
351  private $eavConfig;
355  private $filterCustomAttribute;
356 
398  public function __construct(
399  \Magento\Framework\Model\Context $context,
400  \Magento\Framework\Registry $registry,
401  \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
404  \Magento\Catalog\Api\ProductAttributeRepositoryInterface $metadataService,
405  Product\Url $url,
406  Product\Link $productLink,
407  \Magento\Catalog\Model\Product\Configuration\Item\OptionFactory $itemOptionFactory,
408  \Magento\CatalogInventory\Api\Data\StockItemInterfaceFactory $stockItemFactory,
409  \Magento\Catalog\Model\Product\OptionFactory $catalogProductOptionFactory,
410  \Magento\Catalog\Model\Product\Visibility $catalogProductVisibility,
411  \Magento\Catalog\Model\Product\Attribute\Source\Status $catalogProductStatus,
412  \Magento\Catalog\Model\Product\Media\Config $catalogProductMediaConfig,
413  Product\Type $catalogProductType,
414  \Magento\Framework\Module\Manager $moduleManager,
415  \Magento\Catalog\Helper\Product $catalogProduct,
416  \Magento\Catalog\Model\ResourceModel\Product $resource,
417  \Magento\Catalog\Model\ResourceModel\Product\Collection $resourceCollection,
418  \Magento\Framework\Data\CollectionFactory $collectionFactory,
419  \Magento\Framework\Filesystem $filesystem,
420  \Magento\Framework\Indexer\IndexerRegistry $indexerRegistry,
421  \Magento\Catalog\Model\Indexer\Product\Flat\Processor $productFlatIndexerProcessor,
422  \Magento\Catalog\Model\Indexer\Product\Price\Processor $productPriceIndexerProcessor,
423  \Magento\Catalog\Model\Indexer\Product\Eav\Processor $productEavIndexerProcessor,
425  Product\Image\CacheFactory $imageCacheFactory,
426  \Magento\Catalog\Model\ProductLink\CollectionProvider $entityCollectionProvider,
427  \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider,
428  \Magento\Catalog\Api\Data\ProductLinkInterfaceFactory $productLinkFactory,
429  \Magento\Catalog\Api\Data\ProductLinkExtensionFactory $productLinkExtensionFactory,
431  \Magento\Framework\Api\DataObjectHelper $dataObjectHelper,
432  \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $joinProcessor,
433  array $data = [],
434  \Magento\Eav\Model\Config $config = null,
435  FilterProductCustomAttribute $filterCustomAttribute = null
436  ) {
437  $this->metadataService = $metadataService;
438  $this->_itemOptionFactory = $itemOptionFactory;
439  $this->_stockItemFactory = $stockItemFactory;
440  $this->optionFactory = $catalogProductOptionFactory;
441  $this->_catalogProductVisibility = $catalogProductVisibility;
442  $this->_catalogProductStatus = $catalogProductStatus;
443  $this->_catalogProductMediaConfig = $catalogProductMediaConfig;
444  $this->_catalogProductType = $catalogProductType;
445  $this->moduleManager = $moduleManager;
446  $this->_catalogProduct = $catalogProduct;
447  $this->_collectionFactory = $collectionFactory;
448  $this->_urlModel = $url;
449  $this->_linkInstance = $productLink;
450  $this->_filesystem = $filesystem;
451  $this->indexerRegistry = $indexerRegistry;
452  $this->_productFlatIndexerProcessor = $productFlatIndexerProcessor;
453  $this->_productPriceIndexerProcessor = $productPriceIndexerProcessor;
454  $this->_productEavIndexerProcessor = $productEavIndexerProcessor;
455  $this->categoryRepository = $categoryRepository;
456  $this->imageCacheFactory = $imageCacheFactory;
457  $this->entityCollectionProvider = $entityCollectionProvider;
458  $this->linkTypeProvider = $linkTypeProvider;
459  $this->productLinkFactory = $productLinkFactory;
460  $this->productLinkExtensionFactory = $productLinkExtensionFactory;
461  $this->mediaGalleryEntryConverterPool = $mediaGalleryEntryConverterPool;
462  $this->dataObjectHelper = $dataObjectHelper;
463  $this->joinProcessor = $joinProcessor;
464  parent::__construct(
465  $context,
466  $registry,
467  $extensionFactory,
470  $resource,
471  $resourceCollection,
472  $data
473  );
474  $this->eavConfig = $config ?? ObjectManager::getInstance()->get(\Magento\Eav\Model\Config::class);
475  $this->filterCustomAttribute = $filterCustomAttribute
476  ?? ObjectManager::getInstance()->get(FilterProductCustomAttribute::class);
477  }
478 
484  protected function _construct()
485  {
486  $this->_init(\Magento\Catalog\Model\ResourceModel\Product::class);
487  }
488 
497  protected function _getResource()
498  {
499  return parent::_getResource();
500  }
501 
509  protected function getCustomAttributesCodes()
510  {
511  if ($this->customAttributesCodes === null) {
512  $this->customAttributesCodes = array_diff(
513  array_keys(
514  $this->filterCustomAttribute->execute(
515  $this->eavConfig->getEntityAttributes(
516  self::ENTITY,
517  $this
518  )
519  )
520  ),
522  );
523  }
524 
526  }
527 
533  public function getStoreId()
534  {
535  if ($this->hasData(self::STORE_ID)) {
536  return $this->getData(self::STORE_ID);
537  }
538  return $this->_storeManager->getStore()->getId();
539  }
540 
546  public function getUrlModel()
547  {
548  return $this->_urlModel;
549  }
550 
558  public function validate()
559  {
560  $this->_eventManager->dispatch($this->_eventPrefix . '_validate_before', $this->_getEventData());
561  $result = $this->_getResource()->validate($this);
562  $this->_eventManager->dispatch($this->_eventPrefix . '_validate_after', $this->_getEventData());
563  return $result;
564  }
565 
572  public function getName()
573  {
574  return $this->_getData(self::NAME);
575  }
576 
577  //@codeCoverageIgnoreEnd
578 
584  public function getPrice()
585  {
586  if ($this->_calculatePrice || !$this->getData(self::PRICE)) {
587  return $this->getPriceModel()->getPrice($this);
588  } else {
589  return $this->getData(self::PRICE);
590  }
591  }
592 
601  public function getVisibility()
602  {
603  return $this->_getData(self::VISIBILITY);
604  }
605 
611  public function getAttributeSetId()
612  {
613  return $this->_getData(self::ATTRIBUTE_SET_ID);
614  }
615 
621  public function getCreatedAt()
622  {
623  return $this->_getData(self::CREATED_AT);
624  }
625 
631  public function getUpdatedAt()
632  {
633  return $this->_getData(self::UPDATED_AT);
634  }
635 
643  public function setPriceCalculation($calculate = true)
644  {
645  $this->_calculatePrice = $calculate;
646  }
647 
653  public function getTypeId()
654  {
655  return $this->_getData(self::TYPE_ID);
656  }
657 
658  //@codeCoverageIgnoreEnd
659 
665  public function getStatus()
666  {
667  $status = $this->_getData(self::STATUS);
668  return $status !== null ? $status : \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED;
669  }
670 
678  public function getTypeInstance()
679  {
680  if ($this->_typeInstance === null) {
681  $this->_typeInstance = $this->_catalogProductType->factory($this);
682  }
683  return $this->_typeInstance;
684  }
685 
692  public function setTypeInstance($instance)
693  {
694  $this->_typeInstance = $instance;
695  return $this;
696  }
697 
703  public function getLinkInstance()
704  {
705  return $this->_linkInstance;
706  }
707 
714  public function getIdBySku($sku)
715  {
716  return $this->_getResource()->getIdBySku($sku);
717  }
718 
724  public function getCategoryId()
725  {
726  $category = $this->_registry->registry('current_category');
727  if ($category) {
728  return $category->getId();
729  }
730  return false;
731  }
732 
738  public function getCategory()
739  {
740  $category = $this->getData('category');
741  if ($category === null && $this->getCategoryId()) {
742  $category = $this->categoryRepository->get($this->getCategoryId());
743  $this->setCategory($category);
744  }
745  return $category;
746  }
747 
753  public function getCategoryIds()
754  {
755  if (!$this->hasData('category_ids')) {
756  $wasLocked = false;
757  if ($this->isLockedAttribute('category_ids')) {
758  $wasLocked = true;
759  $this->unlockAttribute('category_ids');
760  }
761  $ids = $this->_getResource()->getCategoryIds($this);
762  $this->setData('category_ids', $ids);
763  if ($wasLocked) {
764  $this->lockAttribute('category_ids');
765  }
766  }
767 
768  return (array) $this->_getData('category_ids');
769  }
770 
776  public function getCategoryCollection()
777  {
778  if ($this->categoryCollection === null || $this->getId() != $this->_productIdCached) {
779  $categoryCollection = $this->_getResource()->getCategoryCollection($this);
781  $this->_productIdCached = $this->getId();
782  }
784  }
785 
792  protected function setCategoryCollection(\Magento\Framework\Data\Collection $categoryCollection)
793  {
794  $this->categoryCollection = $categoryCollection;
795  return $this;
796  }
797 
803  public function getWebsiteIds()
804  {
805  if (!$this->hasWebsiteIds()) {
806  $ids = $this->_getResource()->getWebsiteIds($this);
807  $this->setWebsiteIds($ids);
808  }
809  return $this->getData('website_ids');
810  }
811 
817  public function getStoreIds()
818  {
819  if (!$this->hasStoreIds()) {
820  $storeIds = [];
821  if ($websiteIds = $this->getWebsiteIds()) {
822  foreach ($websiteIds as $websiteId) {
823  $websiteStores = $this->_storeManager->getWebsite($websiteId)->getStoreIds();
824  $storeIds = array_merge($storeIds, $websiteStores);
825  }
826  }
827  $this->setStoreIds($storeIds);
828  }
829  return $this->getData('store_ids');
830  }
831 
842  public function getAttributes($groupId = null, $skipSuper = false)
843  {
844  $productAttributes = $this->getTypeInstance()->getSetAttributes($this);
845  if ($groupId) {
846  $attributes = [];
847  foreach ($productAttributes as $attribute) {
848  if ($attribute->isInGroup($this->getAttributeSetId(), $groupId)) {
850  }
851  }
852  } else {
853  $attributes = $productAttributes;
854  }
855 
856  return $attributes;
857  }
858 
866  public function beforeSave()
867  {
868  $this->cleanCache();
869  $this->setTypeHasOptions(false);
870  $this->setTypeHasRequiredOptions(false);
871  $this->setHasOptions(false);
872  $this->setRequiredOptions(false);
873 
874  $this->getTypeInstance()->beforeSave($this);
875 
876  $hasOptions = false;
877  $hasRequiredOptions = false;
878 
884  $this->canAffectOptions($this->_canAffectOptions && $this->getCanSaveCustomOptions());
885  if ($this->getCanSaveCustomOptions()) {
886  $options = $this->getOptions();
887  if (is_array($options)) {
888  $this->setIsCustomOptionChanged(true);
889  foreach ($options as $option) {
890  if ($option instanceof \Magento\Catalog\Api\Data\ProductCustomOptionInterface) {
891  $option = $option->getData();
892  }
893  if (!isset($option['is_delete']) || $option['is_delete'] != '1') {
894  $hasOptions = true;
895  }
896  if ($option['is_require'] == '1') {
897  $hasRequiredOptions = true;
898  break;
899  }
900  }
901  }
902  }
903 
908  if ($hasOptions || (bool)$this->getTypeHasOptions()) {
909  $this->setHasOptions(true);
910  if ($hasRequiredOptions || (bool)$this->getTypeHasRequiredOptions()) {
911  $this->setRequiredOptions(true);
912  } elseif ($this->canAffectOptions()) {
913  $this->setRequiredOptions(false);
914  }
915  } elseif ($this->canAffectOptions()) {
916  $this->setHasOptions(false);
917  $this->setRequiredOptions(false);
918  }
919 
920  if (!$this->getOrigData('website_ids')) {
921  $websiteIds = $this->_getResource()->getWebsiteIds($this);
922  $this->setOrigData('website_ids', $websiteIds);
923  }
924  parent::beforeSave();
925  }
926 
935  public function canAffectOptions($value = null)
936  {
937  if (null !== $value) {
938  $this->_canAffectOptions = (bool) $value;
939  }
941  }
942 
948  public function afterSave()
949  {
950  $this->getLinkInstance()->saveProductRelations($this);
951  $this->getTypeInstance()->save($this);
952 
953  if ($this->getStockData()) {
954  $this->setForceReindexEavRequired(true);
955  }
956 
957  $this->_getResource()->addCommitCallback([$this, 'priceReindexCallback']);
958  $this->_getResource()->addCommitCallback([$this, 'eavReindexCallback']);
959 
960  $result = parent::afterSave();
961 
962  $this->_getResource()->addCommitCallback([$this, 'reindex']);
963  $this->reloadPriceInfo();
964 
965  return $result;
966  }
967 
974  public function setQty($qty)
975  {
976  if ($this->getData('qty') != $qty) {
977  $this->setData('qty', $qty);
978  $this->reloadPriceInfo();
979  }
980  return $this;
981  }
982 
988  public function getQty()
989  {
990  return $this->getData('qty');
991  }
992 
998  public function priceReindexCallback()
999  {
1000  if ($this->isObjectNew() || $this->_catalogProduct->isDataForPriceIndexerWasChanged($this)) {
1001  $this->_productPriceIndexerProcessor->reindexRow($this->getEntityId());
1002  }
1003  }
1004 
1010  public function eavReindexCallback()
1011  {
1012  if ($this->isObjectNew() || $this->isDataChanged($this)) {
1013  $this->_productEavIndexerProcessor->reindexRow($this->getEntityId());
1014  }
1015  }
1016 
1022  public function isDataChanged()
1023  {
1024  foreach (array_keys($this->getData()) as $field) {
1025  if ($this->dataHasChangedFor($field)) {
1026  return true;
1027  }
1028  }
1029  return false;
1030  }
1031 
1037  public function reindex()
1038  {
1039  if ($this->_catalogProduct->isDataForProductCategoryIndexerWasChanged($this) || $this->isDeleted()) {
1040  $productCategoryIndexer = $this->indexerRegistry->get(Indexer\Product\Category::INDEXER_ID);
1041  if (!$productCategoryIndexer->isScheduled()) {
1042  $productCategoryIndexer->reindexRow($this->getId());
1043  }
1044  }
1045  $this->_productFlatIndexerProcessor->reindexRow($this->getEntityId());
1046  }
1047 
1056  public function beforeDelete()
1057  {
1058  $this->cleanCache();
1059  return parent::beforeDelete();
1060  }
1061 
1067  public function afterDeleteCommit()
1068  {
1069  $this->reindex();
1070  $this->_productPriceIndexerProcessor->reindexRow($this->getId());
1071  parent::afterDeleteCommit();
1072  }
1073 
1079  protected function _afterLoad()
1080  {
1081  if (!$this->hasData(self::STATUS)) {
1082  $this->setData(self::STATUS, \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED);
1083  }
1084  parent::_afterLoad();
1085  return $this;
1086  }
1087 
1093  public function cleanCache()
1094  {
1095  $this->_cacheManager->clean('catalog_product_' . $this->getId());
1096  return $this;
1097  }
1098 
1104  public function getPriceModel()
1105  {
1106  return $this->_catalogProductType->priceFactory($this->getTypeId());
1107  }
1108 
1114  public function getPriceInfo()
1115  {
1116  if (!$this->_priceInfo) {
1117  $this->_priceInfo = $this->_catalogProductType->getPriceInfo($this);
1118  }
1119  return $this->_priceInfo;
1120  }
1121 
1127  public function getTierPrices()
1128  {
1129  return $this->getPriceModel()->getTierPrices($this);
1130  }
1131 
1138  public function setTierPrices(array $tierPrices = null)
1139  {
1140  $this->getPriceModel()->setTierPrices($this, $tierPrices);
1141  return $this;
1142  }
1143 
1150  public function getTierPrice($qty = null)
1151  {
1152  return $this->getPriceModel()->getTierPrice($qty, $this);
1153  }
1154 
1161  public function getFormattedPrice()
1162  {
1163  return $this->getPriceModel()->getFormattedPrice($this);
1164  }
1165 
1174  public function getFormatedPrice()
1175  {
1176  return $this->getFormattedPrice();
1177  }
1178 
1189  public function setFinalPrice($price)
1190  {
1191  $this->_data['final_price'] = $price;
1192  return $this;
1193  }
1194 
1201  public function getFinalPrice($qty = null)
1202  {
1203  if ($this->_calculatePrice || $this->_getData('final_price') === null) {
1204  return $this->getPriceModel()->getFinalPrice($qty, $this);
1205  } else {
1206  return $this->_getData('final_price');
1207  }
1208  }
1209 
1215  public function getCalculatedFinalPrice()
1216  {
1217  return $this->_getData('calculated_final_price');
1218  }
1219 
1225  public function getMinimalPrice()
1226  {
1227  return max($this->_getData('minimal_price'), 0);
1228  }
1229 
1235  public function getSpecialPrice()
1236  {
1237  return $this->_getData('special_price');
1238  }
1239 
1245  public function getSpecialFromDate()
1246  {
1247  return $this->_getData('special_from_date');
1248  }
1249 
1255  public function getSpecialToDate()
1256  {
1257  return $this->_getData('special_to_date');
1258  }
1259 
1265  public function getRelatedProducts()
1266  {
1267  if (!$this->hasRelatedProducts()) {
1268  $products = [];
1270  foreach ($collection as $product) {
1271  $products[] = $product;
1272  }
1273  $this->setRelatedProducts($products);
1274  }
1275  return $this->getData('related_products');
1276  }
1277 
1283  public function getRelatedProductIds()
1284  {
1285  if (!$this->hasRelatedProductIds()) {
1286  $ids = [];
1287  foreach ($this->getRelatedProducts() as $product) {
1288  $ids[] = $product->getId();
1289  }
1290  $this->setRelatedProductIds($ids);
1291  }
1292  return $this->getData('related_product_ids');
1293  }
1294 
1301  {
1302  $collection = $this->getLinkInstance()->useRelatedLinks()->getProductCollection()->setIsStrongMode();
1303  $collection->setProduct($this);
1304  return $collection;
1305  }
1306 
1312  public function getRelatedLinkCollection()
1313  {
1314  $collection = $this->getLinkInstance()->useRelatedLinks()->getLinkCollection();
1315  $collection->setProduct($this);
1316  $collection->addLinkTypeIdFilter();
1317  $collection->addProductIdFilter();
1318  $collection->joinAttributes();
1319  return $collection;
1320  }
1321 
1327  public function getUpSellProducts()
1328  {
1329  if (!$this->hasUpSellProducts()) {
1330  $products = [];
1331  foreach ($this->getUpSellProductCollection() as $product) {
1332  $products[] = $product;
1333  }
1334  $this->setUpSellProducts($products);
1335  }
1336  return $this->getData('up_sell_products');
1337  }
1338 
1344  public function getUpSellProductIds()
1345  {
1346  if (!$this->hasUpSellProductIds()) {
1347  $ids = [];
1348  foreach ($this->getUpSellProducts() as $product) {
1349  $ids[] = $product->getId();
1350  }
1351  $this->setUpSellProductIds($ids);
1352  }
1353  return $this->getData('up_sell_product_ids');
1354  }
1355 
1361  public function getUpSellProductCollection()
1362  {
1363  $collection = $this->getLinkInstance()->useUpSellLinks()->getProductCollection()->setIsStrongMode();
1364  $collection->setProduct($this);
1365  return $collection;
1366  }
1367 
1373  public function getUpSellLinkCollection()
1374  {
1375  $collection = $this->getLinkInstance()->useUpSellLinks()->getLinkCollection();
1376  $collection->setProduct($this);
1377  $collection->addLinkTypeIdFilter();
1378  $collection->addProductIdFilter();
1379  $collection->joinAttributes();
1380  return $collection;
1381  }
1382 
1388  public function getCrossSellProducts()
1389  {
1390  if (!$this->hasCrossSellProducts()) {
1391  $products = [];
1392  foreach ($this->getCrossSellProductCollection() as $product) {
1393  $products[] = $product;
1394  }
1395  $this->setCrossSellProducts($products);
1396  }
1397  return $this->getData('cross_sell_products');
1398  }
1399 
1405  public function getCrossSellProductIds()
1406  {
1407  if (!$this->hasCrossSellProductIds()) {
1408  $ids = [];
1409  foreach ($this->getCrossSellProducts() as $product) {
1410  $ids[] = $product->getId();
1411  }
1412  $this->setCrossSellProductIds($ids);
1413  }
1414  return $this->getData('cross_sell_product_ids');
1415  }
1416 
1423  {
1424  $collection = $this->getLinkInstance()->useCrossSellLinks()->getProductCollection()->setIsStrongMode();
1425  $collection->setProduct($this);
1426  return $collection;
1427  }
1428 
1434  public function getCrossSellLinkCollection()
1435  {
1436  $collection = $this->getLinkInstance()->useCrossSellLinks()->getLinkCollection();
1437  $collection->setProduct($this);
1438  $collection->addLinkTypeIdFilter();
1439  $collection->addProductIdFilter();
1440  $collection->joinAttributes();
1441  return $collection;
1442  }
1443 
1449  public function getProductLinks()
1450  {
1451  if ($this->_links === null) {
1452  $this->_links = $this->getLinkRepository()->getList($this);
1453  }
1454  return $this->_links;
1455  }
1456 
1463  public function setProductLinks(array $links = null)
1464  {
1465  if ($links === null) {
1466  $this->setData('ignore_links_flag', true);
1467  } else {
1468  $this->setData('ignore_links_flag', false);
1469  }
1470  $this->_links = $links;
1471  return $this;
1472  }
1473 
1479  public function getMediaAttributes()
1480  {
1481  if (!$this->hasMediaAttributes()) {
1482  $mediaAttributes = [];
1483  foreach ($this->getAttributes() as $attribute) {
1484  if ($attribute->getFrontend()->getInputType() == 'media_image') {
1485  $mediaAttributes[$attribute->getAttributeCode()] = $attribute;
1486  }
1487  }
1488  $this->setMediaAttributes($mediaAttributes);
1489  }
1490  return $this->getData('media_attributes');
1491  }
1492 
1498  public function getMediaAttributeValues()
1499  {
1500  $mediaAttributeCodes = $this->_catalogProductMediaConfig->getMediaAttributeCodes();
1501  $mediaAttributeValues = [];
1502  foreach ($mediaAttributeCodes as $attributeCode) {
1503  $mediaAttributeValues[$attributeCode] = $this->getData($attributeCode);
1504  }
1505  return $mediaAttributeValues;
1506  }
1507 
1513  public function getMediaGalleryImages()
1514  {
1515  $directory = $this->_filesystem->getDirectoryRead(DirectoryList::MEDIA);
1516  if (!$this->hasData('media_gallery_images')) {
1517  $this->setData('media_gallery_images', $this->_collectionFactory->create());
1518  }
1519  if (!$this->getData('media_gallery_images')->count() && is_array($this->getMediaGallery('images'))) {
1520  $images = $this->getData('media_gallery_images');
1521  foreach ($this->getMediaGallery('images') as $image) {
1522  if (!empty($image['disabled'])
1523  || !empty($image['removed'])
1524  || empty($image['value_id'])
1525  || $images->getItemById($image['value_id']) != null
1526  ) {
1527  continue;
1528  }
1529  $image['url'] = $this->getMediaConfig()->getMediaUrl($image['file']);
1530  $image['id'] = $image['value_id'];
1531  $image['path'] = $directory->getAbsolutePath($this->getMediaConfig()->getMediaPath($image['file']));
1532  $images->addItem(new \Magento\Framework\DataObject($image));
1533  }
1534  $this->setData('media_gallery_images', $images);
1535  }
1536 
1537  return $this->getData('media_gallery_images');
1538  }
1539 
1546  public function hasGalleryAttribute()
1547  {
1548  $attributes = $this->getAttributes();
1549 
1550  if (!isset($attributes['media_gallery'])
1551  || !($attributes['media_gallery'] instanceof \Magento\Eav\Model\Entity\Attribute\AbstractAttribute)
1552  ) {
1553  return false;
1554  }
1555 
1556  return true;
1557  }
1558 
1569  public function addImageToMediaGallery($file, $mediaAttribute = null, $move = false, $exclude = true)
1570  {
1571  if ($this->hasGalleryAttribute()) {
1572  $this->getMediaGalleryProcessor()->addImage(
1573  $this,
1574  $file,
1575  $mediaAttribute,
1576  $move,
1577  $exclude
1578  );
1579  }
1580 
1581  return $this;
1582  }
1583 
1589  public function getMediaConfig()
1590  {
1592  }
1593 
1600  {
1601  return $this->_catalogProductStatus->getVisibleStatusIds();
1602  }
1603 
1609  public function getVisibleStatuses()
1610  {
1611  return $this->_catalogProductStatus->getVisibleStatusIds();
1612  }
1613 
1619  public function isVisibleInCatalog()
1620  {
1621  return in_array($this->getStatus(), $this->getVisibleInCatalogStatuses());
1622  }
1623 
1630  {
1631  return $this->_catalogProductVisibility->getVisibleInSiteIds();
1632  }
1633 
1639  public function isVisibleInSiteVisibility()
1640  {
1641  return in_array($this->getVisibility(), $this->getVisibleInSiteVisibilities());
1642  }
1643 
1649  public function isDuplicable()
1650  {
1651  return $this->_isDuplicable;
1652  }
1653 
1660  public function setIsDuplicable($value)
1661  {
1662  $this->_isDuplicable = (bool)$value;
1663  return $this;
1664  }
1665 
1671  public function isSalable()
1672  {
1673  if ($this->_catalogProduct->getSkipSaleableCheck()) {
1674  return true;
1675  }
1676  if (($this->getOrigData('status') != $this->getData('status'))
1677  || $this->isStockStatusChanged()) {
1678  $this->unsetData('salable');
1679  }
1680 
1681  if ($this->hasData('salable')) {
1682  return $this->getData('salable');
1683  }
1684  $this->_eventManager->dispatch('catalog_product_is_salable_before', ['product' => $this]);
1685 
1686  $salable = $this->isAvailable();
1687 
1688  $object = new \Magento\Framework\DataObject(['product' => $this, 'is_salable' => $salable]);
1689  $this->_eventManager->dispatch(
1690  'catalog_product_is_salable_after',
1691  ['product' => $this, 'salable' => $object]
1692  );
1693  $this->setData('salable', $object->getIsSalable());
1694  return $this->getData('salable');
1695  }
1696 
1702  public function isAvailable()
1703  {
1704  return $this->_catalogProduct->getSkipSaleableCheck() || $this->getTypeInstance()->isSalable($this);
1705  }
1706 
1713  public function getIsSalable()
1714  {
1715  $productType = $this->getTypeInstance();
1716  if (method_exists($productType, 'getIsSalable')) {
1717  return $productType->getIsSalable($this);
1718  }
1719  if ($this->hasData('is_saleable')) {
1720  return $this->getData('is_saleable');
1721  }
1722 
1723  return $this->isSalable();
1724  }
1725 
1731  public function isVirtual()
1732  {
1733  return $this->getIsVirtual();
1734  }
1735 
1741  public function isSaleable()
1742  {
1743  return $this->isSalable();
1744  }
1745 
1751  public function isInStock()
1752  {
1753  return $this->getStatus() == \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED;
1754  }
1755 
1763  {
1764  return $this->getResource()->getAttribute($attributeCode)->getSource()->getOptionText(
1765  $this->getData($attributeCode)
1766  );
1767  }
1768 
1774  public function getCustomDesignDate()
1775  {
1776  $result = [];
1777  $result['from'] = $this->getData('custom_design_from');
1778  $result['to'] = $this->getData('custom_design_to');
1779 
1780  return $result;
1781  }
1782 
1789  public function getProductUrl($useSid = null)
1790  {
1791  return $this->getUrlModel()->getProductUrl($this, $useSid);
1792  }
1793 
1800  public function getUrlInStore($params = [])
1801  {
1802  return $this->getUrlModel()->getUrlInStore($this, $params);
1803  }
1804 
1811  public function formatUrlKey($str)
1812  {
1813  return $this->getUrlModel()->formatUrlKey($str);
1814  }
1815 
1825  {
1826  $oldValue = $this->getData($code);
1827  $oldStore = $this->getStoreId();
1828 
1829  $this->setData($code, $value);
1830  $this->setStoreId($store);
1831  $this->getResource()->saveAttribute($this, $code);
1832 
1833  $this->setData($code, $oldValue);
1834  $this->setStoreId($oldStore);
1835  }
1836 
1843  public function toArray(array $arrAttributes = [])
1844  {
1845  $data = parent::toArray($arrAttributes);
1846  $stock = $this->getStockItem();
1847  if ($stock) {
1848  $data['stock_item'] = $stock->toArray();
1849  }
1850  unset($data['stock_item']['product']);
1851  return $data;
1852  }
1853 
1860  public function fromArray(array $data)
1861  {
1862  if (isset($data['stock_item'])) {
1863  if ($this->moduleManager->isEnabled('Magento_CatalogInventory')) {
1864  $stockItem = $this->_stockItemFactory->create();
1865  $this->dataObjectHelper->populateWithArray(
1866  $stockItem,
1867  $data['stock_item'],
1868  \Magento\CatalogInventory\Api\Data\StockItemInterface::class
1869  );
1870  $stockItem->setProduct($this);
1871  $this->setStockItem($stockItem);
1872  }
1873  unset($data['stock_item']);
1874  }
1875  $this->setData($data);
1876  return $this;
1877  }
1878 
1884  public function getRequestPath()
1885  {
1886  return $this->_getData('request_path');
1887  }
1888 
1894  public function getGiftMessageAvailable()
1895  {
1896  return $this->_getData('gift_message_available');
1897  }
1898 
1904  public function isComposite()
1905  {
1906  return $this->getTypeInstance()->isComposite($this);
1907  }
1908 
1914  public function canConfigure()
1915  {
1916  $options = $this->getOptions();
1917  return !empty($options) || $this->getTypeInstance()->canConfigure($this);
1918  }
1919 
1925  public function getSku()
1926  {
1927  return $this->getTypeInstance()->getSku($this);
1928  }
1929 
1935  public function getWeight()
1936  {
1937  return $this->getTypeInstance()->getWeight($this);
1938  }
1939 
1945  public function getOptionInstance()
1946  {
1947  if (!isset($this->optionInstance)) {
1948  $this->optionInstance = $this->optionFactory->create();
1949  $this->optionInstance->setProduct($this);
1950  }
1951  return $this->optionInstance;
1952  }
1953 
1960  public function addOption(Product\Option $option)
1961  {
1962  $options = (array)$this->getData('options');
1963  $options[] = $option;
1964  $option->setProduct($this);
1965  $this->setData('options', $options);
1966  return $this;
1967  }
1968 
1975  public function getOptionById($optionId)
1976  {
1977  if (is_array($this->getOptions())) {
1979  foreach ($this->getOptions() as $option) {
1980  if ($option->getId() == $optionId) {
1981  return $option;
1982  }
1983  }
1984  }
1985 
1986  return null;
1987  }
1988 
1995  {
1996  return $this->getOptionInstance()->getProductOptionCollection($this);
1997  }
1998 
2004  public function getOptions()
2005  {
2006  return $this->getData('options');
2007  }
2008 
2015  public function setOptions(array $options = null)
2016  {
2017  $this->setData('options', $options);
2018  return $this;
2019  }
2020 
2027  public function getIsVirtual()
2028  {
2029  return $this->getTypeInstance()->isVirtual($this);
2030  }
2031 
2040  public function addCustomOption($code, $value, $product = null)
2041  {
2042  $product = $product ?: $this;
2043  $option = $this->_itemOptionFactory->create()->addData(
2044  ['product_id' => $product->getId(), 'product' => $product, 'code' => $code, 'value' => $value]
2045  );
2046  $this->_customOptions[$code] = $option;
2047  return $this;
2048  }
2049 
2056  public function setCustomOptions(array $options)
2057  {
2058  $this->_customOptions = $options;
2059  }
2060 
2066  public function getCustomOptions()
2067  {
2068  return $this->_customOptions;
2069  }
2070 
2077  public function getCustomOption($code)
2078  {
2079  if (isset($this->_customOptions[$code])) {
2080  return $this->_customOptions[$code];
2081  }
2082  return null;
2083  }
2084 
2090  public function hasCustomOptions()
2091  {
2092  if (count($this->_customOptions)) {
2093  return true;
2094  } else {
2095  return false;
2096  }
2097  }
2098 
2105  public function canBeShowInCategory($categoryId)
2106  {
2107  return $this->_getResource()->canBeShowInCategory($this, $categoryId);
2108  }
2109 
2115  public function getAvailableInCategories()
2116  {
2117  return $this->_getResource()->getAvailableInCategories($this);
2118  }
2119 
2125  public function getDefaultAttributeSetId()
2126  {
2127  return $this->getResource()->getEntityType()->getDefaultAttributeSetId();
2128  }
2129 
2135  public function reset()
2136  {
2137  $this->unlockAttributes();
2138  $this->_clearData();
2139  return $this;
2140  }
2141 
2149  public function getCacheIdTags()
2150  {
2151  $tags = parent::getCacheIdTags();
2152  $affectedCategoryIds = $this->getAffectedCategoryIds();
2153  if (!$affectedCategoryIds) {
2154  $affectedCategoryIds = $this->getCategoryIds();
2155  }
2156  foreach ($affectedCategoryIds as $categoryId) {
2157  $tags[] = \Magento\Catalog\Model\Category::CACHE_TAG . '_' . $categoryId;
2158  }
2159  return $tags;
2160  }
2161 
2168  public function isProductsHasSku(array $productIds)
2169  {
2170  $products = $this->_getResource()->getProductsSku($productIds);
2171  if (count($products)) {
2172  foreach ($products as $product) {
2173  if (!strlen($product['sku'])) {
2174  return false;
2175  }
2176  }
2177  return true;
2178  }
2179  return null;
2180  }
2181 
2188  public function processBuyRequest(\Magento\Framework\DataObject $buyRequest)
2189  {
2190  $options = new \Magento\Framework\DataObject();
2191 
2192  /* add product custom options data */
2193  $customOptions = $buyRequest->getOptions();
2194  if (is_array($customOptions)) {
2195  array_filter(
2197  function ($value) {
2198  return $value !== '';
2199  }
2200  );
2201  $options->setOptions($customOptions);
2202  }
2203 
2204  /* add product type selected options data */
2205  $type = $this->getTypeInstance();
2206  $typeSpecificOptions = $type->processBuyRequest($this, $buyRequest);
2207  $options->addData($typeSpecificOptions);
2208 
2209  /* check correctness of product's options */
2210  $options->setErrors($type->checkProductConfiguration($this, $buyRequest));
2211 
2212  return $options;
2213  }
2214 
2220  public function getPreconfiguredValues()
2221  {
2222  $preConfiguredValues = $this->getData('preconfigured_values');
2223  if (!$preConfiguredValues) {
2224  $preConfiguredValues = new \Magento\Framework\DataObject();
2225  }
2226 
2227  return $preConfiguredValues;
2228  }
2229 
2237  public function prepareCustomOptions()
2238  {
2239  foreach ($this->getCustomOptions() as $option) {
2240  if (!is_object($option->getProduct()) || $option->getId()) {
2241  $this->addCustomOption($option->getCode(), $option->getValue());
2242  }
2243  }
2244 
2245  return $this;
2246  }
2247 
2253  protected function _clearReferences()
2254  {
2255  $this->_clearOptionReferences();
2256  return $this;
2257  }
2258 
2264  protected function _clearData()
2265  {
2266  foreach ($this->_data as $data) {
2267  if (is_object($data) && method_exists($data, 'reset') && is_callable([$data, 'reset'])) {
2268  $data->reset();
2269  }
2270  }
2271 
2272  $this->setData([]);
2273  $this->setOrigData();
2274  $this->_customOptions = [];
2275  $this->_canAffectOptions = false;
2276  $this->_errors = [];
2277 
2278  return $this;
2279  }
2280 
2286  protected function _clearOptionReferences()
2287  {
2291  if (!empty($this->getOptions())) {
2293  foreach ($this->getOptions() as $option) {
2294  $option->setProduct();
2295  $option->clearInstance();
2296  }
2297  }
2298 
2299  return $this;
2300  }
2301 
2308  public function getProductEntitiesInfo($columns = null)
2309  {
2310  return $this->_getResource()->getProductEntitiesInfo($columns);
2311  }
2312 
2318  public function isDisabled()
2319  {
2320  return $this->getStatus() == \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED;
2321  }
2322 
2328  public function getImage()
2329  {
2330  $this->getTypeInstance()->setImageFromChildProduct($this);
2331  return parent::getImage();
2332  }
2333 
2339  public function getIdentities()
2340  {
2341  $identities = [self::CACHE_TAG . '_' . $this->getId()];
2342  if ($this->getIsChangedCategories()) {
2343  foreach ($this->getAffectedCategoryIds() as $categoryId) {
2344  $identities[] = self::CACHE_PRODUCT_CATEGORY_TAG . '_' . $categoryId;
2345  }
2346  }
2347 
2348  if (($this->getOrigData('status') != $this->getData('status')) || $this->isStockStatusChanged()) {
2349  foreach ($this->getCategoryIds() as $categoryId) {
2350  $identities[] = self::CACHE_PRODUCT_CATEGORY_TAG . '_' . $categoryId;
2351  }
2352  }
2353  if ($this->_appState->getAreaCode() == \Magento\Framework\App\Area::AREA_FRONTEND) {
2354  $identities[] = self::CACHE_TAG;
2355  }
2356 
2357  return array_unique($identities);
2358  }
2359 
2365  private function isStockStatusChanged()
2366  {
2367  $stockItem = null;
2368  $extendedAttributes = $this->getExtensionAttributes();
2369  if ($extendedAttributes !== null) {
2370  $stockItem = $extendedAttributes->getStockItem();
2371  }
2372  $stockData = $this->getStockData();
2373  return (
2374  (is_array($stockData))
2375  && array_key_exists('is_in_stock', $stockData)
2376  && (null !== $stockItem)
2377  && ($stockItem->getIsInStock() != $stockData['is_in_stock'])
2378  );
2379  }
2380 
2386  public function reloadPriceInfo()
2387  {
2388  if ($this->_priceInfo) {
2389  $this->_priceInfo = null;
2390  return $this->getPriceInfo();
2391  }
2392  }
2393 
2400  public function __toArray()
2401  {
2402  $data = $this->_data;
2403  $hasToArray = function ($model) {
2404  return is_object($model) && method_exists($model, '__toArray') && is_callable([$model, '__toArray']);
2405  };
2406  foreach ($data as $key => $value) {
2407  if ($hasToArray($value)) {
2408  $data[$key] = $value->__toArray();
2409  } elseif (is_array($value)) {
2410  foreach ($value as $nestedKey => $nestedValue) {
2411  if ($hasToArray($nestedValue)) {
2412  $value[$nestedKey] = $nestedValue->__toArray();
2413  }
2414  }
2415  $data[$key] = $value;
2416  }
2417  }
2418  return $data;
2419  }
2420 
2426  public function toFlatArray()
2427  {
2428  $dataArray = $this->__toArray();
2429  //process custom attributes if present
2430  if (array_key_exists('custom_attributes', $dataArray) && !empty($dataArray['custom_attributes'])) {
2432  $customAttributes = $dataArray['custom_attributes'];
2433  unset($dataArray['custom_attributes']);
2434  foreach ($customAttributes as $attributeValue) {
2437  }
2438  }
2439  return $dataArray;
2440  }
2441 
2448  public function setSku($sku)
2449  {
2450  return $this->setData(self::SKU, $sku);
2451  }
2452 
2459  public function setName($name)
2460  {
2461  return $this->setData(self::NAME, $name);
2462  }
2463 
2470  public function setStoreId($storeId)
2471  {
2472  return $this->setData(self::STORE_ID, $storeId);
2473  }
2474 
2482  {
2483  return $this->setData(self::ATTRIBUTE_SET_ID, $attributeSetId);
2484  }
2485 
2492  public function setPrice($price)
2493  {
2494  return $this->setData(self::PRICE, $price);
2495  }
2496 
2503  public function setStatus($status)
2504  {
2505  return $this->setData(self::STATUS, $status);
2506  }
2507 
2514  public function setVisibility($visibility)
2515  {
2516  return $this->setData(self::VISIBILITY, $visibility);
2517  }
2518 
2525  public function setCreatedAt($createdAt)
2526  {
2527  return $this->setData(self::CREATED_AT, $createdAt);
2528  }
2529 
2536  public function setUpdatedAt($updatedAt)
2537  {
2538  return $this->setData(self::UPDATED_AT, $updatedAt);
2539  }
2540 
2547  public function setWeight($weight)
2548  {
2549  return $this->setData(self::WEIGHT, $weight);
2550  }
2551 
2558  public function setTypeId($typeId)
2559  {
2560  if ($typeId !== $this->_getData('type_id')) {
2561  $this->_typeInstance = null;
2562  }
2563  return $this->setData(self::TYPE_ID, $typeId);
2564  }
2565 
2571  public function getExtensionAttributes()
2572  {
2573  return $this->_getExtensionAttributes();
2574  }
2575 
2582  public function setExtensionAttributes(\Magento\Catalog\Api\Data\ProductExtensionInterface $extensionAttributes)
2583  {
2584  return $this->_setExtensionAttributes($extensionAttributes);
2585  }
2586 
2587  //@codeCoverageIgnoreEnd
2588 
2596  protected function convertToMediaGalleryInterface(array $mediaGallery)
2597  {
2598  $entries = [];
2599  foreach ($mediaGallery as $image) {
2600  $entry = $this
2601  ->mediaGalleryEntryConverterPool
2602  ->getConverterByMediaType($image['media_type'])
2603  ->convertTo($this, $image);
2604  $entries[] = $entry;
2605  }
2606  return $entries;
2607  }
2608 
2615  public function getMediaGalleryEntries()
2616  {
2617  $mediaGallery = $this->getMediaGallery('images');
2618  if ($mediaGallery === null) {
2619  return null;
2620  }
2621  //convert the data
2622  $convertedEntries = $this->convertToMediaGalleryInterface($mediaGallery);
2623  return $convertedEntries;
2624  }
2625 
2633  public function setMediaGalleryEntries(array $mediaGalleryEntries = null)
2634  {
2635  if ($mediaGalleryEntries !== null) {
2636  $images = [];
2637  foreach ($mediaGalleryEntries as $entry) {
2638  $images[] = $this
2639  ->mediaGalleryEntryConverterPool
2640  ->getConverterByMediaType($entry->getMediaType())
2641  ->convertFrom($entry);
2642  }
2643  $this->setData('media_gallery', ['images' => $images]);
2644  }
2645  return $this;
2646  }
2647 
2654  public function getId()
2655  {
2656  return $this->_getData('entity_id');
2657  }
2658 
2666  public function setId($value)
2667  {
2668  return $this->setData('entity_id', $value);
2669  }
2670 
2676  private function getLinkRepository()
2677  {
2678  if (null === $this->linkRepository) {
2679  $this->linkRepository = \Magento\Framework\App\ObjectManager::getInstance()
2680  ->get(\Magento\Catalog\Api\ProductLinkRepositoryInterface::class);
2681  }
2682  return $this->linkRepository;
2683  }
2684 
2690  private function getMediaGalleryProcessor()
2691  {
2692  if (null === $this->mediaGalleryProcessor) {
2693  $this->mediaGalleryProcessor = \Magento\Framework\App\ObjectManager::getInstance()
2694  ->get(\Magento\Catalog\Model\Product\Gallery\Processor::class);
2695  }
2697  }
2698 
2706  public function setAssociatedProductIds(array $productIds)
2707  {
2708  $this->getExtensionAttributes()->setConfigurableProductLinks($productIds);
2709  return $this;
2710  }
2711 
2723  public function getQuantityAndStockStatus()
2724  {
2725  return $this->getData('quantity_and_stock_status');
2726  }
2727 
2740  public function setQuantityAndStockStatus($quantityAndStockStatusData)
2741  {
2742  $this->setData('quantity_and_stock_status', $quantityAndStockStatusData);
2743  return $this;
2744  }
2745 
2757  public function getStockData()
2758  {
2759  return $this->getData('stock_data');
2760  }
2761 
2774  public function setStockData($stockData)
2775  {
2776  $this->setData('stock_data', $stockData);
2777  return $this;
2778  }
2779 }
setMediaGalleryEntries(array $mediaGalleryEntries=null)
Definition: Product.php:2633
addAttributeUpdate($code, $value, $store)
Definition: Product.php:1824
toArray(array $arrAttributes=[])
Definition: Product.php:1843
setOptions(array $options=null)
Definition: Product.php:2015
setAttributeSetId($attributeSetId)
Definition: Product.php:2481
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
canBeShowInCategory($categoryId)
Definition: Product.php:2105
getAttributes($groupId=null, $skipSuper=false)
Definition: Product.php:842
getAttributeText($attributeCode)
Definition: Product.php:1762
processBuyRequest(\Magento\Framework\DataObject $buyRequest)
Definition: Product.php:2188
$config
Definition: fraud_order.php:17
_setExtensionAttributes(\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)
setQuantityAndStockStatus($quantityAndStockStatusData)
Definition: Product.php:2740
$storeManager
addCustomOption($code, $value, $product=null)
Definition: Product.php:2040
$resource
Definition: bulk.php:12
$price
isProductsHasSku(array $productIds)
Definition: Product.php:2168
setExtensionAttributes(\Magento\Catalog\Api\Data\ProductExtensionInterface $extensionAttributes)
Definition: Product.php:2582
canAffectOptions($value=null)
Definition: Product.php:935
$columns
Definition: default.phtml:15
$type
Definition: item.phtml:13
addImageToMediaGallery($file, $mediaAttribute=null, $move=false, $exclude=true)
Definition: Product.php:1569
addOption(Product\Option $option)
Definition: Product.php:1960
$value
Definition: gender.phtml:16
convertToMediaGalleryInterface(array $mediaGallery)
Definition: Product.php:2596
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Catalog\Api\ProductAttributeRepositoryInterface $metadataService, Product\Url $url, Product\Link $productLink, \Magento\Catalog\Model\Product\Configuration\Item\OptionFactory $itemOptionFactory, \Magento\CatalogInventory\Api\Data\StockItemInterfaceFactory $stockItemFactory, \Magento\Catalog\Model\Product\OptionFactory $catalogProductOptionFactory, \Magento\Catalog\Model\Product\Visibility $catalogProductVisibility, \Magento\Catalog\Model\Product\Attribute\Source\Status $catalogProductStatus, \Magento\Catalog\Model\Product\Media\Config $catalogProductMediaConfig, Product\Type $catalogProductType, \Magento\Framework\Module\Manager $moduleManager, \Magento\Catalog\Helper\Product $catalogProduct, \Magento\Catalog\Model\ResourceModel\Product $resource, \Magento\Catalog\Model\ResourceModel\Product\Collection $resourceCollection, \Magento\Framework\Data\CollectionFactory $collectionFactory, \Magento\Framework\Filesystem $filesystem, \Magento\Framework\Indexer\IndexerRegistry $indexerRegistry, \Magento\Catalog\Model\Indexer\Product\Flat\Processor $productFlatIndexerProcessor, \Magento\Catalog\Model\Indexer\Product\Price\Processor $productPriceIndexerProcessor, \Magento\Catalog\Model\Indexer\Product\Eav\Processor $productEavIndexerProcessor, CategoryRepositoryInterface $categoryRepository, Product\Image\CacheFactory $imageCacheFactory, \Magento\Catalog\Model\ProductLink\CollectionProvider $entityCollectionProvider, \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider, \Magento\Catalog\Api\Data\ProductLinkInterfaceFactory $productLinkFactory, \Magento\Catalog\Api\Data\ProductLinkExtensionFactory $productLinkExtensionFactory, EntryConverterPool $mediaGalleryEntryConverterPool, \Magento\Framework\Api\DataObjectHelper $dataObjectHelper, \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $joinProcessor, array $data=[], \Magento\Eav\Model\Config $config=null, FilterProductCustomAttribute $filterCustomAttribute=null)
Definition: Product.php:398
$attributeCode
Definition: extend.phtml:12
getProductEntitiesInfo($columns=null)
Definition: Product.php:2308
$status
Definition: order_status.php:8
foreach($product->getExtensionAttributes() ->getBundleProductOptions() as $option) $buyRequest
setProductLinks(array $links=null)
Definition: Product.php:1463
$attributes
Definition: matrix.phtml:13
$stock
setAssociatedProductIds(array $productIds)
Definition: Product.php:2706
setPriceCalculation($calculate=true)
Definition: Product.php:643
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18
setCustomOptions(array $options)
Definition: Product.php:2056
$filesystem
setCategoryCollection(\Magento\Framework\Data\Collection $categoryCollection)
Definition: Product.php:792
setTierPrices(array $tierPrices=null)
Definition: Product.php:1138
$stockData
Definition: products.php:27
$code
Definition: info.phtml:12
if(!isset($_GET['name'])) $name
Definition: log.php:14