/** * Retrieve Stock Indexer Models per Product Type * * @return \Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\StockInterface[] */ protected function _getTypeIndexers() { if (empty($this->_indexers)) { foreach ($this->_catalogProductType->getTypesByPriority() as $typeId => $typeInfo) { $indexerClassName = isset($typeInfo['stock_indexer']) ? $typeInfo['stock_indexer'] : ''; $indexer = $this->_indexerFactory->create($indexerClassName)->setTypeId($typeId)->setIsComposite(!empty($typeInfo['composite'])); $this->_indexers[$typeId] = $indexer; } } return $this->_indexers; }
public function testGetTypesByPriority() { $expected = []; foreach ($this->_productTypes as $typeId => $type) { $type['label'] = __($type['label']); $options[$typeId] = $type; } $expected['simple'] = $options['simple']; $expected['type_id_2'] = $options['type_id_2']; $expected['type_id_1'] = $options['type_id_1']; $expected['type_id_3'] = $options['type_id_3']; $this->assertEquals($expected, $this->_model->getTypesByPriority()); }
/** * Retrieve price indexers per product type * * @return \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\PriceInterface[] */ public function getTypeIndexers() { if ($this->_indexers === null) { $this->_indexers = []; $types = $this->_catalogProductType->getTypesByPriority(); foreach ($types as $typeId => $typeInfo) { $modelName = isset($typeInfo['price_indexer']) ? $typeInfo['price_indexer'] : get_class($this->_defaultIndexerResource); $isComposite = !empty($typeInfo['composite']); $indexer = $this->_indexerPriceFactory->create($modelName)->setTypeId($typeId)->setIsComposite($isComposite); $this->_indexers[$typeId] = $indexer; } } return $this->_indexers; }
public function testGetTypesByPriority() { $types = $this->_productType->getTypesByPriority(); // collect the types and priority in the same order as the method returns $result = []; foreach ($types as $typeId => $type) { if (!isset($type['index_priority'])) { // possible bug: index_priority is not defined for each type $priority = 0; } else { $priority = (int) $type['index_priority']; } // non-composite must be before composite if (1 != $type['composite']) { $priority = -1 * $priority; } $result[$typeId] = $priority; } $expectedResult = $result; asort($expectedResult); $this->assertEquals($expectedResult, $result); }
/** * {@inheritdoc} */ public function getTypesByPriority() { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getTypesByPriority'); if (!$pluginInfo) { return parent::getTypesByPriority(); } else { return $this->___callPlugins('getTypesByPriority', func_get_args(), $pluginInfo); } }