コード例 #1
0
 /**
  * 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);
     }
 }
コード例 #2
0
 public function testAfterImportSource()
 {
     $this->_indexerMock->expects($this->once())->method('invalidate');
     $this->indexerRegistryMock->expects($this->once())->method('get')->with(\Magento\Catalog\Model\Indexer\Product\Price\Processor::INDEXER_ID)->will($this->returnValue($this->_indexerMock));
     $importMock = $this->getMock('Magento\\ImportExport\\Model\\Import', [], [], '', false);
     $this->assertEquals('return_value', $this->_model->afterImportSource($importMock, 'return_value'));
 }
コード例 #3
0
ファイル: Fulltext.php プロジェクト: shabbirvividads/magento2
 /**
  * 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);
 }
コード例 #4
0
ファイル: Engine.php プロジェクト: shabbirvividads/magento2
 /**
  * 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;
 }
コード例 #5
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;
 }
コード例 #6
0
 public function testExecuteWithIndexer()
 {
     $ids = [1, 2, 3];
     $this->indexerRegistryMock->expects($this->once())->method('get')->with(\Magento\CatalogSearch\Model\Indexer\Fulltext::INDEXER_ID)->will($this->returnValue($this->indexerMock));
     $rowMock = $this->getMock('Magento\\CatalogSearch\\Model\\Indexer\\Fulltext\\Action\\Rows', ['reindex'], [], '', false);
     $rowMock->expects($this->once())->method('reindex')->with($ids)->will($this->returnSelf());
     $this->rowsMock->expects($this->once())->method('create')->will($this->returnValue($rowMock));
     $this->model->execute($ids);
 }
コード例 #7
0
 public function testAroundSave()
 {
     $this->stateMock->expects($this->once())->method('isFlatEnabled')->will($this->returnValue(true));
     $this->indexerMock->expects($this->once())->method('invalidate');
     $this->indexerRegistryMock->expects($this->once())->method('get')->with(\Magento\Catalog\Model\Indexer\Category\Flat\State::INDEXER_ID)->will($this->returnValue($this->indexerMock));
     $this->groupMock->expects($this->once())->method('dataHasChangedFor')->with('root_category_id')->will($this->returnValue(true));
     $this->groupMock->expects($this->once())->method('isObjectNew')->will($this->returnValue(false));
     $this->assertFalse($this->model->aroundSave($this->subjectMock, $this->closureMock, $this->groupMock));
 }
コード例 #8
0
 /**
  * @param $isAvailable
  * @param $isFlatEnabled
  * @param $isValid
  * @param $result
  * @dataProvider isAvailableDataProvider
  */
 public function testIsAvailable($isAvailable, $isFlatEnabled, $isValid, $result)
 {
     $this->flatIndexerMock->expects($this->any())->method('load')->with('catalog_category_flat');
     $this->flatIndexerMock->expects($this->any())->method('isValid')->will($this->returnValue($isValid));
     $this->indexerRegistryMock->expects($this->any())->method('get')->with(\Magento\Catalog\Model\Indexer\Category\Flat\State::INDEXER_ID)->will($this->returnValue($this->flatIndexerMock));
     $this->scopeConfigMock->expects($this->any())->method('isSetFlag')->with('catalog/frontend/flat_catalog_category')->will($this->returnValue($isFlatEnabled));
     $this->model = new \Magento\Catalog\Model\Indexer\Category\Flat\State($this->scopeConfigMock, $this->indexerRegistryMock, $isAvailable);
     $this->assertEquals($result, $this->model->isAvailable());
 }
コード例 #9
0
 public function setUp()
 {
     $this->_objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->_subjectMock = $this->getMock('\\Magento\\Customer\\Api\\GroupRepositoryInterface', [], [], '', false);
     $indexerMock = $this->getMock('Magento\\Indexer\\Model\\Indexer', ['getId', 'invalidate'], [], '', false);
     $indexerMock->expects($this->once())->method('invalidate');
     $this->indexerRegistryMock = $this->getMock('Magento\\Indexer\\Model\\IndexerRegistry', ['get'], [], '', false);
     $this->indexerRegistryMock->expects($this->once())->method('get')->with(\Magento\Catalog\Model\Indexer\Product\Price\Processor::INDEXER_ID)->will($this->returnValue($indexerMock));
     $this->_model = $this->_objectManager->getObject('Magento\\Catalog\\Model\\Indexer\\Product\\Price\\Plugin\\CustomerGroup', ['indexerRegistry' => $this->indexerRegistryMock]);
 }
コード例 #10
0
ファイル: Product.php プロジェクト: shabbirvividads/magento2
 /**
  * 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;
 }
コード例 #11
0
ファイル: Mode.php プロジェクト: nja78/magento2
 /**
  * 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);
         }
     }
 }
コード例 #12
0
ファイル: Flat.php プロジェクト: shabbirvividads/magento2
 /**
  * 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);
 }
コード例 #13
0
 /**
  * @param array $indexerIds
  * @param \Exception $exception
  * @param array $expectsExceptionValues
  * @dataProvider executeDataProvider
  */
 public function testExecute($indexerIds, $exception, $expectsExceptionValues)
 {
     $this->model = new \Magento\Indexer\Controller\Adminhtml\Indexer\MassChangelog($this->contextMock);
     $this->request->expects($this->any())->method('getParam')->with('indexer_ids')->will($this->returnValue($indexerIds));
     if (!is_array($indexerIds)) {
         $this->messageManager->expects($this->once())->method('addError')->with(__('Please select indexers.'))->will($this->returnValue(1));
     } else {
         $this->objectManager->expects($this->any())->method('get')->with('Magento\\Indexer\\Model\\IndexerRegistry')->will($this->returnValue($this->indexReg));
         $indexerInterface = $this->getMockForAbstractClass('Magento\\Indexer\\Model\\IndexerInterface', ['setScheduled'], '', false);
         $this->indexReg->expects($this->any())->method('get')->with(1)->will($this->returnValue($indexerInterface));
         if ($exception !== null) {
             $indexerInterface->expects($this->any())->method('setScheduled')->with(true)->will($this->throwException($exception));
         } else {
             $indexerInterface->expects($this->any())->method('setScheduled')->with(true)->will($this->returnValue(1));
         }
         $this->messageManager->expects($this->any())->method('addSuccess')->will($this->returnValue(1));
         if ($exception !== null) {
             $this->messageManager->expects($this->exactly($expectsExceptionValues[2]))->method('addError')->with($exception->getMessage());
             $this->messageManager->expects($this->exactly($expectsExceptionValues[1]))->method('addException')->with($exception, "We couldn't change indexer(s)' mode because of an error.");
         }
     }
     $this->helper->expects($this->any())->method("getUrl")->willReturn("magento.com");
     $this->response->expects($this->any())->method("setRedirect")->willReturn(1);
     $this->model->execute();
 }
コード例 #14
0
ファイル: ModeTest.php プロジェクト: shabbirvividads/magento2
 /**
  * @param string $oldValue
  * @param string $value
  * @dataProvider dataProviderProcessValueOff
  */
 public function testProcessValueOff($oldValue, $value)
 {
     $this->configMock->expects($this->once())->method('getValue')->with(null, 'default')->will($this->returnValue($oldValue));
     $this->model->setValue($value);
     $this->indexerStateMock->expects($this->never())->method('loadByIndexer');
     $this->indexerStateMock->expects($this->never())->method('setStatus');
     $this->indexerStateMock->expects($this->never())->method('save');
     $this->indexerRegistry->expects($this->once())->method('get')->with('catalog_category_flat')->willReturn($this->flatIndexer);
     $this->flatIndexer->expects($this->once())->method('setScheduled')->with(false);
     $this->model->processValue();
 }
コード例 #15
0
ファイル: Action.php プロジェクト: shabbirvividads/magento2
 /**
  * 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));
     }
 }
コード例 #16
0
 /**
  * @param $productScheduled
  * @param $expectedProductReindexCall
  *
  * @dataProvider reindexFlatDisabledTestDataProvider
  */
 public function testReindexFlatDisabled($productScheduled, $expectedProductReindexCall)
 {
     $affectedProductIds = ["1", "2"];
     $this->category->setAffectedProductIds($affectedProductIds);
     $pathIds = ['path/1/2', 'path/2/3'];
     $this->category->setData('path_ids', $pathIds);
     $this->category->setId('123');
     $this->flatState->expects($this->any())->method('isFlatEnabled')->will($this->returnValue(false));
     $this->productIndexer->expects($this->exactly(1))->method('isScheduled')->will($this->returnValue($productScheduled));
     $this->productIndexer->expects($this->exactly($expectedProductReindexCall))->method('reindexList')->with($pathIds);
     $this->indexerRegistry->expects($this->at(0))->method('get')->with(Indexer\Category\Product::INDEXER_ID)->will($this->returnValue($this->productIndexer));
     $this->category->reindex();
 }
コード例 #17
0
 public function testMovePrimaryWorkflow()
 {
     $indexer = $this->getMock('stdClass', ['isScheduled']);
     $indexer->expects($this->once())->method('isScheduled')->will($this->returnValue(true));
     $this->indexerRegistry->expects($this->once())->method('get')->with('catalog_category_product')->will($this->returnValue($indexer));
     $parentCategory = $this->getMock('Magento\\Catalog\\Model\\Category', ['getId', 'setStoreId', 'load'], [], '', false);
     $parentCategory->expects($this->any())->method('getId')->will($this->returnValue(5));
     $parentCategory->expects($this->any())->method('setStoreId')->will($this->returnSelf());
     $parentCategory->expects($this->any())->method('load')->will($this->returnSelf());
     $this->categoryRepository->expects($this->any())->method('get')->will($this->returnValue($parentCategory));
     $store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
     $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($store));
     $this->category->setId(3);
     $this->category->move(5, 7);
 }
コード例 #18
0
ファイル: Import.php プロジェクト: opexsw/magento2
 /**
  * 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;
 }
コード例 #19
0
 /**
  * @param bool $scheduled
  * @dataProvider runDataProvider
  */
 public function testReindexList($scheduled)
 {
     $ids = [1];
     if ($scheduled) {
         $this->_indexerRegistryMock->expects($this->once())->method('get')->with(\Magento\Catalog\Model\Indexer\Category\Product::INDEXER_ID)->willReturnSelf();
         $this->_indexerRegistryMock->expects($this->once())->method('isScheduled')->willReturn($scheduled);
         $this->assertEquals(null, $this->model->reindexList($ids));
     } else {
         $this->_indexerRegistryMock->expects($this->exactly(2))->method('get')->with(\Magento\Catalog\Model\Indexer\Category\Product::INDEXER_ID)->willReturnSelf();
         $this->_indexerRegistryMock->expects($this->once())->method('isScheduled')->willReturn($scheduled);
         $this->_indexerRegistryMock->expects($this->once())->method('reindexList')->with($ids)->willReturnSelf();
         $this->assertEquals(null, $this->model->reindexList($ids));
     }
 }
コード例 #20
0
 protected function prepareIndexer()
 {
     $this->indexerRegistryMock->expects($this->once())->method('get')->with(\Magento\Catalog\Model\Indexer\Product\Category::INDEXER_ID)->will($this->returnValue($this->indexerMock));
 }
コード例 #21
0
ファイル: Product.php プロジェクト: opexsw/magento2
 /**
  * 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());
 }
コード例 #22
0
ファイル: ViewTest.php プロジェクト: shabbirvividads/magento2
 /**
  * @param int $invalidateCounter
  */
 protected function prepareIndexer($invalidateCounter)
 {
     $this->indexerRegistryMock->expects($this->exactly($invalidateCounter))->method('get')->with(\Magento\CatalogSearch\Model\Indexer\Fulltext::INDEXER_ID)->will($this->returnValue($this->indexerMock));
 }
コード例 #23
0
 /**
  * Test isIndexerScheduled()
  */
 public function testIsIndexerScheduled()
 {
     $this->_indexerRegistryMock->expects($this->once())->method('get')->with(\Magento\Catalog\Model\Indexer\Category\Product::INDEXER_ID)->willReturnSelf();
     $this->_indexerRegistryMock->expects($this->once())->method('isScheduled')->willReturn(false);
     $this->model->isIndexerScheduled();
 }
コード例 #24
0
 /**
  * @param int $countCall
  */
 protected function prepareIndexer($countCall)
 {
     $this->indexerRegistryMock->expects($this->exactly($countCall))->method('get')->with(\Magento\Catalog\Model\Indexer\Product\Price\Processor::INDEXER_ID)->will($this->returnValue($this->_indexerMock));
 }
コード例 #25
0
 /**
  * Get indexer
  *
  * @return \Magento\Indexer\Model\IndexerInterface
  */
 public function getIndexer()
 {
     return $this->indexerRegistry->get(static::INDEXER_ID);
 }
コード例 #26
0
 protected function mockIndexerMethods()
 {
     $this->indexerMock->expects($this->once())->method('invalidate');
     $this->indexerRegistryMock->expects($this->once())->method('get')->with(\Magento\Catalog\Model\Indexer\Category\Product::INDEXER_ID)->will($this->returnValue($this->indexerMock));
 }
コード例 #27
0
 /**
  * Invalidate indexer
  *
  * @return void
  */
 protected function invalidateIndexer()
 {
     $this->indexerRegistry->get(\Magento\Catalog\Model\Indexer\Product\Price\Processor::INDEXER_ID)->invalidate();
 }
コード例 #28
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();
     }
 }
コード例 #29
0
ファイル: Category.php プロジェクト: kid17/magento2
 /**
  * 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());
     }
 }
コード例 #30
0
ファイル: Product.php プロジェクト: nja78/magento2
 /**
  * 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;
 }