Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Product Class Reference
Inheritance diagram for Product:
AbstractResource AbstractEntity AbstractResource EntityInterface ProviderInterface ResourceModel

Public Member Functions

 __construct (\Magento\Eav\Model\Entity\Context $context, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Catalog\Model\Factory $modelFactory, \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory, Category $catalogCategory, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Eav\Model\Entity\Attribute\SetFactory $setFactory, \Magento\Eav\Model\Entity\TypeFactory $typeFactory, \Magento\Catalog\Model\Product\Attribute\DefaultAttributes $defaultAttributes, $data=[], TableMaintainer $tableMaintainer=null)
 
 getEntityType ()
 
 getProductWebsiteTable ()
 
 getProductCategoryTable ()
 
 getWebsiteIds ($product)
 
 getWebsiteIdsByProductIds ($productIds)
 
 getCategoryIds ($product)
 
 getIdBySku ($sku)
 
 delete ($object)
 
 getAvailableInCategories ($object)
 
 getDefaultAttributeSourceModel ()
 
 canBeShowInCategory ($product, $categoryId)
 
 duplicate ($oldId, $newId)
 
 getProductsSku (array $productIds)
 
 getProductsIdsBySkus (array $productSkuList)
 
 getProductEntitiesInfo ($columns=null)
 
 countAll ()
 
 validate ($object)
 
 load ($object, $entityId, $attributes=[])
 
 save (\Magento\Framework\Model\AbstractModel $object)
 
- Public Member Functions inherited from AbstractResource
 __construct (\Magento\Eav\Model\Entity\Context $context, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Catalog\Model\Factory $modelFactory, $data=[])
 
 getDefaultStoreId ()
 
 getAttributeRawValue ($entityId, $attribute, $store)
 
- Public Member Functions inherited from AbstractEntity
 __construct (Context $context, $data=[])
 
 setConnection ($connection)
 
 getConnection ()
 
 getIdFieldName ()
 
 getTable ($alias)
 
 setType ($type)
 
 getEntityType ()
 
 getType ()
 
 getTypeId ()
 
 unsetAttributes ($attributes=null)
 
 addAttribute (AbstractAttribute $attribute, $object=null)
 
 isPartialLoad ($flag=null)
 
 isPartialSave ($flag=null)
 
 loadAllAttributes ($object=null)
 
 getSortedAttributes ($setId=null)
 
 attributesCompare ($firstAttribute, $secondAttribute)
 
 getAttributesByCode ()
 
 getAttributesByTable ()
 
 getEntityTable ()
 
 getLinkField ()
 
 getEntityIdField ()
 
 getValueEntityIdField ()
 
 getValueTablePrefix ()
 
 getEntityTablePrefix ()
 
 isAttributeStatic ($attribute)
 
 validate ($object)
 
 setNewIncrementId (DataObject $object)
 
 checkAttributeUniqueValue (AbstractAttribute $attribute, $object)
 
 getDefaultAttributeSourceModel ()
 
 load ($object, $entityId, $attributes=[])
 
 save (\Magento\Framework\Model\AbstractModel $object)
 
 saveAttribute (DataObject $object, $attributeCode)
 
 delete ($object)
 
 getDefaultAttributes ()
 
 afterLoad (DataObject $object)
 
 beforeSave (DataObject $object)
 
 afterSave (DataObject $object)
 
 beforeDelete (DataObject $object)
 
 afterDelete (DataObject $object)
 
- Public Member Functions inherited from AbstractResource
 __construct ()
 
 getConnection ()
 
 beginTransaction ()
 
 addCommitCallback ($callback)
 
 commit ()
 
 rollBack ()
 
 getValidationRulesBeforeSave ()
 

Protected Member Functions

 _getDefaultAttributes ()
 
 _beforeSave (\Magento\Framework\DataObject $object)
 
 _afterSave (\Magento\Framework\DataObject $product)
 
 _saveWebsiteIds ($product)
 
 _saveCategories (\Magento\Framework\DataObject $object)
 
 evaluateDelete ($object, $id, $connection)
 
 getAttributeRow ($entity, $object, $attribute)
 
- Protected Member Functions inherited from AbstractResource
 _getDefaultAttributeModel ()
 
 _isApplicableAttribute ($object, $attribute)
 
 _isCallableAttributeInstance ($instance, $method, $args)
 
 _getLoadAttributesSelect ($object, $table)
 
 _prepareLoadSelect (array $selects)
 
 _saveAttributeValue ($object, $attribute, $value)
 
 _insertAttribute ($object, $attribute, $value)
 
 _updateAttribute ($object, $attribute, $valueId, $value)
 
 _updateAttributeForStore ($object, $attribute, $value, $storeId)
 
 _deleteAttributes ($object, $table, $info)
 
 _getOrigObject ($object)
 
 _canUpdateAttribute (AbstractAttribute $attribute, $value, array &$origData)
 
- Protected Member Functions inherited from AbstractEntity
 _construct ()
 
 _getConfig ()
 
 _isApplicableAttribute ($object, $attribute)
 
 _isCallableAttributeInstance ($instance, $method, $args)
 
 loadAttributesMetadata ($attributes)
 
 _loadModelAttributes ($object)
 
 _prepareLoadSelect (array $selects)
 
 _getLoadRowSelect ($object, $rowId)
 
 _getLoadAttributesSelect ($object, $table)
 
 _setAttributeValue ($object, $valueRow)
 
 processSave ($object)
 
 _getOrigObject ($object)
 
 _collectSaveData ($newObject)
 
 _canUpdateAttribute (AbstractAttribute $attribute, $v, array &$origData)
 
 _getStaticFieldProperties ($field)
 
 _prepareStaticValue ($key, $value)
 
 _insertAttribute ($object, $attribute, $value)
 
 _updateAttribute ($object, $attribute, $valueId, $value)
 
 _saveAttribute ($object, $attribute, $value)
 
 _processAttributeValues ()
 
 _prepareValueForSave ($value, AbstractAttribute $attribute)
 
 _deleteAttributes ($object, $table, $info)
 
 getAttributeRow ($entity, $object, $attribute)
 
 evaluateDelete ($object, $id, $connection)
 
 _afterLoad (DataObject $object)
 
 _beforeSave (DataObject $object)
 
 _afterSave (DataObject $object)
 
 _beforeDelete (DataObject $object)
 
 _afterDelete (DataObject $object)
 
 _getDefaultAttributeModel ()
 
 _getDefaultAttributes ()
 
 _isAttributeValueEmpty (AbstractAttribute $attribute, $value)
 
 getAttributeLoader ()
 
 loadAttributesForObject ($attributes, $object=null)
 
- Protected Member Functions inherited from AbstractResource
 _construct ()
 
 _serializeField (DataObject $object, $field, $defaultValue=null, $unsetEmpty=false)
 
 _unserializeField (DataObject $object, $field, $defaultValue=null)
 
 _prepareDataForTable (DataObject $object, $table)
 
 _prepareTableValueForSave ($value, $type)
 
 _getColumnsForEntityLoad (\Magento\Framework\Model\AbstractModel $object, $tableName)
 
 getSerializer ()
 

Protected Attributes

 $_productWebsiteTable
 
 $_productCategoryTable
 
 $_catalogCategory
 
 $_categoryCollectionFactory
 
 $eventManager
 
 $setFactory
 
 $typeFactory
 
 $entityManager
 
 $defaultAttributes
 
 $availableCategoryIdsCache = []
 
- Protected Attributes inherited from AbstractResource
 $_storeManager
 
 $_modelFactory
 
- Protected Attributes inherited from AbstractEntity
 $attributeLoader
 
 $connectionName
 
 $_type
 
 $_attributesByCode = []
 
 $_attributesByTable = []
 
 $_staticAttributes = []
 
 $_entityTable
 
 $_describeTable = []
 
 $_entityIdField
 
 $linkIdField
 
 $_valueEntityIdField
 
 $_valueTablePrefix
 
 $_entityTablePrefix
 
 $_isPartialLoad = false
 
 $_isPartialSave = false
 
 $_sortingSetId = null
 
 $_attributeValuesToDelete = []
 
 $_attributeValuesToSave = []
 
 $_resource
 
 $_eavConfig
 
 $_attrSetEntity
 
 $_localeFormat
 
 $_resourceHelper
 
 $_universalFactory
 
 $transactionManager
 
 $objectRelationProcessor
 
- Protected Attributes inherited from AbstractResource
 $serializer
 
 $_logger
 

Additional Inherited Members

- Static Protected Attributes inherited from AbstractEntity
static $_attributeBackendTables = []
 

Detailed Description

Product entity resource model

@api @SuppressWarnings(PHPMD.LongVariable) @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Since
100.0.2

Definition at line 20 of file Product.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Eav\Model\Entity\Context  $context,
\Magento\Store\Model\StoreManagerInterface  $storeManager,
\Magento\Catalog\Model\Factory  $modelFactory,
\Magento\Catalog\Model\ResourceModel\Category\CollectionFactory  $categoryCollectionFactory,
Category  $catalogCategory,
\Magento\Framework\Event\ManagerInterface  $eventManager,
\Magento\Eav\Model\Entity\Attribute\SetFactory  $setFactory,
\Magento\Eav\Model\Entity\TypeFactory  $typeFactory,
\Magento\Catalog\Model\Product\Attribute\DefaultAttributes  $defaultAttributes,
  $data = [],
TableMaintainer  $tableMaintainer = null 
)
Parameters
\Magento\Eav\Model\Entity\Context$context
\Magento\Store\Model\StoreManagerInterface$storeManager
\Magento\Catalog\Model\Factory$modelFactory
Category\CollectionFactory$categoryCollectionFactory
Category$catalogCategory
\Magento\Framework\Event\ManagerInterface$eventManager
\Magento\Eav\Model\Entity\Attribute\SetFactory$setFactory
\Magento\Eav\Model\Entity\TypeFactory$typeFactory
\Magento\Catalog\Model\Product\Attribute\DefaultAttributes$defaultAttributes
array$data
TableMaintainer | null$tableMaintainer@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 107 of file Product.php.

119  {
120  $this->_categoryCollectionFactory = $categoryCollectionFactory;
121  $this->_catalogCategory = $catalogCategory;
122  $this->eventManager = $eventManager;
123  $this->setFactory = $setFactory;
124  $this->typeFactory = $typeFactory;
125  $this->defaultAttributes = $defaultAttributes;
126  parent::__construct(
127  $context,
129  $modelFactory,
130  $data
131  );
132  $this->connectionName = 'catalog';
133  $this->tableMaintainer = $tableMaintainer ?: ObjectManager::getInstance()->get(TableMaintainer::class);
134  }
$storeManager

Member Function Documentation

◆ _afterSave()

_afterSave ( \Magento\Framework\DataObject  $product)
protected

Save data related with product

Parameters
\Magento\Framework\DataObject$product
Returns
$this

Definition at line 285 of file Product.php.

286  {
287  $this->_saveWebsiteIds($product)->_saveCategories($product);
288  return parent::_afterSave($product);
289  }

◆ _beforeSave()

_beforeSave ( \Magento\Framework\DataObject  $object)
protected

Process product data before save

Parameters
\Magento\Framework\DataObject$object
Returns
$this

Try detect product id by sku if id is not declared

Definition at line 267 of file Product.php.

268  {
269  $self = parent::_beforeSave($object);
273  if (!$object->getId() && $object->getSku()) {
274  $object->setId($this->getIdBySku($object->getSku()));
275  }
276  return $self;
277  }

◆ _getDefaultAttributes()

_getDefaultAttributes ( )
protected

Default product attributes

Returns
string[]

Definition at line 182 of file Product.php.

183  {
184  return $this->defaultAttributes->getDefaultAttributes();
185  }

◆ _saveCategories()

_saveCategories ( \Magento\Framework\DataObject  $object)
protected

Save product category relations

Parameters
\Magento\Framework\DataObject$object
Returns
$this @SuppressWarnings(PHPMD.UnusedFormalParameter)
Deprecated:
102.0.0

Definition at line 338 of file Product.php.

339  {
340  return $this;
341  }

◆ _saveWebsiteIds()

_saveWebsiteIds (   $product)
protected

Save product website relations

Deprecated:
102.0.0
Parameters
\Magento\Catalog\Model\Product$product
Returns
$this

Definition at line 311 of file Product.php.

312  {
313  if ($product->hasWebsiteIds()) {
314  if ($this->_storeManager->isSingleStoreMode()) {
315  $id = $this->_storeManager->getDefaultStoreView()->getWebsiteId();
316  $product->setWebsiteIds([$id]);
317  }
318  $websiteIds = $product->getWebsiteIds();
319  $product->setIsChangedWebsites(false);
320  $changed = $this->getProductWebsiteLink()->saveWebsiteIds($product, $websiteIds);
321 
322  if ($changed) {
323  $product->setIsChangedWebsites(true);
324  }
325  }
326 
327  return $this;
328  }
$id
Definition: fieldset.phtml:14

◆ canBeShowInCategory()

canBeShowInCategory (   $product,
  $categoryId 
)

Check availability display product in category

Parameters
\Magento\Catalog\Model\Product$product
int$categoryId
Returns
string

Definition at line 431 of file Product.php.

432  {
433  $select = $this->getConnection()->select()->from(
434  $this->tableMaintainer->getMainTable($product->getStoreId()),
435  'product_id'
436  )->where(
437  'product_id = ?',
438  (int)$product->getEntityId()
439  )->where(
440  'category_id = ?',
441  (int)$categoryId
442  );
443 
444  return $this->getConnection()->fetchOne($select);
445  }

◆ countAll()

countAll ( )

Get total number of records in the system

Returns
int

Definition at line 586 of file Product.php.

587  {
588  $connection = $this->getConnection();
589  $select = $connection->select();
590  $select->from($this->getEntityTable(), 'COUNT(*)');
591  $result = (int)$connection->fetchOne($select);
592  return $result;
593  }
$connection
Definition: bulk.php:13

◆ delete()

delete (   $object)

{}

Definition at line 294 of file Product.php.

295  {
296  $this->getEntityManager()->delete($object);
297  $this->eventManager->dispatch(
298  'catalog_product_delete_after_done',
299  ['product' => $object]
300  );
301  return $this;
302  }

◆ duplicate()

duplicate (   $oldId,
  $newId 
)

Duplicate product store values

Parameters
int$oldId
int$newId
Returns
$this

Definition at line 454 of file Product.php.

455  {
456  $eavTables = ['datetime', 'decimal', 'int', 'text', 'varchar'];
457  $connection = $this->getConnection();
458 
459  // duplicate EAV store values
460  foreach ($eavTables as $suffix) {
461  $tableName = $this->getTable(['catalog_product_entity', $suffix]);
462 
463  $select = $connection->select()->from(
464  $tableName,
465  [
466  'attribute_id',
467  'store_id',
468  $this->getLinkField() => new \Zend_Db_Expr($connection->quote($newId)),
469  'value'
470  ]
471  )->where(
472  $this->getLinkField() . ' = ?',
473  $oldId
474  );
475 
476  $connection->query(
477  $connection->insertFromSelect(
478  $select,
479  $tableName,
480  ['attribute_id', 'store_id', $this->getLinkField(), 'value'],
482  )
483  );
484  }
485 
486  // set status as disabled
487  $statusAttribute = $this->getAttribute('status');
488  $statusAttributeId = $statusAttribute->getAttributeId();
489  $statusAttributeTable = $statusAttribute->getBackend()->getTable();
490  $updateCond[] = $connection->quoteInto($this->getLinkField() . ' = ?', $newId);
491  $updateCond[] = $connection->quoteInto('attribute_id = ?', $statusAttributeId);
492  $connection->update(
493  $statusAttributeTable,
494  ['value' => \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED],
495  $updateCond
496  );
497 
498  return $this;
499  }
$tableName
Definition: trigger.php:13
$suffix
Definition: name.phtml:27
$connection
Definition: bulk.php:13

◆ evaluateDelete()

evaluateDelete (   $object,
  $id,
  $connection 
)
protected

{} @SuppressWarnings(PHPMD.UnusedLocalVariable)

Since
101.0.0

Definition at line 640 of file Product.php.

641  {
642  $where = [$this->getLinkField() . '=?' => $id];
643  $this->objectRelationProcessor->delete(
644  $this->transactionManager,
645  $connection,
646  $this->getEntityTable(),
647  $this->getConnection()->quoteInto(
648  $this->getLinkField() . '=?',
649  $id
650  ),
651  [$this->getLinkField() => $id]
652  );
653 
654  $this->loadAllAttributes($object);
655  foreach ($this->getAttributesByTable() as $table => $attributes) {
656  $this->getConnection()->delete(
657  $table,
658  $where
659  );
660  }
661  }
$id
Definition: fieldset.phtml:14
$attributes
Definition: matrix.phtml:13
$connection
Definition: bulk.php:13
$table
Definition: trigger.php:14

◆ getAttributeRow()

getAttributeRow (   $entity,
  $object,
  $attribute 
)
protected

Extends parent method to be appropriate for product. Store id is required to correctly identify attribute value we are working with.

{}

Since
102.0.0

Definition at line 718 of file Product.php.

719  {
720  $data = parent::getAttributeRow($entity, $object, $attribute);
721  $data['store_id'] = $object->getStoreId();
722  return $data;
723  }
$entity
Definition: element.phtml:22

◆ getAvailableInCategories()

getAvailableInCategories (   $object)

Retrieve category ids where product is available

Parameters
\Magento\Catalog\Model\Product$object
Returns
array

Definition at line 372 of file Product.php.

373  {
374  // is_parent=1 ensures that we'll get only category IDs those are direct parents of the product, instead of
375  // fetching all parent IDs, including those are higher on the tree
376  $entityId = (int)$object->getEntityId();
377  if (!isset($this->availableCategoryIdsCache[$entityId])) {
378  foreach ($this->_storeManager->getStores() as $store) {
379  $unionTables[] = $this->getAvailableInCategoriesSelect(
380  $entityId,
381  $this->tableMaintainer->getMainTable($store->getId())
382  );
383  }
384  $unionSelect = new \Magento\Framework\DB\Sql\UnionExpression(
385  $unionTables,
386  \Magento\Framework\DB\Select::SQL_UNION_ALL
387  );
388  $this->availableCategoryIdsCache[$entityId] = array_unique($this->getConnection()->fetchCol($unionSelect));
389  }
390  return $this->availableCategoryIdsCache[$entityId];
391  }
const SQL_UNION_ALL
Definition: Select.php:69

◆ getCategoryIds()

getCategoryIds (   $product)

Retrieve product category identifiers

Parameters
\Magento\Catalog\Model\Product$product
Returns
array

Definition at line 238 of file Product.php.

239  {
240  $result = $this->getProductCategoryLink()->getCategoryLinks($product);
241  return array_column($result, 'category_id');
242  }

◆ getDefaultAttributeSourceModel()

getDefaultAttributeSourceModel ( )

Get default attribute source model

Returns
string

Definition at line 419 of file Product.php.

420  {
421  return \Magento\Eav\Model\Entity\Attribute\Source\Table::class;
422  }

◆ getEntityType()

getEntityType ( )

Entity type getter and lazy loader

Returns
\Magento\Eav\Model\Entity\Type
Exceptions

Definition at line 142 of file Product.php.

143  {
144  if (empty($this->_type)) {
145  $this->setType(\Magento\Catalog\Model\Product::ENTITY);
146  }
147  return parent::getEntityType();
148  }

◆ getIdBySku()

getIdBySku (   $sku)

Get product identifier by sku

Parameters
string$sku
Returns
int|false

Definition at line 250 of file Product.php.

251  {
252  $connection = $this->getConnection();
253 
254  $select = $connection->select()->from($this->getEntityTable(), 'entity_id')->where('sku = :sku');
255 
256  $bind = [':sku' => (string)$sku];
257 
258  return $connection->fetchOne($select, $bind);
259  }
$connection
Definition: bulk.php:13

◆ getProductCategoryTable()

getProductCategoryTable ( )

Product Category table name getter

Deprecated:
102.0.0
Returns
string

Definition at line 169 of file Product.php.

170  {
171  if (!$this->_productCategoryTable) {
172  $this->_productCategoryTable = $this->getTable('catalog_category_product');
173  }
175  }

◆ getProductEntitiesInfo()

getProductEntitiesInfo (   $columns = null)

Retrieve product entities info

Parameters
array | string | null$columns
Returns
array

Definition at line 566 of file Product.php.

567  {
568  if (!empty($columns) && is_string($columns)) {
569  $columns = [$columns];
570  }
571  if (empty($columns) || !is_array($columns)) {
572  $columns = $this->_getDefaultAttributes();
573  }
574 
575  $connection = $this->getConnection();
576  $select = $connection->select()->from($this->getTable('catalog_product_entity'), $columns);
577 
578  return $connection->fetchAll($select);
579  }
$columns
Definition: default.phtml:15
$connection
Definition: bulk.php:13

◆ getProductsIdsBySkus()

getProductsIdsBySkus ( array  $productSkuList)

Get product ids by their sku

Parameters
array$productSkuList
Returns
array

Definition at line 525 of file Product.php.

526  {
527  $select = $this->getConnection()->select()->from(
528  $this->getTable('catalog_product_entity'),
529  ['sku', 'entity_id']
530  )->where(
531  'sku IN (?)',
533  );
534 
535  $result = [];
536  foreach ($this->getConnection()->fetchAll($select) as $row) {
537  $result[$this->getResultKey($row['sku'], $productSkuList)] = $row['entity_id'];
538  }
539  return $result;
540  }

◆ getProductsSku()

getProductsSku ( array  $productIds)

Get SKU through product identifiers

Parameters
array$productIds
Returns
array

Definition at line 507 of file Product.php.

508  {
509  $select = $this->getConnection()->select()->from(
510  $this->getTable('catalog_product_entity'),
511  ['entity_id', 'sku']
512  )->where(
513  'entity_id IN (?)',
515  );
516  return $this->getConnection()->fetchAll($select);
517  }

◆ getProductWebsiteTable()

getProductWebsiteTable ( )

Product Website table name getter

Returns
string

Definition at line 155 of file Product.php.

156  {
157  if (!$this->_productWebsiteTable) {
158  $this->_productWebsiteTable = $this->getTable('catalog_product_website');
159  }
161  }

◆ getWebsiteIds()

getWebsiteIds (   $product)

Retrieve product website identifiers

Deprecated:
102.0.0
Parameters
\Magento\Catalog\Model\Product | int$product
Returns
array

Definition at line 194 of file Product.php.

195  {
196  if ($product instanceof \Magento\Catalog\Model\Product) {
197  $productId = $product->getEntityId();
198  } else {
200  }
201 
202  return $this->getProductWebsiteLink()->getWebsiteIdsByProductId($productId);
203  }

◆ getWebsiteIdsByProductIds()

getWebsiteIdsByProductIds (   $productIds)

Retrieve product website identifiers by product identifiers

Parameters
array$productIds
Returns
array

Definition at line 211 of file Product.php.

212  {
213  $select = $this->getConnection()->select()->from(
214  $this->getProductWebsiteTable(),
215  ['product_id', 'website_id']
216  )->where(
217  'product_id IN (?)',
219  );
220  $productsWebsites = [];
221  foreach ($this->getConnection()->fetchAll($select) as $productInfo) {
222  $productId = $productInfo['product_id'];
223  if (!isset($productsWebsites[$productId])) {
224  $productsWebsites[$productId] = [];
225  }
226  $productsWebsites[$productId][] = $productInfo['website_id'];
227  }
228 
229  return $productsWebsites;
230  }

◆ load()

load (   $object,
  $entityId,
  $attributes = [] 
)

Reset firstly loaded attributes

Parameters
\Magento\Framework\Model\AbstractModel$object
integer$entityId
array | null$attributes
Returns
$this
Since
101.0.0

Definition at line 619 of file Product.php.

620  {
621  $select = $this->_getLoadRowSelect($object, $entityId);
622  $row = $this->getConnection()->fetchRow($select);
623 
624  if (is_array($row)) {
625  $object->addData($row);
626  } else {
627  $object->isObjectNew(true);
628  }
629 
630  $this->loadAttributesForObject($attributes, $object);
631  $this->getEntityManager()->load($object, $entityId);
632  return $this;
633  }
$attributes
Definition: matrix.phtml:13
loadAttributesForObject($attributes, $object=null)

◆ save()

Save entity's attributes into the object's resource

Parameters
\Magento\Framework\Model\AbstractModel$object
Returns
$this
Exceptions

Definition at line 671 of file Product.php.

672  {
673  $this->getEntityManager()->save($object);
674  return $this;
675  }

◆ validate()

validate (   $object)

{}

Definition at line 598 of file Product.php.

599  {
600  //validate attribute set entity type
601  $entityType = $this->typeFactory->create()->loadByCode(\Magento\Catalog\Model\Product::ENTITY);
602  $attributeSet = $this->setFactory->create()->load($object->getAttributeSetId());
603  if ($attributeSet->getEntityTypeId() != $entityType->getId()) {
604  return ['attribute_set' => 'Invalid attribute set entity type'];
605  }
606 
607  return parent::validate($object);
608  }

Field Documentation

◆ $_catalogCategory

$_catalogCategory
protected

Definition at line 41 of file Product.php.

◆ $_categoryCollectionFactory

$_categoryCollectionFactory
protected

Definition at line 48 of file Product.php.

◆ $_productCategoryTable

$_productCategoryTable
protected

Definition at line 34 of file Product.php.

◆ $_productWebsiteTable

$_productWebsiteTable
protected

Definition at line 27 of file Product.php.

◆ $availableCategoryIdsCache

$availableCategoryIdsCache = []
protected

Definition at line 80 of file Product.php.

◆ $defaultAttributes

$defaultAttributes
protected

Definition at line 74 of file Product.php.

◆ $entityManager

$entityManager
protected

Definition at line 69 of file Product.php.

◆ $eventManager

$eventManager
protected

Definition at line 53 of file Product.php.

◆ $setFactory

$setFactory
protected

Definition at line 58 of file Product.php.

◆ $typeFactory

$typeFactory
protected

Definition at line 63 of file Product.php.


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