/**
  * @param Action $subject
  * @param \Closure $proceed
  * @param array $productIds
  * @param array $attrData
  * @param int $storeId
  * @return Action
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundUpdateAttributes(Action $subject, \Closure $proceed, $productIds, $attrData, $storeId)
 {
     $returnValue = $proceed($productIds, $attrData, $storeId);
     $this->cacheContext->registerEntities(Product::CACHE_TAG, $productIds);
     $this->eventManager->dispatch('clean_cache_by_tags', ['object' => $this->cacheContext]);
     return $returnValue;
 }
示例#2
0
 /**
  * test getIdentities
  */
 public function testGetIdentities()
 {
     $expectedIdentities = ['product_1', 'product_2', 'product_3', 'category_5', 'category_6', 'category_7'];
     $productTag = 'product';
     $categoryTag = 'category';
     $productIds = [1, 2, 3];
     $categoryIds = [5, 6, 7];
     $this->context->registerEntities($productTag, $productIds);
     $this->context->registerEntities($categoryTag, $categoryIds);
     $actualIdentities = $this->context->getIdentities();
     $this->assertEquals($expectedIdentities, $actualIdentities);
 }
示例#3
0
 /**
  * Refresh entities index
  *
  * @param array $productIds
  * @return array Affected ids
  */
 protected function _reindexRows($productIds = [])
 {
     $adapter = $this->_getConnection();
     if (!is_array($productIds)) {
         $productIds = [$productIds];
     }
     $parentIds = $this->getRelationsByChild($productIds);
     $processIds = $parentIds ? array_merge($parentIds, $productIds) : $productIds;
     // retrieve product types by processIds
     $select = $adapter->select()->from($this->_getTable('catalog_product_entity'), ['entity_id', 'type_id'])->where('entity_id IN(?)', $processIds);
     $pairs = $adapter->fetchPairs($select);
     $byType = [];
     foreach ($pairs as $productId => $typeId) {
         $byType[$typeId][$productId] = $productId;
     }
     $indexers = $this->_getTypeIndexers();
     foreach ($indexers as $indexer) {
         if (isset($byType[$indexer->getTypeId()])) {
             $indexer->reindexEntity($byType[$indexer->getTypeId()]);
         }
     }
     $select = $adapter->select()->distinct(true)->from($this->_getTable('catalog_category_product'), ['category_id'])->where('product_id IN(?)', $processIds);
     $affectedCategories = $adapter->fetchCol($select);
     $this->cacheContext->registerEntities(Category::CACHE_TAG, $affectedCategories);
     $this->eventManager->dispatch('clean_cache_by_tags', ['object' => $this->cacheContext]);
     return $this;
 }
示例#4
0
 /**
  * @param \Magento\Indexer\Model\ActionInterface $subject
  * @param array $ids
  * @return array
  */
 public function beforeExecute(\Magento\Indexer\Model\ActionInterface $subject, $ids)
 {
     $this->context->registerEntities(\Magento\Catalog\Model\Product::CACHE_TAG, $ids);
     return array($ids);
 }