/**
  * Reindex by product if indexer is not scheduled
  *
  * @param int[] $productIds
  * @return void
  */
 protected function reindexList(array $productIds)
 {
     $indexer = $this->indexerRegistry->get(Fulltext::INDEXER_ID);
     if (!$indexer->isScheduled()) {
         $indexer->reindexList($productIds);
     }
 }
Esempio n. 2
0
 /**
  * Execute materialization on ids entities
  *
  * @param int[] $ids
  * @return void
  */
 public function execute($ids)
 {
     $this->indexerRegistry->get(self::INDEXER_ID);
     /** @var Fulltext\Action\Rows $action */
     $action = $this->rowsActionFactory->create();
     $action->reindex($ids);
 }
Esempio n. 3
0
 /**
  * After save call
  * Invalidate catalog search index if engine was changed
  *
  * @return $this
  */
 public function afterSave()
 {
     parent::afterSave();
     if ($this->isValueChanged()) {
         $this->indexerRegistry->get(\Magento\CatalogSearch\Model\Indexer\Fulltext::INDEXER_ID)->invalidate();
     }
     return $this;
 }
Esempio n. 4
0
 /**
  * @param \Magento\Framework\Model\Resource\Db\AbstractDb $subject
  * @param callable $proceed
  * @param \Magento\Framework\Model\AbstractModel $group
  * @return mixed
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundSave(\Magento\Framework\Model\Resource\Db\AbstractDb $subject, \Closure $proceed, \Magento\Framework\Model\AbstractModel $group)
 {
     $needInvalidating = $this->validate($group);
     $objectResource = $proceed($group);
     if ($needInvalidating) {
         $this->indexerRegistry->get(\Magento\Catalog\Model\Indexer\Category\Product::INDEXER_ID)->invalidate();
     }
     return $objectResource;
 }
Esempio n. 5
0
 /**
  * Process flat enabled mode change
  *
  * @return void
  */
 public function processValue()
 {
     if ((bool) $this->getValue() != (bool) $this->getOldValue()) {
         if ((bool) $this->getValue()) {
             $this->indexerState->loadByIndexer(\Magento\Catalog\Model\Indexer\Category\Flat\State::INDEXER_ID);
             $this->indexerState->setStatus(\Magento\Indexer\Model\Indexer\State::STATUS_INVALID);
             $this->indexerState->save();
         } else {
             $this->indexerRegistry->get(\Magento\Catalog\Model\Indexer\Category\Flat\State::INDEXER_ID)->setScheduled(false);
         }
     }
 }
Esempio n. 6
0
 /**
  * Execute action for single entity or list of entities
  *
  * @param int[] $ids
  * @return $this
  */
 protected function executeAction($ids)
 {
     $ids = array_unique($ids);
     $indexer = $this->indexerRegistry->get(static::INDEXER_ID);
     /** @var Product\Action\Rows $action */
     $action = $this->rowsActionFactory->create();
     if ($indexer->isWorking()) {
         $action->execute($ids, true);
     }
     $action->execute($ids);
     return $this;
 }
Esempio n. 7
0
 /**
  * Execute materialization on ids entities
  *
  * @param int[] $ids
  * @return void
  */
 public function execute($ids)
 {
     $indexer = $this->indexerRegistry->get(Flat\State::INDEXER_ID);
     if ($indexer->isInvalid()) {
         return;
     }
     /** @var Flat\Action\Rows $action */
     $action = $this->rowsActionFactory->create();
     if ($indexer->isWorking()) {
         $action->reindex($ids, true);
     }
     $action->reindex($ids);
 }
Esempio n. 8
0
 /**
  * Update websites for product action
  *
  * Allowed types:
  * - add
  * - remove
  *
  * @param array $productIds
  * @param array $websiteIds
  * @param string $type
  * @return void
  */
 public function updateWebsites($productIds, $websiteIds, $type)
 {
     if ($type == 'add') {
         $this->_productWebsiteFactory->create()->addProducts($websiteIds, $productIds);
     } elseif ($type == 'remove') {
         $this->_productWebsiteFactory->create()->removeProducts($websiteIds, $productIds);
     }
     $this->setData(['product_ids' => array_unique($productIds), 'website_ids' => $websiteIds, 'action_type' => $type]);
     $categoryIndexer = $this->indexerRegistry->get(\Magento\Catalog\Model\Indexer\Product\Category::INDEXER_ID);
     if (!$categoryIndexer->isScheduled()) {
         $categoryIndexer->reindexList(array_unique($productIds));
     }
 }
Esempio n. 9
0
 /**
  * Invalidate indexes by process codes.
  *
  * @return $this
  */
 public function invalidateIndex()
 {
     $relatedIndexers = $this->_importConfig->getRelatedIndexers($this->getEntity());
     if (empty($relatedIndexers)) {
         return $this;
     }
     foreach (array_keys($relatedIndexers) as $indexerId) {
         try {
             $indexer = $this->indexerRegistry->get($indexerId);
             $indexer->invalidate();
         } catch (\InvalidArgumentException $e) {
         }
     }
     return $this;
 }
Esempio n. 10
0
 /**
  * Init indexing process after category save
  *
  * @return void
  */
 public function reindex()
 {
     if ($this->flatState->isFlatEnabled()) {
         $flatIndexer = $this->indexerRegistry->get(Indexer\Category\Flat\State::INDEXER_ID);
         if (!$flatIndexer->isScheduled()) {
             $flatIndexer->reindexRow($this->getId());
         }
     }
     $affectedProductIds = $this->getAffectedProductIds();
     $productIndexer = $this->indexerRegistry->get(Indexer\Category\Product::INDEXER_ID);
     if (!$productIndexer->isScheduled() && !empty($affectedProductIds)) {
         $productIndexer->reindexList($this->getPathIds());
     }
 }
Esempio n. 11
0
 /**
  * Init indexing process after product save
  *
  * @return void
  */
 public function reindex()
 {
     if ($this->_catalogProduct->isDataForProductCategoryIndexerWasChanged($this) || $this->isDeleted()) {
         $productCategoryIndexer = $this->indexerRegistry->get(Indexer\Product\Category::INDEXER_ID);
         if (!$productCategoryIndexer->isScheduled()) {
             $productCategoryIndexer->reindexRow($this->getId());
         }
     }
     $this->_productFlatIndexerProcessor->reindexRow($this->getEntityId());
 }
Esempio n. 12
0
 /**
  * Stock item saving.
  *
  * @return $this
  */
 protected function _saveStockItem()
 {
     $indexer = $this->indexerRegistry->get('catalog_product_category');
     /** @var $stockResource \Magento\CatalogInventory\Model\Resource\Stock\Item */
     $stockResource = $this->_stockResItemFac->create();
     $entityTable = $stockResource->getMainTable();
     while ($bunch = $this->_dataSourceModel->getNextBunch()) {
         $stockData = [];
         $productIdsToReindex = [];
         // Format bunch to stock data rows
         foreach ($bunch as $rowNum => $rowData) {
             if (!$this->isRowAllowedToImport($rowData, $rowNum)) {
                 continue;
             }
             $row = [];
             $row['product_id'] = $this->skuProcessor->getNewSku($rowData[self::COL_SKU])['entity_id'];
             $productIdsToReindex[] = $row['product_id'];
             $row['website_id'] = $this->stockConfiguration->getDefaultWebsiteId();
             $row['stock_id'] = $this->stockRegistry->getStock($row['website_id'])->getStockId();
             $stockItemDo = $this->stockRegistry->getStockItem($row['product_id'], $row['website_id']);
             $existStockData = $stockItemDo->getData();
             $row = array_merge($this->defaultStockData, array_intersect_key($existStockData, $this->defaultStockData), array_intersect_key($rowData, $this->defaultStockData), $row);
             if ($this->stockConfiguration->isQty($this->skuProcessor->getNewSku($rowData[self::COL_SKU])['type_id'])) {
                 $stockItemDo->setData($row);
                 $row['is_in_stock'] = $this->stockStateProvider->verifyStock($stockItemDo);
                 if ($this->stockStateProvider->verifyNotification($stockItemDo)) {
                     $row['low_stock_date'] = $this->_localeDate->date(null, null, false)->format('Y-m-d H:i:s');
                 }
                 $row['stock_status_changed_auto'] = (int) (!$this->stockStateProvider->verifyStock($stockItemDo));
             } else {
                 $row['qty'] = 0;
             }
             $stockData[] = $row;
         }
         // Insert rows
         if (!empty($stockData)) {
             $this->_connection->insertOnDuplicate($entityTable, $stockData);
         }
         if ($productIdsToReindex) {
             $indexer->reindexList($productIdsToReindex);
         }
     }
     return $this;
 }
Esempio n. 13
0
 /**
  * Invalidate indexer
  *
  * @return void
  */
 protected function invalidateIndexer()
 {
     $this->indexerRegistry->get(\Magento\Catalog\Model\Indexer\Product\Price\Processor::INDEXER_ID)->invalidate();
 }
 /**
  * Get indexer
  *
  * @return \Magento\Indexer\Model\IndexerInterface
  */
 public function getIndexer()
 {
     return $this->indexerRegistry->get(static::INDEXER_ID);
 }
Esempio n. 15
0
 /**
  * Process product price scope change
  *
  * @return void
  */
 public function processValue()
 {
     if ($this->isValueChanged()) {
         $this->indexerRegistry->get(\Magento\Catalog\Model\Indexer\Product\Price\Processor::INDEXER_ID)->invalidate();
     }
 }
 /**
  * Check if Flat Index is available for use
  *
  * @return bool
  */
 public function isAvailable()
 {
     return $this->isAvailable && $this->isFlatEnabled() && $this->indexerRegistry->get(static::INDEXER_ID)->isValid();
 }