Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Action Class Reference
Inheritance diagram for Action:
AbstractModel DataObject View

Public Member Functions

 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Catalog\Model\Product\WebsiteFactory $productWebsiteFactory, \Magento\Framework\Indexer\IndexerRegistry $indexerRegistry, \Magento\Eav\Model\Config $eavConfig, \Magento\Catalog\Model\Indexer\Product\Eav\Processor $productEavIndexerProcessor, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 updateAttributes ($productIds, $attrData, $storeId)
 
 updateWebsites ($productIds, $websiteIds, $type)
 
- 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)
 

Protected Member Functions

 _construct ()
 
 _hasIndexableAttributes ($attributesData)
 
 _attributeIsIndexable ($attribute)
 
- 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

 $_productWebsiteFactory
 
 $indexerRegistry
 
 $_eavConfig
 
 $_productEavIndexerProcessor
 
- 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 = []
 

Additional Inherited Members

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

Detailed Description

Catalog Product Mass Action processing model

@api

Author
Magento Core Team core@.nosp@m.mage.nosp@m.ntoco.nosp@m.mmer.nosp@m.ce.co.nosp@m.m
Since
100.0.2

Definition at line 17 of file Action.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\Model\Context  $context,
\Magento\Framework\Registry  $registry,
\Magento\Catalog\Model\Product\WebsiteFactory  $productWebsiteFactory,
\Magento\Framework\Indexer\IndexerRegistry  $indexerRegistry,
\Magento\Eav\Model\Config  $eavConfig,
\Magento\Catalog\Model\Indexer\Product\Eav\Processor  $productEavIndexerProcessor,
\Magento\Framework\Model\ResourceModel\AbstractResource  $resource = null,
\Magento\Framework\Data\Collection\AbstractDb  $resourceCollection = null,
array  $data = [] 
)
Parameters
\Magento\Framework\Model\Context$context
\Magento\Framework\Registry$registry
WebsiteFactory$productWebsiteFactory
\Magento\Framework\Indexer\IndexerRegistry$indexerRegistry
\Magento\Eav\Model\Config$eavConfig
\Magento\Catalog\Model\Indexer\Product\Eav\Processor$productEavIndexerProcessor
\Magento\Framework\Model\ResourceModel\AbstractResource$resource
\Magento\Framework\Data\Collection\AbstractDb$resourceCollection
array$data

Definition at line 52 of file Action.php.

62  {
63  $this->_productWebsiteFactory = $productWebsiteFactory;
64  $this->indexerRegistry = $indexerRegistry;
65  $this->_eavConfig = $eavConfig;
66  $this->_productEavIndexerProcessor = $productEavIndexerProcessor;
67  parent::__construct($context, $registry, $resource, $resourceCollection, $data);
68  }
$resource
Definition: bulk.php:12

Member Function Documentation

◆ _attributeIsIndexable()

_attributeIsIndexable (   $attribute)
protected

Check is attribute indexable in EAV

Parameters
\Magento\Catalog\Model\ResourceModel\Eav\Attribute | string$attribute
Returns
bool

Definition at line 134 of file Action.php.

135  {
136  if (!$attribute instanceof \Magento\Catalog\Model\ResourceModel\Eav\Attribute) {
137  $attribute = $this->_eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $attribute);
138  }
139 
140  return $attribute->isIndexable();
141  }

◆ _construct()

_construct ( )
protected

Initialize resource model

Returns
void

Definition at line 75 of file Action.php.

76  {
77  $this->_init(\Magento\Catalog\Model\ResourceModel\Product\Action::class);
78  }

◆ _hasIndexableAttributes()

_hasIndexableAttributes (   $attributesData)
protected

Attributes array has indexable attributes

Parameters
array$attributesData
Returns
bool @SuppressWarnings(PHPMD.UnusedLocalVariable)

Definition at line 118 of file Action.php.

119  {
120  foreach ($attributesData as $code => $value) {
121  if ($this->_attributeIsIndexable($code)) {
122  return true;
123  }
124  }
125  return false;
126  }
$attributesData
$value
Definition: gender.phtml:16
$code
Definition: info.phtml:12

◆ updateAttributes()

updateAttributes (   $productIds,
  $attrData,
  $storeId 
)

Update attribute values for entity list per store

Parameters
array$productIds
array$attrData
int$storeId
Returns
$this

Definition at line 88 of file Action.php.

89  {
90  $this->_eventManager->dispatch(
91  'catalog_product_attribute_update_before',
92  ['attributes_data' => &$attrData, 'product_ids' => &$productIds, 'store_id' => &$storeId]
93  );
94 
95  $this->_getResource()->updateAttributes($productIds, $attrData, $storeId);
96  $this->setData(
97  ['product_ids' => array_unique($productIds), 'attributes_data' => $attrData, 'store_id' => $storeId]
98  );
99 
100  if ($this->_hasIndexableAttributes($attrData)) {
101  $this->_productEavIndexerProcessor->reindexList(array_unique($productIds));
102  }
103 
104  $categoryIndexer = $this->indexerRegistry->get(\Magento\Catalog\Model\Indexer\Product\Category::INDEXER_ID);
105  if (!$categoryIndexer->isScheduled()) {
106  $categoryIndexer->reindexList(array_unique($productIds));
107  }
108  return $this;
109  }
_hasIndexableAttributes($attributesData)
Definition: Action.php:118

◆ updateWebsites()

updateWebsites (   $productIds,
  $websiteIds,
  $type 
)

Update websites for product action

Allowed types:

  • add
  • remove
Parameters
array$productIds
array$websiteIds
string$type
Returns
void

Definition at line 155 of file Action.php.

156  {
157  if ($type == 'add') {
158  $this->_productWebsiteFactory->create()->addProducts($websiteIds, $productIds);
159  } elseif ($type == 'remove') {
160  $this->_productWebsiteFactory->create()->removeProducts($websiteIds, $productIds);
161  }
162 
163  $this->setData(
164  ['product_ids' => array_unique($productIds), 'website_ids' => $websiteIds, 'action_type' => $type]
165  );
166 
167  $categoryIndexer = $this->indexerRegistry->get(\Magento\Catalog\Model\Indexer\Product\Category::INDEXER_ID);
168  if (!$categoryIndexer->isScheduled()) {
169  $categoryIndexer->reindexList(array_unique($productIds));
170  }
171  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$type
Definition: item.phtml:13

Field Documentation

◆ $_eavConfig

$_eavConfig
protected

Definition at line 34 of file Action.php.

◆ $_productEavIndexerProcessor

$_productEavIndexerProcessor
protected

Definition at line 39 of file Action.php.

◆ $_productWebsiteFactory

$_productWebsiteFactory
protected

Definition at line 24 of file Action.php.

◆ $indexerRegistry

$indexerRegistry
protected

Definition at line 29 of file Action.php.


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