Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes | Static Protected Attributes
Product Class Reference
Inheritance diagram for Product:
AbstractModel IdentityInterface SaleableInterface ProductInterface AbstractExtensibleModel CustomAttributesDataInterface AbstractModel CustomAttributesDataInterface ExtensibleDataInterface DataObject ExtensibleDataInterface Product

Public Member Functions

 __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)
 
 getStoreId ()
 
 getUrlModel ()
 
 validate ()
 
 getName ()
 
 getPrice ()
 
 getVisibility ()
 
 getAttributeSetId ()
 
 getCreatedAt ()
 
 getUpdatedAt ()
 
 setPriceCalculation ($calculate=true)
 
 getTypeId ()
 
 getStatus ()
 
 getTypeInstance ()
 
 setTypeInstance ($instance)
 
 getLinkInstance ()
 
 getIdBySku ($sku)
 
 getCategoryId ()
 
 getCategory ()
 
 getCategoryIds ()
 
 getCategoryCollection ()
 
 getWebsiteIds ()
 
 getStoreIds ()
 
 getAttributes ($groupId=null, $skipSuper=false)
 
 beforeSave ()
 
 canAffectOptions ($value=null)
 
 afterSave ()
 
 setQty ($qty)
 
 getQty ()
 
 priceReindexCallback ()
 
 eavReindexCallback ()
 
 isDataChanged ()
 
 reindex ()
 
 beforeDelete ()
 
 afterDeleteCommit ()
 
 cleanCache ()
 
 getPriceModel ()
 
 getPriceInfo ()
 
 getTierPrices ()
 
 setTierPrices (array $tierPrices=null)
 
 getTierPrice ($qty=null)
 
 getFormattedPrice ()
 
 getFormatedPrice ()
 
 setFinalPrice ($price)
 
 getFinalPrice ($qty=null)
 
 getCalculatedFinalPrice ()
 
 getMinimalPrice ()
 
 getSpecialPrice ()
 
 getSpecialFromDate ()
 
 getSpecialToDate ()
 
 getRelatedProducts ()
 
 getRelatedProductIds ()
 
 getRelatedProductCollection ()
 
 getRelatedLinkCollection ()
 
 getUpSellProducts ()
 
 getUpSellProductIds ()
 
 getUpSellProductCollection ()
 
 getUpSellLinkCollection ()
 
 getCrossSellProducts ()
 
 getCrossSellProductIds ()
 
 getCrossSellProductCollection ()
 
 getCrossSellLinkCollection ()
 
 getProductLinks ()
 
 setProductLinks (array $links=null)
 
 getMediaAttributes ()
 
 getMediaAttributeValues ()
 
 getMediaGalleryImages ()
 
 hasGalleryAttribute ()
 
 addImageToMediaGallery ($file, $mediaAttribute=null, $move=false, $exclude=true)
 
 getMediaConfig ()
 
 getVisibleInCatalogStatuses ()
 
 getVisibleStatuses ()
 
 isVisibleInCatalog ()
 
 getVisibleInSiteVisibilities ()
 
 isVisibleInSiteVisibility ()
 
 isDuplicable ()
 
 setIsDuplicable ($value)
 
 isSalable ()
 
 isAvailable ()
 
 getIsSalable ()
 
 isVirtual ()
 
 isSaleable ()
 
 isInStock ()
 
 getAttributeText ($attributeCode)
 
 getCustomDesignDate ()
 
 getProductUrl ($useSid=null)
 
 getUrlInStore ($params=[])
 
 formatUrlKey ($str)
 
 addAttributeUpdate ($code, $value, $store)
 
 toArray (array $arrAttributes=[])
 
 fromArray (array $data)
 
 getRequestPath ()
 
 getGiftMessageAvailable ()
 
 isComposite ()
 
 canConfigure ()
 
 getSku ()
 
 getWeight ()
 
 getOptionInstance ()
 
 addOption (Product\Option $option)
 
 getProductOptionsCollection ()
 
 getOptions ()
 
 setOptions (array $options=null)
 
 getIsVirtual ()
 
 addCustomOption ($code, $value, $product=null)
 
 setCustomOptions (array $options)
 
 getCustomOptions ()
 
 getCustomOption ($code)
 
 hasCustomOptions ()
 
 canBeShowInCategory ($categoryId)
 
 getAvailableInCategories ()
 
 getDefaultAttributeSetId ()
 
 reset ()
 
 getCacheIdTags ()
 
 isProductsHasSku (array $productIds)
 
 processBuyRequest (\Magento\Framework\DataObject $buyRequest)
 
 getPreconfiguredValues ()
 
 prepareCustomOptions ()
 
 getProductEntitiesInfo ($columns=null)
 
 isDisabled ()
 
 getImage ()
 
 getIdentities ()
 
 reloadPriceInfo ()
 
 __toArray ()
 
 setSku ($sku)
 
 setName ($name)
 
 setStoreId ($storeId)
 
 setAttributeSetId ($attributeSetId)
 
 setPrice ($price)
 
 setStatus ($status)
 
 setVisibility ($visibility)
 
 setCreatedAt ($createdAt)
 
 setUpdatedAt ($updatedAt)
 
 setWeight ($weight)
 
 setTypeId ($typeId)
 
 getExtensionAttributes ()
 
 setExtensionAttributes (\Magento\Catalog\Api\Data\ProductExtensionInterface $extensionAttributes)
 
 getMediaGalleryEntries ()
 
 setMediaGalleryEntries (array $mediaGalleryEntries=null)
 
 getId ()
 
 setId ($value)
 
 setAssociatedProductIds (array $productIds)
 
 getQuantityAndStockStatus ()
 
 setQuantityAndStockStatus ($quantityAndStockStatusData)
 
 getStockData ()
 
 setStockData ($stockData)
 
- Public Member Functions inherited from AbstractModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 lockAttribute ($attributeCode)
 
 unlockAttribute ($attributeCode)
 
 unlockAttributes ()
 
 getLockedAttributes ()
 
 hasLockedAttributes ()
 
 isLockedAttribute ($attributeCode)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getResourceCollection ()
 
 loadByAttribute ($attribute, $value, $additionalAttributes=' *')
 
 getStore ()
 
 getWebsiteStoreIds ()
 
 setAttributeDefaultValue ($attributeCode, $value)
 
 getAttributeDefaultValue ($attributeCode)
 
 setExistsStoreValueFlag ($attributeCode)
 
 getExistsStoreValueFlag ($attributeCode)
 
 beforeSave ()
 
 isDeleteable ()
 
 setIsDeleteable ($value)
 
 isReadonly ()
 
 setIsReadonly ($value)
 
- Public Member Functions inherited from AbstractExtensibleModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 getCustomAttributes ()
 
 getCustomAttribute ($attributeCode)
 
 setCustomAttributes (array $attributes)
 
 setCustomAttribute ($attributeCode, $attributeValue)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 setId ($value)
 
 __sleep ()
 
 __wakeup ()
 
- Public Member Functions inherited from AbstractModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 __sleep ()
 
 __wakeup ()
 
 setIdFieldName ($name)
 
 getIdFieldName ()
 
 getId ()
 
 setId ($value)
 
 isDeleted ($isDeleted=null)
 
 hasDataChanges ()
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 setDataChanges ($value)
 
 getOrigData ($key=null)
 
 setOrigData ($key=null, $data=null)
 
 dataHasChangedFor ($field)
 
 getResourceName ()
 
 getResourceCollection ()
 
 getCollection ()
 
 load ($modelId, $field=null)
 
 beforeLoad ($identifier, $field=null)
 
 afterLoad ()
 
 isSaveAllowed ()
 
 setHasDataChanges ($flag)
 
 save ()
 
 afterCommitCallback ()
 
 isObjectNew ($flag=null)
 
 beforeSave ()
 
 validateBeforeSave ()
 
 getCacheTags ()
 
 cleanModelCache ()
 
 afterSave ()
 
 delete ()
 
 beforeDelete ()
 
 afterDelete ()
 
 afterDeleteCommit ()
 
 getResource ()
 
 getEntityId ()
 
 setEntityId ($entityId)
 
 clearInstance ()
 
 getStoredData ()
 
 getEventPrefix ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 

Data Fields

const ENTITY = 'catalog_product'
 
const CACHE_TAG = 'cat_p'
 
const CACHE_PRODUCT_CATEGORY_TAG = 'cat_c_p'
 
const STORE_ID = 'store_id'
 
- Data Fields inherited from CustomAttributesDataInterface
const CUSTOM_ATTRIBUTES = 'custom_attributes'
 
- Data Fields inherited from ExtensibleDataInterface
const EXTENSION_ATTRIBUTES_KEY = 'extension_attributes'
 
- Data Fields inherited from ProductInterface
const SKU = 'sku'
 
const NAME = 'name'
 
const PRICE = 'price'
 
const WEIGHT = 'weight'
 
const STATUS = 'status'
 
const VISIBILITY = 'visibility'
 
const ATTRIBUTE_SET_ID = 'attribute_set_id'
 
const TYPE_ID = 'type_id'
 
const CREATED_AT = 'created_at'
 
const UPDATED_AT = 'updated_at'
 
const MEDIA_GALLERY = 'media_gallery'
 
const TIER_PRICE = 'tier_price'
 
const ATTRIBUTES
 

Protected Member Functions

 _construct ()
 
 _getResource ()
 
 getCustomAttributesCodes ()
 
 setCategoryCollection (\Magento\Framework\Data\Collection $categoryCollection)
 
 _afterLoad ()
 
 _clearReferences ()
 
 _clearData ()
 
 convertToMediaGalleryInterface (array $mediaGallery)
 
- Protected Member Functions inherited from AbstractExtensibleModel
 filterCustomAttributes ($data)
 
 initializeCustomAttributes ()
 
 convertCustomAttributeValues (array &$customAttributes)
 
 getCustomAttributesCodes ()
 
 _setExtensionAttributes (\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)
 
 _getExtensionAttributes ()
 
- Protected Member Functions inherited from AbstractModel
 _construct ()
 
 _init ($resourceModel)
 
 _setResourceModel ($resourceName, $collectionName=null)
 
 _getResource ()
 
 _getEventData ()
 
 _beforeLoad ($modelId, $field=null)
 
 _afterLoad ()
 
 _hasModelChanged ()
 
 _getValidatorBeforeSave ()
 
 _createValidatorBeforeSave ()
 
 _getValidationRulesBeforeSave ()
 
 _clearReferences ()
 
 _clearData ()
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $linkRepository
 
 $_cacheTag = self::CACHE_TAG
 
 $_eventPrefix = 'catalog_product'
 
 $_eventObject = 'product'
 
 $_canAffectOptions = false
 
 $_typeInstance = null
 
 $_linkInstance
 
 $_customOptions = []
 
 $_urlModel = null
 
 $_resource
 
 $_errors = []
 
 $optionFactory
 
 $optionInstance
 
 $_links = null
 
 $_isDuplicable = true
 
 $_calculatePrice = true
 
 $_catalogProduct = null
 
 $moduleManager
 
 $_collectionFactory
 
 $_catalogProductType
 
 $_catalogProductMediaConfig
 
 $_catalogProductStatus
 
 $_catalogProductVisibility
 
 $_stockItemFactory
 
 $_itemOptionFactory
 
 $_filesystem
 
 $indexerRegistry
 
 $_productFlatIndexerProcessor
 
 $_productPriceIndexerProcessor
 
 $_productEavIndexerProcessor
 
 $_priceInfo
 
 $categoryRepository
 
 $categoryCollection
 
 $imageCacheFactory
 
 $metadataService
 
 $entityCollectionProvider
 
 $linkProvider
 
 $productLinkFactory
 
 $productLinkExtensionFactory
 
 $dataObjectHelper
 
 $_productIdCached
 
 $interfaceAttributes = ProductInterface::ATTRIBUTES
 
 $joinProcessor
 
 $mediaGalleryEntryConverterPool
 
 $mediaGalleryProcessor
 
 $linkTypeProvider
 
- Protected Attributes inherited from AbstractModel
 $_defaultValues
 
 $_storeValuesFlags
 
 $_lockedAttributes = []
 
 $_isDeleteable = true
 
 $_isReadonly = false
 
 $_storeManager
 
- Protected Attributes inherited from AbstractExtensibleModel
 $extensionAttributesFactory
 
 $extensionAttributes
 
 $customAttributeFactory
 
 $customAttributesCodes = null
 
 $customAttributesChanged = false
 
- Protected Attributes inherited from AbstractModel
 $_eventPrefix = 'core_abstract'
 
 $_eventObject = 'object'
 
 $_idFieldName = 'id'
 
 $_hasDataChanges = false
 
 $_origData
 
 $_isDeleted = false
 
 $_resource
 
 $_resourceCollection
 
 $_resourceName
 
 $_collectionName
 
 $_cacheTag = false
 
 $_dataSaveAllowed = true
 
 $_isObjectNew = null
 
 $_validatorBeforeSave = null
 
 $_eventManager
 
 $_cacheManager
 
 $_registry
 
 $_logger
 
 $_appState
 
 $_actionValidator
 
 $storedData = []
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Static Protected Attributes

static $_url
 
- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Catalog product model

@api @method Product setHasError(bool $value) @method null|bool getHasError() @method array getAssociatedProductIds() @method Product setNewVariationsAttributeSetId(int $value) @method int getNewVariationsAttributeSetId() @method int getPriceType() @method string getUrlKey() @method Product setUrlKey(string $urlKey) @method Product setRequestPath(string $requestPath) @method Product setWebsiteIds(array $ids)

@SuppressWarnings(PHPMD.LongVariable) @SuppressWarnings(PHPMD.ExcessivePublicCount) @SuppressWarnings(PHPMD.TooManyFields) @SuppressWarnings(PHPMD.ExcessiveClassComplexity) @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Since
100.0.2

Definition at line 42 of file Product.php.

Constructor & Destructor Documentation

◆ __construct()

__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 
)
Parameters
\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
Product\Configuration\Item\OptionFactory$itemOptionFactory
\Magento\CatalogInventory\Api\Data\StockItemInterfaceFactory$stockItemFactory
Product\OptionFactory$catalogProductOptionFactory
Product\Visibility$catalogProductVisibility
Product\Attribute\Source\Status$catalogProductStatus
Product\Media\Config$catalogProductMediaConfig
Product\Type$catalogProductType
\Magento\Framework\Module\Manager$moduleManager
\Magento\Catalog\Helper\Product$catalogProduct
ResourceModel\Product$resource
ResourceModel\Product\Collection$resourceCollection
\Magento\Framework\Data\CollectionFactory$collectionFactory
\Magento\Framework\Filesystem$filesystem
\Magento\Framework\Indexer\IndexerRegistry$indexerRegistry
Indexer\Product\Flat\Processor$productFlatIndexerProcessor
Indexer\Product\Price\Processor$productPriceIndexerProcessor
Indexer\Product\Eav\Processor$productEavIndexerProcessor
CategoryRepositoryInterface$categoryRepository
Product\Image\CacheFactory$imageCacheFactory
ProductLink\CollectionProvider$entityCollectionProvider
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 | null$config
FilterProductCustomAttribute | null$filterCustomAttribute@SuppressWarnings(PHPMD.ExcessiveParameterList) @SuppressWarnings(PHPMD.UnusedFormalParameter)

Definition at line 398 of file Product.php.

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  }
$config
Definition: fraud_order.php:17
$storeManager
$resource
Definition: bulk.php:12
$filesystem

Member Function Documentation

◆ __toArray()

__toArray ( )

Return Data Object data in array format.

Returns
array
Todo:
refactor with converter for AbstractExtensibleModel

Definition at line 2400 of file Product.php.

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  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$value
Definition: gender.phtml:16

◆ _afterLoad()

_afterLoad ( )
protected

Load product options if they exists

Returns
$this

Definition at line 1079 of file Product.php.

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  }

◆ _clearData()

_clearData ( )
protected

Clearing product's data

Returns
\Magento\Catalog\Model\Product

Definition at line 2264 of file Product.php.

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  }

◆ _clearReferences()

_clearReferences ( )
protected

Clearing references on product

Returns
\Magento\Catalog\Model\Product

Definition at line 2253 of file Product.php.

2254  {
2255  $this->_clearOptionReferences();
2256  return $this;
2257  }

◆ _construct()

_construct ( )
protected

Initialize resources

Returns
void

Definition at line 484 of file Product.php.

485  {
486  $this->_init(\Magento\Catalog\Model\ResourceModel\Product::class);
487  }

◆ _getResource()

_getResource ( )
protected

Get resource instance

Exceptions

Definition at line 497 of file Product.php.

498  {
499  return parent::_getResource();
500  }

◆ addAttributeUpdate()

addAttributeUpdate (   $code,
  $value,
  $store 
)

Save current attribute with code $code and assign new value

Parameters
string$codeAttribute code
mixed$valueNew attribute value
int$storeStore ID
Returns
void

Definition at line 1824 of file Product.php.

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  }
$value
Definition: gender.phtml:16
$code
Definition: info.phtml:12

◆ addCustomOption()

addCustomOption (   $code,
  $value,
  $product = null 
)

Add custom option information to product

Parameters
string$codeOption code
mixed$valueValue of the option
int | Product$productProduct ID
Returns
$this

Definition at line 2040 of file Product.php.

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  }
$value
Definition: gender.phtml:16
$code
Definition: info.phtml:12

◆ addImageToMediaGallery()

addImageToMediaGallery (   $file,
  $mediaAttribute = null,
  $move = false,
  $exclude = true 
)

Add image to media gallery

Parameters
string$filefile path of image in file system
string | array$mediaAttributecode of type 'media_image', leave blank if image should be only in gallery
boolean$moveif true, it will move source file
boolean$excludemark image as disabled in product page view
Returns
\Magento\Catalog\Model\Product
Exceptions

Definition at line 1569 of file Product.php.

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  }

◆ addOption()

addOption ( Product\Option  $option)

Add option to array of product options

Parameters
Product\Option$option
Returns
\Magento\Catalog\Model\Product

Definition at line 1960 of file Product.php.

1961  {
1962  $options = (array)$this->getData('options');
1963  $options[] = $option;
1964  $option->setProduct($this);
1965  $this->setData('options', $options);
1966  return $this;
1967  }

◆ afterDeleteCommit()

afterDeleteCommit ( )

Init indexing process after product delete commit

Returns
void

Definition at line 1067 of file Product.php.

1068  {
1069  $this->reindex();
1070  $this->_productPriceIndexerProcessor->reindexRow($this->getId());
1071  parent::afterDeleteCommit();
1072  }

◆ afterSave()

afterSave ( )

Saving product type related data and init index

Returns
\Magento\Catalog\Model\Product

Definition at line 948 of file Product.php.

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  }

◆ beforeDelete()

beforeDelete ( )

Clear cache related with product and protect delete from not admin

Register indexing event before delete product

Returns
\Magento\Catalog\Model\Product
Exceptions

Definition at line 1056 of file Product.php.

1057  {
1058  $this->cleanCache();
1059  return parent::beforeDelete();
1060  }

◆ beforeSave()

beforeSave ( )

Check product options and type options and save them, too

Returns
void @SuppressWarnings(PHPMD.CyclomaticComplexity) @SuppressWarnings(PHPMD.NPathComplexity)

We need reset attribute set id to attribute after related simple product was saved

Parameters
\Magento\Catalog\Model\ResourceModel\Product$subject
\Magento\Framework\DataObject$object
Returns
void

@SuppressWarnings(PHPMD.UnusedFormalParameter)

$this->_canAffectOptions - set by type instance only $this->getCanSaveCustomOptions() - set either in controller when "Custom Options" ajax tab is loaded, or in type instance as well

Set true, if any Set false, ONLY if options have been affected by Options tab and Type instance tab

Definition at line 866 of file Product.php.

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  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
canAffectOptions($value=null)
Definition: Product.php:935

◆ canAffectOptions()

canAffectOptions (   $value = null)

Check/set if options can be affected when saving product

If value specified, it will be set.

Parameters
bool$value
Returns
bool

Definition at line 935 of file Product.php.

936  {
937  if (null !== $value) {
938  $this->_canAffectOptions = (bool) $value;
939  }
941  }
$value
Definition: gender.phtml:16

◆ canBeShowInCategory()

canBeShowInCategory (   $categoryId)

Check availability display product in category

Parameters
int$categoryId
Returns
bool

Definition at line 2105 of file Product.php.

2106  {
2107  return $this->_getResource()->canBeShowInCategory($this, $categoryId);
2108  }

◆ canConfigure()

canConfigure ( )

Check if product can be configured

Returns
bool

Definition at line 1914 of file Product.php.

1915  {
1916  $options = $this->getOptions();
1917  return !empty($options) || $this->getTypeInstance()->canConfigure($this);
1918  }

◆ cleanCache()

cleanCache ( )

Clear cache related with product id

Returns
$this

Definition at line 1093 of file Product.php.

1094  {
1095  $this->_cacheManager->clean('catalog_product_' . $this->getId());
1096  return $this;
1097  }

◆ convertToMediaGalleryInterface()

convertToMediaGalleryInterface ( array  $mediaGallery)
protected

Convert to media gallery interface

Parameters
array$mediaGallery
Returns
\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface[]
Exceptions

Definition at line 2596 of file Product.php.

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  }

◆ eavReindexCallback()

eavReindexCallback ( )

Reindex callback for EAV indexer

Returns
void

Definition at line 1010 of file Product.php.

1011  {
1012  if ($this->isObjectNew() || $this->isDataChanged($this)) {
1013  $this->_productEavIndexerProcessor->reindexRow($this->getEntityId());
1014  }
1015  }

◆ formatUrlKey()

formatUrlKey (   $str)

Formats URL key

Parameters
string$strURL
Returns
string

Definition at line 1811 of file Product.php.

1812  {
1813  return $this->getUrlModel()->formatUrlKey($str);
1814  }

◆ fromArray()

fromArray ( array  $data)

Same as setData(), but also initiates the stock item (if it is there)

Parameters
array$dataArray to form the object from
Returns
\Magento\Catalog\Model\Product

Definition at line 1860 of file Product.php.

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  }

◆ getAttributes()

getAttributes (   $groupId = null,
  $skipSuper = false 
)

Retrieve product attributes

If $groupId is null - retrieve all product attributes

Parameters
int$groupIdRetrieve attributes of the specified group
bool$skipSuperNot used
Returns
\Magento\Eav\Model\Entity\Attribute\AbstractAttribute[] @SuppressWarnings(PHPMD.UnusedFormalParameter)

Definition at line 842 of file Product.php.

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  }
$attributes
Definition: matrix.phtml:13

◆ getAttributeSetId()

getAttributeSetId ( )

Get product attribute set id

Returns
int

Implements ProductInterface.

Definition at line 611 of file Product.php.

612  {
613  return $this->_getData(self::ATTRIBUTE_SET_ID);
614  }

◆ getAttributeText()

getAttributeText (   $attributeCode)

Get attribute text by its code

Parameters
string$attributeCodeCode of the attribute
Returns
string|array|null

Definition at line 1762 of file Product.php.

1763  {
1764  return $this->getResource()->getAttribute($attributeCode)->getSource()->getOptionText(
1765  $this->getData($attributeCode)
1766  );
1767  }
$attributeCode
Definition: extend.phtml:12

◆ getAvailableInCategories()

getAvailableInCategories ( )

Retrieve category ids where product is available

Returns
array

Definition at line 2115 of file Product.php.

2116  {
2117  return $this->_getResource()->getAvailableInCategories($this);
2118  }

◆ getCacheIdTags()

getCacheIdTags ( )

Get cache tags associated with object id

Deprecated:
102.0.5
See also
\Magento\Catalog\Model\Product::getIdentities
Returns
string[]

Definition at line 2149 of file Product.php.

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  }

◆ getCalculatedFinalPrice()

getCalculatedFinalPrice ( )

Returns calculated final price

Returns
float

Definition at line 1215 of file Product.php.

1216  {
1217  return $this->_getData('calculated_final_price');
1218  }

◆ getCategory()

getCategory ( )

Retrieve product category

Returns
\Magento\Catalog\Model\Category

Definition at line 738 of file Product.php.

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  }

◆ getCategoryCollection()

getCategoryCollection ( )

Retrieve product categories

Returns
\Magento\Framework\Data\Collection

Get collection of product categories

Parameters
\Magento\Catalog\Model\Product$product
Returns
\Magento\Catalog\Model\ResourceModel\Category\Collection

Definition at line 776 of file Product.php.

777  {
778  if ($this->categoryCollection === null || $this->getId() != $this->_productIdCached) {
779  $categoryCollection = $this->_getResource()->getCategoryCollection($this);
781  $this->_productIdCached = $this->getId();
782  }
784  }
setCategoryCollection(\Magento\Framework\Data\Collection $categoryCollection)
Definition: Product.php:792

◆ getCategoryId()

getCategoryId ( )

Retrieve product category id

Returns
int

Definition at line 724 of file Product.php.

725  {
726  $category = $this->_registry->registry('current_category');
727  if ($category) {
728  return $category->getId();
729  }
730  return false;
731  }

◆ getCategoryIds()

getCategoryIds ( )

Retrieve assigned category Ids

Returns
array

Definition at line 753 of file Product.php.

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  }

◆ getCreatedAt()

getCreatedAt ( )

Get product creation date

Returns
string

Implements ProductInterface.

Definition at line 621 of file Product.php.

622  {
623  return $this->_getData(self::CREATED_AT);
624  }

◆ getCrossSellLinkCollection()

getCrossSellLinkCollection ( )

Retrieve collection cross sell link

Returns
\Magento\Catalog\Model\ResourceModel\Product\Link\Collection

Definition at line 1434 of file Product.php.

1435  {
1436  $collection = $this->getLinkInstance()->useCrossSellLinks()->getLinkCollection();
1437  $collection->setProduct($this);
1438  $collection->addLinkTypeIdFilter();
1439  $collection->addProductIdFilter();
1440  $collection->joinAttributes();
1441  return $collection;
1442  }

◆ getCrossSellProductCollection()

getCrossSellProductCollection ( )

Retrieve collection cross sell product

Returns
\Magento\Catalog\Model\ResourceModel\Product\Link\Product\Collection

Definition at line 1422 of file Product.php.

1423  {
1424  $collection = $this->getLinkInstance()->useCrossSellLinks()->getProductCollection()->setIsStrongMode();
1425  $collection->setProduct($this);
1426  return $collection;
1427  }

◆ getCrossSellProductIds()

getCrossSellProductIds ( )

Retrieve cross sell products identifiers

Returns
array

Definition at line 1405 of file Product.php.

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  }

◆ getCrossSellProducts()

getCrossSellProducts ( )

Retrieve array of cross sell products

Returns
array

Definition at line 1388 of file Product.php.

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  }

◆ getCustomAttributesCodes()

getCustomAttributesCodes ( )
protected

Get a list of custom attribute codes that belongs to product attribute set.

If attribute set not specified for product will return all product attribute codes

Returns
string[]

Definition at line 509 of file Product.php.

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  }

◆ getCustomDesignDate()

getCustomDesignDate ( )

Returns array with dates for custom design

Returns
array

Definition at line 1774 of file Product.php.

1775  {
1776  $result = [];
1777  $result['from'] = $this->getData('custom_design_from');
1778  $result['to'] = $this->getData('custom_design_to');
1779 
1780  return $result;
1781  }

◆ getCustomOption()

getCustomOption (   $code)

Get product custom option info

Parameters
string$code
Returns
array

Definition at line 2077 of file Product.php.

2078  {
2079  if (isset($this->_customOptions[$code])) {
2080  return $this->_customOptions[$code];
2081  }
2082  return null;
2083  }
$code
Definition: info.phtml:12

◆ getCustomOptions()

getCustomOptions ( )

Get all custom options of the product

Returns
array

Definition at line 2066 of file Product.php.

2067  {
2068  return $this->_customOptions;
2069  }

◆ getDefaultAttributeSetId()

getDefaultAttributeSetId ( )

Retrieve default attribute set id

Returns
int

Definition at line 2125 of file Product.php.

2126  {
2127  return $this->getResource()->getEntityType()->getDefaultAttributeSetId();
2128  }

◆ getExtensionAttributes()

getExtensionAttributes ( )

Retrieve existing extension attributes object or create a new one.

Returns
\Magento\Framework\Api\ExtensionAttributesInterface

Implements ProductInterface.

Definition at line 2571 of file Product.php.

◆ getFinalPrice()

getFinalPrice (   $qty = null)

Get product final price

Parameters
float$qty
Returns
float

Definition at line 1201 of file Product.php.

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  }

◆ getFormatedPrice()

getFormatedPrice ( )

Get formatted by currency product price

Returns
array|double
Deprecated:
102.0.6
See also
getFormattedPrice()

Definition at line 1174 of file Product.php.

1175  {
1176  return $this->getFormattedPrice();
1177  }

◆ getFormattedPrice()

getFormattedPrice ( )

Get formatted by currency product price

Returns
array|double
Since
102.0.6

Definition at line 1161 of file Product.php.

1162  {
1163  return $this->getPriceModel()->getFormattedPrice($this);
1164  }

◆ getGiftMessageAvailable()

getGiftMessageAvailable ( )

Custom function for other modules

Returns
string

Definition at line 1894 of file Product.php.

1895  {
1896  return $this->_getData('gift_message_available');
1897  }

◆ getId()

getId ( )

Identifier getter

Returns
int
Since
101.0.0

Implements SaleableInterface.

Definition at line 2654 of file Product.php.

2655  {
2656  return $this->_getData('entity_id');
2657  }

◆ getIdBySku()

getIdBySku (   $sku)

Retrieve product id by sku

Parameters
string$sku
Returns
integer

Definition at line 714 of file Product.php.

715  {
716  return $this->_getResource()->getIdBySku($sku);
717  }

◆ getIdentities()

getIdentities ( )

Get identities

Returns
array

Implements IdentityInterface.

Definition at line 2339 of file Product.php.

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  }

◆ getImage()

getImage ( )

Sets product image from it's child if possible

Returns
string

Definition at line 2328 of file Product.php.

2329  {
2330  $this->getTypeInstance()->setImageFromChildProduct($this);
2331  return parent::getImage();
2332  }

◆ getIsSalable()

getIsSalable ( )

Is product salable detecting by product type

Returns
bool @SuppressWarnings(PHPMD.BooleanGetMethodName)

Definition at line 1713 of file Product.php.

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  }

◆ getIsVirtual()

getIsVirtual ( )

Retrieve is a virtual product

Returns
bool @SuppressWarnings(PHPMD.BooleanGetMethodName)

Definition at line 2027 of file Product.php.

2028  {
2029  return $this->getTypeInstance()->isVirtual($this);
2030  }

◆ getLinkInstance()

getLinkInstance ( )

Retrieve link instance

Returns
Product\Link

Definition at line 703 of file Product.php.

704  {
705  return $this->_linkInstance;
706  }

◆ getMediaAttributes()

getMediaAttributes ( )

Retrieve attributes for media gallery

Returns
array

Definition at line 1479 of file Product.php.

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  }
getAttributes($groupId=null, $skipSuper=false)
Definition: Product.php:842

◆ getMediaAttributeValues()

getMediaAttributeValues ( )

Retrieve assoc array that contains media attribute values of the product

Returns
array

Definition at line 1498 of file Product.php.

1499  {
1500  $mediaAttributeCodes = $this->_catalogProductMediaConfig->getMediaAttributeCodes();
1501  $mediaAttributeValues = [];
1502  foreach ($mediaAttributeCodes as $attributeCode) {
1503  $mediaAttributeValues[$attributeCode] = $this->getData($attributeCode);
1504  }
1505  return $mediaAttributeValues;
1506  }
$attributeCode
Definition: extend.phtml:12

◆ getMediaConfig()

getMediaConfig ( )

Retrieve product media config

Returns
Product\Media\Config

Definition at line 1589 of file Product.php.

1590  {
1592  }

◆ getMediaGalleryEntries()

getMediaGalleryEntries ( )

Get media gallery entries

Returns
\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface[]|null
Exceptions

Implements ProductInterface.

Definition at line 2615 of file Product.php.

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  }
convertToMediaGalleryInterface(array $mediaGallery)
Definition: Product.php:2596

◆ getMediaGalleryImages()

getMediaGalleryImages ( )

Retrieve media gallery images

Returns
\Magento\Framework\Data\Collection

Definition at line 1513 of file Product.php.

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  }

◆ getMinimalPrice()

getMinimalPrice ( )

Returns minimal price

Returns
float

Definition at line 1225 of file Product.php.

1226  {
1227  return max($this->_getData('minimal_price'), 0);
1228  }

◆ getName()

getName ( )

Get product name

Returns
string @codeCoverageIgnoreStart

Implements ProductInterface.

Definition at line 572 of file Product.php.

573  {
574  return $this->_getData(self::NAME);
575  }

◆ getOptionInstance()

getOptionInstance ( )

Retrieve option instance

Returns
Product\Option

Definition at line 1945 of file Product.php.

1946  {
1947  if (!isset($this->optionInstance)) {
1948  $this->optionInstance = $this->optionFactory->create();
1949  $this->optionInstance->setProduct($this);
1950  }
1951  return $this->optionInstance;
1952  }

◆ getOptions()

getOptions ( )

Get all options of product

Returns
\Magento\Catalog\Api\Data\ProductCustomOptionInterface[]|null

Implements ProductInterface.

Definition at line 2004 of file Product.php.

2005  {
2006  return $this->getData('options');
2007  }

◆ getPreconfiguredValues()

getPreconfiguredValues ( )

Get preconfigured values from product

Returns
\Magento\Framework\DataObject

Definition at line 2220 of file Product.php.

2221  {
2222  $preConfiguredValues = $this->getData('preconfigured_values');
2223  if (!$preConfiguredValues) {
2224  $preConfiguredValues = new \Magento\Framework\DataObject();
2225  }
2226 
2227  return $preConfiguredValues;
2228  }

◆ getPrice()

getPrice ( )

Get product price through type instance

Returns
float

Implements ProductInterface.

Definition at line 584 of file Product.php.

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  }

◆ getPriceInfo()

getPriceInfo ( )

Get product Price Info object

Returns
\Magento\Framework\Pricing\PriceInfo\Base

Implements SaleableInterface.

Definition at line 1114 of file Product.php.

1115  {
1116  if (!$this->_priceInfo) {
1117  $this->_priceInfo = $this->_catalogProductType->getPriceInfo($this);
1118  }
1119  return $this->_priceInfo;
1120  }

◆ getPriceModel()

getPriceModel ( )

Get product price model

Returns
\Magento\Catalog\Model\Product\Type\Price

Definition at line 1104 of file Product.php.

1105  {
1106  return $this->_catalogProductType->priceFactory($this->getTypeId());
1107  }

◆ getProductEntitiesInfo()

getProductEntitiesInfo (   $columns = null)

Retrieve product entities info as array

Parameters
string | array$columnsOne or several columns
Returns
array

Definition at line 2308 of file Product.php.

2309  {
2310  return $this->_getResource()->getProductEntitiesInfo($columns);
2311  }
$columns
Definition: default.phtml:15

◆ getProductLinks()

getProductLinks ( )

Get product links info

Returns
\Magento\Catalog\Api\Data\ProductLinkInterface[]

Implements ProductInterface.

Definition at line 1449 of file Product.php.

1450  {
1451  if ($this->_links === null) {
1452  $this->_links = $this->getLinkRepository()->getList($this);
1453  }
1454  return $this->_links;
1455  }

◆ getProductOptionsCollection()

getProductOptionsCollection ( )

Retrieve options collection of product

Returns
\Magento\Catalog\Model\ResourceModel\Product\Option\Collection

Definition at line 1994 of file Product.php.

1995  {
1996  return $this->getOptionInstance()->getProductOptionCollection($this);
1997  }

◆ getProductUrl()

getProductUrl (   $useSid = null)

Retrieve Product URL

Parameters
bool$useSid
Returns
string

Definition at line 1789 of file Product.php.

1790  {
1791  return $this->getUrlModel()->getProductUrl($this, $useSid);
1792  }

◆ getQty()

getQty ( )

Get quantity for product

Returns
float

Implements SaleableInterface.

Definition at line 988 of file Product.php.

989  {
990  return $this->getData('qty');
991  }

◆ getQuantityAndStockStatus()

getQuantityAndStockStatus ( )

Get quantity and stock status data

Returns
array|null
Deprecated:
102.0.0 as Product model shouldn't be responsible for stock status
See also
StockItemInterface when you want to change the stock data
StockStatusInterface when you want to read the stock data for representation layer (storefront)
StockItemRepositoryInterface::save as extension point for customization of saving process
Since
102.0.0

Definition at line 2723 of file Product.php.

2724  {
2725  return $this->getData('quantity_and_stock_status');
2726  }

◆ getRelatedLinkCollection()

getRelatedLinkCollection ( )

Retrieve collection related link

Returns
\Magento\Catalog\Model\ResourceModel\Product\Link\Collection

Definition at line 1312 of file Product.php.

1313  {
1314  $collection = $this->getLinkInstance()->useRelatedLinks()->getLinkCollection();
1315  $collection->setProduct($this);
1316  $collection->addLinkTypeIdFilter();
1317  $collection->addProductIdFilter();
1318  $collection->joinAttributes();
1319  return $collection;
1320  }

◆ getRelatedProductCollection()

getRelatedProductCollection ( )

Retrieve collection related product

Returns
\Magento\Catalog\Model\ResourceModel\Product\Link\Product\Collection

Definition at line 1300 of file Product.php.

1301  {
1302  $collection = $this->getLinkInstance()->useRelatedLinks()->getProductCollection()->setIsStrongMode();
1303  $collection->setProduct($this);
1304  return $collection;
1305  }

◆ getRelatedProductIds()

getRelatedProductIds ( )

Retrieve related products identifiers

Returns
array

Definition at line 1283 of file Product.php.

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  }

◆ getRelatedProducts()

getRelatedProducts ( )

Retrieve array of related products

Returns
array

Definition at line 1265 of file Product.php.

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  }

◆ getRequestPath()

getRequestPath ( )

Returns request path

Returns
string

Definition at line 1884 of file Product.php.

1885  {
1886  return $this->_getData('request_path');
1887  }

◆ getSku()

getSku ( )

Retrieve sku through type instance

Returns
string

Implements ProductInterface.

Definition at line 1925 of file Product.php.

1926  {
1927  return $this->getTypeInstance()->getSku($this);
1928  }

◆ getSpecialFromDate()

getSpecialFromDate ( )

Returns starting date of the special price

Returns
mixed

Definition at line 1245 of file Product.php.

1246  {
1247  return $this->_getData('special_from_date');
1248  }

◆ getSpecialPrice()

getSpecialPrice ( )

Returns special price

Returns
float

Definition at line 1235 of file Product.php.

1236  {
1237  return $this->_getData('special_price');
1238  }

◆ getSpecialToDate()

getSpecialToDate ( )

Returns end date of the special price

Returns
mixed

Definition at line 1255 of file Product.php.

1256  {
1257  return $this->_getData('special_to_date');
1258  }

◆ getStatus()

getStatus ( )

Get product status

Returns
int

Implements ProductInterface.

Definition at line 665 of file Product.php.

666  {
667  $status = $this->_getData(self::STATUS);
668  return $status !== null ? $status : \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED;
669  }
$status
Definition: order_status.php:8

◆ getStockData()

getStockData ( )

Get stock data

Returns
array|null
Deprecated:
102.0.0 as Product model shouldn't be responsible for stock status
See also
StockItemInterface when you want to change the stock data
StockStatusInterface when you want to read the stock data for representation layer (storefront)
StockItemRepositoryInterface::save as extension point for customization of saving process
Since
102.0.0

Definition at line 2757 of file Product.php.

2758  {
2759  return $this->getData('stock_data');
2760  }

◆ getStoreId()

getStoreId ( )

Retrieve Store Id

Returns
int

Definition at line 533 of file Product.php.

534  {
535  if ($this->hasData(self::STORE_ID)) {
536  return $this->getData(self::STORE_ID);
537  }
538  return $this->_storeManager->getStore()->getId();
539  }

◆ getStoreIds()

getStoreIds ( )

Get all sore ids where product is presented

Returns
array

Definition at line 817 of file Product.php.

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  }

◆ getTierPrice()

getTierPrice (   $qty = null)

Get product tier price for the customer, based on qty of this product

Parameters
float$qty
Returns
float|array

Definition at line 1150 of file Product.php.

1151  {
1152  return $this->getPriceModel()->getTierPrice($qty, $this);
1153  }

◆ getTierPrices()

getTierPrices ( )

Gets list of product tier prices

Returns
\Magento\Catalog\Api\Data\ProductTierPriceInterface[]|null

Implements ProductInterface.

Definition at line 1127 of file Product.php.

1128  {
1129  return $this->getPriceModel()->getTierPrices($this);
1130  }

◆ getTypeId()

getTypeId ( )

Get product type identifier

Returns
array|string

Implements SaleableInterface.

Definition at line 653 of file Product.php.

654  {
655  return $this->_getData(self::TYPE_ID);
656  }

◆ getTypeInstance()

getTypeInstance ( )

Retrieve type instance of the product.

Type instance implements product type depended logic and is a singleton shared by all products of the same type.

Returns
\Magento\Catalog\Model\Product\Type\AbstractType

Definition at line 678 of file Product.php.

679  {
680  if ($this->_typeInstance === null) {
681  $this->_typeInstance = $this->_catalogProductType->factory($this);
682  }
683  return $this->_typeInstance;
684  }

◆ getUpdatedAt()

getUpdatedAt ( )

Get previous product update date

Returns
string

Implements ProductInterface.

Definition at line 631 of file Product.php.

632  {
633  return $this->_getData(self::UPDATED_AT);
634  }

◆ getUpSellLinkCollection()

getUpSellLinkCollection ( )

Retrieve collection up sell link

Returns
\Magento\Catalog\Model\ResourceModel\Product\Link\Collection

Definition at line 1373 of file Product.php.

1374  {
1375  $collection = $this->getLinkInstance()->useUpSellLinks()->getLinkCollection();
1376  $collection->setProduct($this);
1377  $collection->addLinkTypeIdFilter();
1378  $collection->addProductIdFilter();
1379  $collection->joinAttributes();
1380  return $collection;
1381  }

◆ getUpSellProductCollection()

getUpSellProductCollection ( )

Retrieve collection up sell product

Returns
\Magento\Catalog\Model\ResourceModel\Product\Link\Product\Collection

Definition at line 1361 of file Product.php.

1362  {
1363  $collection = $this->getLinkInstance()->useUpSellLinks()->getProductCollection()->setIsStrongMode();
1364  $collection->setProduct($this);
1365  return $collection;
1366  }

◆ getUpSellProductIds()

getUpSellProductIds ( )

Retrieve up sell products identifiers

Returns
array

Definition at line 1344 of file Product.php.

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  }

◆ getUpSellProducts()

getUpSellProducts ( )

Retrieve array of up sell products

Returns
array

Definition at line 1327 of file Product.php.

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  }

◆ getUrlInStore()

getUrlInStore (   $params = [])

Retrieve URL in current store

Parameters
array$paramsthe route params
Returns
string

Definition at line 1800 of file Product.php.

1801  {
1802  return $this->getUrlModel()->getUrlInStore($this, $params);
1803  }
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ getUrlModel()

getUrlModel ( )

Get product url model

Returns
Product\Url

Definition at line 546 of file Product.php.

547  {
548  return $this->_urlModel;
549  }

◆ getVisibility()

getVisibility ( )

Get visibility status

@codeCoverageIgnoreStart

See also
\Magento\Catalog\Model\Product\Visibility
Returns
int

Implements ProductInterface.

Definition at line 601 of file Product.php.

602  {
603  return $this->_getData(self::VISIBILITY);
604  }

◆ getVisibleInCatalogStatuses()

getVisibleInCatalogStatuses ( )

Returns visible status IDs in catalog

Returns
array

Definition at line 1599 of file Product.php.

1600  {
1601  return $this->_catalogProductStatus->getVisibleStatusIds();
1602  }

◆ getVisibleInSiteVisibilities()

getVisibleInSiteVisibilities ( )

Retrieve visible in site visibilities

Returns
array

Definition at line 1629 of file Product.php.

1630  {
1631  return $this->_catalogProductVisibility->getVisibleInSiteIds();
1632  }

◆ getVisibleStatuses()

getVisibleStatuses ( )

Retrieve visible statuses

Returns
array

Definition at line 1609 of file Product.php.

1610  {
1611  return $this->_catalogProductStatus->getVisibleStatusIds();
1612  }

◆ getWebsiteIds()

getWebsiteIds ( )

Retrieve product websites identifiers

Returns
array

Definition at line 803 of file Product.php.

804  {
805  if (!$this->hasWebsiteIds()) {
806  $ids = $this->_getResource()->getWebsiteIds($this);
807  $this->setWebsiteIds($ids);
808  }
809  return $this->getData('website_ids');
810  }

◆ getWeight()

getWeight ( )

Retrieve weight through type instance

Returns
float

Implements ProductInterface.

Definition at line 1935 of file Product.php.

1936  {
1937  return $this->getTypeInstance()->getWeight($this);
1938  }

◆ hasCustomOptions()

hasCustomOptions ( )

Checks if there custom option for this product

Returns
bool

Definition at line 2090 of file Product.php.

2091  {
2092  if (count($this->_customOptions)) {
2093  return true;
2094  } else {
2095  return false;
2096  }
2097  }

◆ hasGalleryAttribute()

hasGalleryAttribute ( )

Checks whether product has Media Gallery attribute.

Returns
bool
Since
101.0.0

Definition at line 1546 of file Product.php.

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  }
getAttributes($groupId=null, $skipSuper=false)
Definition: Product.php:842
$attributes
Definition: matrix.phtml:13

◆ isAvailable()

isAvailable ( )

Check whether the product type or stock allows to purchase the product

Returns
bool

Definition at line 1702 of file Product.php.

1703  {
1704  return $this->_catalogProduct->getSkipSaleableCheck() || $this->getTypeInstance()->isSalable($this);
1705  }

◆ isComposite()

isComposite ( )

Check is product composite

Returns
bool

Definition at line 1904 of file Product.php.

1905  {
1906  return $this->getTypeInstance()->isComposite($this);
1907  }

◆ isDataChanged()

isDataChanged ( )

Check if data was changed

Returns
bool

Definition at line 1022 of file Product.php.

1023  {
1024  foreach (array_keys($this->getData()) as $field) {
1025  if ($this->dataHasChangedFor($field)) {
1026  return true;
1027  }
1028  }
1029  return false;
1030  }

◆ isDisabled()

isDisabled ( )

Checks whether product has disabled status

Returns
bool

Definition at line 2318 of file Product.php.

2319  {
2320  return $this->getStatus() == \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED;
2321  }

◆ isDuplicable()

isDuplicable ( )

Checks product can be duplicated

Returns
boolean

Definition at line 1649 of file Product.php.

1650  {
1651  return $this->_isDuplicable;
1652  }

◆ isInStock()

isInStock ( )

Whether product available in stock

Returns
bool

Definition at line 1751 of file Product.php.

1752  {
1753  return $this->getStatus() == \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED;
1754  }

◆ isProductsHasSku()

isProductsHasSku ( array  $productIds)

Check for empty SKU on each product

Parameters
array$productIds
Returns
boolean|null

Definition at line 2168 of file Product.php.

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  }

◆ isSalable()

isSalable ( )

Check is product available for sale

Returns
bool

Definition at line 1671 of file Product.php.

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  }

◆ isSaleable()

isSaleable ( )

Alias for isSalable()

Returns
bool

Definition at line 1741 of file Product.php.

1742  {
1743  return $this->isSalable();
1744  }

◆ isVirtual()

isVirtual ( )

Check is a virtual product

Returns
bool

Definition at line 1731 of file Product.php.

1732  {
1733  return $this->getIsVirtual();
1734  }

◆ isVisibleInCatalog()

isVisibleInCatalog ( )

Check Product visible in catalog

Returns
bool

Definition at line 1619 of file Product.php.

1620  {
1621  return in_array($this->getStatus(), $this->getVisibleInCatalogStatuses());
1622  }

◆ isVisibleInSiteVisibility()

isVisibleInSiteVisibility ( )

Check Product visible in site

Returns
bool

Definition at line 1639 of file Product.php.

1640  {
1641  return in_array($this->getVisibility(), $this->getVisibleInSiteVisibilities());
1642  }

◆ prepareCustomOptions()

prepareCustomOptions ( )

Prepare product custom options.

To be sure that all product custom options does not has ID and has product instance

Returns
\Magento\Catalog\Model\Product

Definition at line 2237 of file Product.php.

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  }
addCustomOption($code, $value, $product=null)
Definition: Product.php:2040

◆ priceReindexCallback()

priceReindexCallback ( )

Callback for entity reindex

Returns
void

Definition at line 998 of file Product.php.

999  {
1000  if ($this->isObjectNew() || $this->_catalogProduct->isDataForPriceIndexerWasChanged($this)) {
1001  $this->_productPriceIndexerProcessor->reindexRow($this->getEntityId());
1002  }
1003  }

◆ processBuyRequest()

processBuyRequest ( \Magento\Framework\DataObject  $buyRequest)

Parse buyRequest into options values used by product

Parameters
\Magento\Framework\DataObject$buyRequest
Returns
\Magento\Framework\DataObject

Definition at line 2188 of file Product.php.

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  }
$type
Definition: item.phtml:13
$value
Definition: gender.phtml:16
foreach($product->getExtensionAttributes() ->getBundleProductOptions() as $option) $buyRequest

◆ reindex()

reindex ( )

Init indexing process after product save

Returns
void

Definition at line 1037 of file Product.php.

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  }

◆ reloadPriceInfo()

reloadPriceInfo ( )

Reload PriceInfo object

Returns
\Magento\Framework\Pricing\PriceInfo\Base

Definition at line 2386 of file Product.php.

2387  {
2388  if ($this->_priceInfo) {
2389  $this->_priceInfo = null;
2390  return $this->getPriceInfo();
2391  }
2392  }

◆ reset()

reset ( )

Reset all model data

Returns
\Magento\Catalog\Model\Product

Definition at line 2135 of file Product.php.

2136  {
2137  $this->unlockAttributes();
2138  $this->_clearData();
2139  return $this;
2140  }

◆ setAssociatedProductIds()

setAssociatedProductIds ( array  $productIds)

Set the associated products

Parameters
array$productIds
Returns
$this
Since
101.0.2

Definition at line 2706 of file Product.php.

2707  {
2708  $this->getExtensionAttributes()->setConfigurableProductLinks($productIds);
2709  return $this;
2710  }

◆ setAttributeSetId()

setAttributeSetId (   $attributeSetId)

Set product attribute set id

Parameters
int$attributeSetId
Returns
$this

Implements ProductInterface.

Definition at line 2481 of file Product.php.

2482  {
2483  return $this->setData(self::ATTRIBUTE_SET_ID, $attributeSetId);
2484  }

◆ setCategoryCollection()

setCategoryCollection ( \Magento\Framework\Data\Collection  $categoryCollection)
protected

Set product categories.

Parameters
\Magento\Framework\Data\Collection$categoryCollection
Returns
$this

Definition at line 792 of file Product.php.

793  {
794  $this->categoryCollection = $categoryCollection;
795  return $this;
796  }

◆ setCreatedAt()

setCreatedAt (   $createdAt)

Set product created date

Parameters
string$createdAt
Returns
$this

Implements ProductInterface.

Definition at line 2525 of file Product.php.

2526  {
2527  return $this->setData(self::CREATED_AT, $createdAt);
2528  }

◆ setCustomOptions()

setCustomOptions ( array  $options)

Sets custom options for the product

Parameters
array$optionsArray of options
Returns
void

Definition at line 2056 of file Product.php.

2057  {
2058  $this->_customOptions = $options;
2059  }

◆ setExtensionAttributes()

setExtensionAttributes ( \Magento\Catalog\Api\Data\ProductExtensionInterface  $extensionAttributes)

Set an extension attributes object.

Parameters
\Magento\Catalog\Api\Data\ProductExtensionInterface$extensionAttributes
Returns
$this

Implements ProductInterface.

Definition at line 2582 of file Product.php.

2583  {
2585  }
_setExtensionAttributes(\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)

◆ setFinalPrice()

setFinalPrice (   $price)

Sets final price of product

This func is equal to magic 'setFinalPrice()', but added as a separate func, because in cart with bundle products it's called very often in Item->getProduct(). So removing chain of magic with more cpu consuming algorithms gives nice optimization boost.

Parameters
float$pricePrice amount
Returns
\Magento\Catalog\Model\Product

Definition at line 1189 of file Product.php.

1190  {
1191  $this->_data['final_price'] = $price;
1192  return $this;
1193  }
$price

◆ setId()

setId (   $value)

Set entity Id

Parameters
int$value
Returns
$this
Since
101.0.0

Implements ProductInterface.

Definition at line 2666 of file Product.php.

2667  {
2668  return $this->setData('entity_id', $value);
2669  }
$value
Definition: gender.phtml:16

◆ setIsDuplicable()

setIsDuplicable (   $value)

Set is duplicable flag

Parameters
boolean$value
Returns
\Magento\Catalog\Model\Product

Definition at line 1660 of file Product.php.

1661  {
1662  $this->_isDuplicable = (bool)$value;
1663  return $this;
1664  }
$value
Definition: gender.phtml:16

◆ setMediaGalleryEntries()

setMediaGalleryEntries ( array  $mediaGalleryEntries = null)

Set media gallery entries

Parameters
ProductAttributeMediaGalleryEntryInterface[]$mediaGalleryEntries
Returns
$this
Exceptions

Implements ProductInterface.

Definition at line 2633 of file Product.php.

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  }

◆ setName()

setName (   $name)

Set product name

Parameters
string$name
Returns
$this

Implements ProductInterface.

Definition at line 2459 of file Product.php.

2460  {
2461  return $this->setData(self::NAME, $name);
2462  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ setOptions()

setOptions ( array  $options = null)

Set options for product

Parameters

Implements ProductInterface.

Definition at line 2015 of file Product.php.

2016  {
2017  $this->setData('options', $options);
2018  return $this;
2019  }

◆ setPrice()

setPrice (   $price)

Set product price

Parameters
float$price
Returns
$this

Implements ProductInterface.

Definition at line 2492 of file Product.php.

2493  {
2494  return $this->setData(self::PRICE, $price);
2495  }
$price

◆ setPriceCalculation()

setPriceCalculation (   $calculate = true)

Set Price calculation flag

Parameters
bool$calculate
Returns
void
Deprecated:
102.0.4

Definition at line 643 of file Product.php.

644  {
645  $this->_calculatePrice = $calculate;
646  }

◆ setProductLinks()

setProductLinks ( array  $links = null)

Set product links info

Parameters

Implements ProductInterface.

Definition at line 1463 of file Product.php.

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  }

◆ setQty()

setQty (   $qty)

Set quantity for product

Parameters
float$qty
Returns
$this

Definition at line 974 of file Product.php.

975  {
976  if ($this->getData('qty') != $qty) {
977  $this->setData('qty', $qty);
978  $this->reloadPriceInfo();
979  }
980  return $this;
981  }

◆ setQuantityAndStockStatus()

setQuantityAndStockStatus (   $quantityAndStockStatusData)

Set quantity and stock status data

Parameters
array$quantityAndStockStatusData
Returns
$this
Deprecated:
102.0.0 as Product model shouldn't be responsible for stock status
See also
StockItemInterface when you want to change the stock data
StockStatusInterface when you want to read the stock data for representation layer (storefront)
StockItemRepositoryInterface::save as extension point for customization of saving process
Since
102.0.0

Definition at line 2740 of file Product.php.

2741  {
2742  $this->setData('quantity_and_stock_status', $quantityAndStockStatusData);
2743  return $this;
2744  }

◆ setSku()

setSku (   $sku)

Set product sku

Parameters
string$sku
Returns
$this

Implements ProductInterface.

Definition at line 2448 of file Product.php.

2449  {
2450  return $this->setData(self::SKU, $sku);
2451  }

◆ setStatus()

setStatus (   $status)

Set product status

Parameters
int$status
Returns
$this

Implements ProductInterface.

Definition at line 2503 of file Product.php.

2504  {
2505  return $this->setData(self::STATUS, $status);
2506  }
$status
Definition: order_status.php:8

◆ setStockData()

setStockData (   $stockData)

Set stock data

Parameters
array$stockData
Returns
$this
Deprecated:
102.0.0 as Product model shouldn't be responsible for stock status
See also
StockItemInterface when you want to change the stock data
StockStatusInterface when you want to read the stock data for representation layer (storefront)
StockItemRepositoryInterface::save as extension point for customization of saving process
Since
102.0.0

Definition at line 2774 of file Product.php.

2775  {
2776  $this->setData('stock_data', $stockData);
2777  return $this;
2778  }
$stockData
Definition: products.php:27

◆ setStoreId()

setStoreId (   $storeId)

Set product store id

Parameters
int$storeId
Returns
$this

Definition at line 2470 of file Product.php.

2471  {
2472  return $this->setData(self::STORE_ID, $storeId);
2473  }

◆ setTierPrices()

setTierPrices ( array  $tierPrices = null)

Sets list of product tier prices

Parameters

Implements ProductInterface.

Definition at line 1138 of file Product.php.

1139  {
1140  $this->getPriceModel()->setTierPrices($this, $tierPrices);
1141  return $this;
1142  }

◆ setTypeId()

setTypeId (   $typeId)

Set product type id

Parameters
string$typeId
Returns
$this

Implements ProductInterface.

Definition at line 2558 of file Product.php.

2559  {
2560  if ($typeId !== $this->_getData('type_id')) {
2561  $this->_typeInstance = null;
2562  }
2563  return $this->setData(self::TYPE_ID, $typeId);
2564  }

◆ setTypeInstance()

setTypeInstance (   $instance)

Set type instance for the product

Parameters
\Magento\Catalog\Model\Product\Type\AbstractType | null$instanceProduct type instance
Returns
\Magento\Catalog\Model\Product

Definition at line 692 of file Product.php.

693  {
694  $this->_typeInstance = $instance;
695  return $this;
696  }

◆ setUpdatedAt()

setUpdatedAt (   $updatedAt)

Set product updated date

Parameters
string$updatedAt
Returns
$this

Implements ProductInterface.

Definition at line 2536 of file Product.php.

2537  {
2538  return $this->setData(self::UPDATED_AT, $updatedAt);
2539  }

◆ setVisibility()

setVisibility (   $visibility)

Set product visibility

Parameters
int$visibility
Returns
$this

Implements ProductInterface.

Definition at line 2514 of file Product.php.

2515  {
2516  return $this->setData(self::VISIBILITY, $visibility);
2517  }

◆ setWeight()

setWeight (   $weight)

Set product weight

Parameters
float$weight
Returns
$this

Implements ProductInterface.

Definition at line 2547 of file Product.php.

2548  {
2549  return $this->setData(self::WEIGHT, $weight);
2550  }

◆ toArray()

toArray ( array  $arrAttributes = [])

Renders the object to array

Parameters
array$arrAttributesAttribute array
Returns
array

Definition at line 1843 of file Product.php.

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  }
$stock

◆ validate()

validate ( )

Validate Product Data

Todo:
implement full validation process with errors returning which are ignoring now
Returns
array

Definition at line 558 of file Product.php.

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  }

Field Documentation

◆ $_cacheTag

$_cacheTag = self::CACHE_TAG
protected

Definition at line 77 of file Product.php.

◆ $_calculatePrice

$_calculatePrice = true
protected

Definition at line 169 of file Product.php.

◆ $_canAffectOptions

$_canAffectOptions = false
protected

Definition at line 92 of file Product.php.

◆ $_catalogProduct

$_catalogProduct = null
protected

Definition at line 176 of file Product.php.

◆ $_catalogProductMediaConfig

$_catalogProductMediaConfig
protected

Definition at line 200 of file Product.php.

◆ $_catalogProductStatus

$_catalogProductStatus
protected

Definition at line 207 of file Product.php.

◆ $_catalogProductType

$_catalogProductType
protected

Definition at line 193 of file Product.php.

◆ $_catalogProductVisibility

$_catalogProductVisibility
protected

Definition at line 214 of file Product.php.

◆ $_collectionFactory

$_collectionFactory
protected

Definition at line 186 of file Product.php.

◆ $_customOptions

$_customOptions = []
protected

Definition at line 113 of file Product.php.

◆ $_errors

$_errors = []
protected

Definition at line 136 of file Product.php.

◆ $_eventObject

$_eventObject = 'product'
protected

Definition at line 87 of file Product.php.

◆ $_eventPrefix

$_eventPrefix = 'catalog_product'
protected

Definition at line 82 of file Product.php.

◆ $_filesystem

$_filesystem
protected

Definition at line 235 of file Product.php.

◆ $_isDuplicable

$_isDuplicable = true
protected

Definition at line 162 of file Product.php.

◆ $_itemOptionFactory

$_itemOptionFactory
protected

Definition at line 228 of file Product.php.

◆ $_linkInstance

$_linkInstance
protected

Definition at line 106 of file Product.php.

◆ $_links

$_links = null
protected

Definition at line 155 of file Product.php.

◆ $_priceInfo

$_priceInfo
protected

Definition at line 260 of file Product.php.

◆ $_productEavIndexerProcessor

$_productEavIndexerProcessor
protected

Definition at line 255 of file Product.php.

◆ $_productFlatIndexerProcessor

$_productFlatIndexerProcessor
protected

Definition at line 245 of file Product.php.

◆ $_productIdCached

$_productIdCached
protected

Definition at line 313 of file Product.php.

◆ $_productPriceIndexerProcessor

$_productPriceIndexerProcessor
protected

Definition at line 250 of file Product.php.

◆ $_resource

$_resource
protected

Definition at line 126 of file Product.php.

◆ $_stockItemFactory

$_stockItemFactory
protected

Definition at line 221 of file Product.php.

◆ $_typeInstance

$_typeInstance = null
protected

Definition at line 99 of file Product.php.

◆ $_url

$_url
staticprotected

Definition at line 131 of file Product.php.

◆ $_urlModel

$_urlModel = null
protected

Definition at line 120 of file Product.php.

◆ $categoryCollection

$categoryCollection
protected

Definition at line 272 of file Product.php.

◆ $categoryRepository

$categoryRepository
protected

Definition at line 265 of file Product.php.

◆ $dataObjectHelper

$dataObjectHelper
protected

Definition at line 308 of file Product.php.

◆ $entityCollectionProvider

$entityCollectionProvider
protected
Parameters

Definition at line 288 of file Product.php.

◆ $imageCacheFactory

$imageCacheFactory
protected

Definition at line 277 of file Product.php.

◆ $indexerRegistry

$indexerRegistry
protected

Definition at line 240 of file Product.php.

◆ $interfaceAttributes

$interfaceAttributes = ProductInterface::ATTRIBUTES
protected

Definition at line 322 of file Product.php.

◆ $joinProcessor

$joinProcessor
protected

Definition at line 327 of file Product.php.

◆ $linkProvider

$linkProvider
protected
Parameters

Definition at line 293 of file Product.php.

◆ $linkRepository

$linkRepository
protected

Definition at line 51 of file Product.php.

◆ $linkTypeProvider

$linkTypeProvider
protected

Definition at line 346 of file Product.php.

◆ $mediaGalleryEntryConverterPool

$mediaGalleryEntryConverterPool
protected

Definition at line 334 of file Product.php.

◆ $mediaGalleryProcessor

$mediaGalleryProcessor
protected

Definition at line 340 of file Product.php.

◆ $metadataService

$metadataService
protected

Definition at line 283 of file Product.php.

◆ $moduleManager

$moduleManager
protected

Definition at line 181 of file Product.php.

◆ $optionFactory

$optionFactory
protected

Definition at line 143 of file Product.php.

◆ $optionInstance

$optionInstance
protected

Definition at line 150 of file Product.php.

◆ $productLinkExtensionFactory

$productLinkExtensionFactory
protected
Parameters

Definition at line 303 of file Product.php.

◆ $productLinkFactory

$productLinkFactory
protected
Parameters

Definition at line 298 of file Product.php.

◆ CACHE_PRODUCT_CATEGORY_TAG

const CACHE_PRODUCT_CATEGORY_TAG = 'cat_c_p'

Category product relation cache tag

Definition at line 67 of file Product.php.

◆ CACHE_TAG

const CACHE_TAG = 'cat_p'

Product cache tag

Definition at line 62 of file Product.php.

◆ ENTITY

const ENTITY = 'catalog_product'

Entity code. Can be used as part of method name for entity processing

Definition at line 57 of file Product.php.

◆ STORE_ID

const STORE_ID = 'store_id'

Product Store Id

Definition at line 72 of file Product.php.


The documentation for this class was generated from the following file: