本文整理汇总了PHP中Magento\Catalog\Model\Indexer\Product\Flat\Processor::reindexList方法的典型用法代码示例。如果您正苦于以下问题:PHP Processor::reindexList方法的具体用法?PHP Processor::reindexList怎么用?PHP Processor::reindexList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Catalog\Model\Indexer\Product\Flat\Processor
的用法示例。
在下文中一共展示了Processor::reindexList方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testProductsUpdate
/**
* @magentoDbIsolation enabled
* @magentoAppIsolation enabled
* @magentoConfigFixture current_store catalog/frontend/flat_catalog_product 1
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
*/
public function testProductsUpdate()
{
$this->_product->load(1);
$this->_processor->reindexList([$this->_product->getId()]);
$categoryFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Catalog\\Model\\CategoryFactory');
$listProduct = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Catalog\\Block\\Product\\ListProduct');
$category = $categoryFactory->create()->load(2);
$layer = $listProduct->getLayer();
$layer->setCurrentCategory($category);
$productCollection = $layer->getProductCollection();
$this->assertCount(1, $productCollection);
/** @var $product \Magento\Catalog\Model\Product */
foreach ($productCollection as $product) {
$this->assertEquals($this->_product->getName(), $product->getName());
$this->assertEquals($this->_product->getShortDescription(), $product->getShortDescription());
}
}
示例2: testReindexListForce
public function testReindexListForce()
{
$ids = [1];
$this->_stateMock->expects($this->once())->method('isFlatEnabled')->willReturn(true);
$indexerMock = $this->getMockBuilder('Magento\\Indexer\\Model\\Indexer')->disableOriginalConstructor()->getMock();
$this->indexerRegistryMock->expects($this->any())->method('get')->with(Processor::INDEXER_ID)->willReturn($indexerMock);
$indexerMock->expects($this->any())->method('isScheduled')->willReturn(true);
$indexerMock->expects($this->any())->method('reindexList')->with($ids)->willReturnSelf();
$this->_model->reindexList($ids, true);
}
示例3: execute
/**
* Update product attributes
*
* @return \Magento\Backend\Model\View\Result\Redirect
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function execute()
{
if (!$this->_validateProducts()) {
return $this->resultRedirectFactory->create()->setPath('catalog/product/', ['_current' => true]);
}
/* Collect Data */
$inventoryData = $this->getRequest()->getParam('inventory', []);
$attributesData = $this->getRequest()->getParam('attributes', []);
$websiteRemoveData = $this->getRequest()->getParam('remove_website_ids', []);
$websiteAddData = $this->getRequest()->getParam('add_website_ids', []);
/* Prepare inventory data item options (use config settings) */
$options = $this->_objectManager->get('Magento\\CatalogInventory\\Api\\StockConfigurationInterface')->getConfigItemOptions();
foreach ($options as $option) {
if (isset($inventoryData[$option]) && !isset($inventoryData['use_config_' . $option])) {
$inventoryData['use_config_' . $option] = 0;
}
}
try {
$storeId = $this->attributeHelper->getSelectedStoreId();
if ($attributesData) {
$dateFormat = $this->_objectManager->get('Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface')->getDateFormat(\IntlDateFormatter::SHORT);
foreach ($attributesData as $attributeCode => $value) {
$attribute = $this->_objectManager->get('Magento\\Eav\\Model\\Config')->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $attributeCode);
if (!$attribute->getAttributeId()) {
unset($attributesData[$attributeCode]);
continue;
}
if ($attribute->getBackendType() == 'datetime') {
if (!empty($value)) {
$filterInput = new \Zend_Filter_LocalizedToNormalized(['date_format' => $dateFormat]);
$filterInternal = new \Zend_Filter_NormalizedToLocalized(['date_format' => \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT]);
$value = $filterInternal->filter($filterInput->filter($value));
} else {
$value = null;
}
$attributesData[$attributeCode] = $value;
} elseif ($attribute->getFrontendInput() == 'multiselect') {
// Check if 'Change' checkbox has been checked by admin for this attribute
$isChanged = (bool) $this->getRequest()->getPost($attributeCode . '_checkbox');
if (!$isChanged) {
unset($attributesData[$attributeCode]);
continue;
}
if (is_array($value)) {
$value = implode(',', $value);
}
$attributesData[$attributeCode] = $value;
}
}
$this->_objectManager->get('Magento\\Catalog\\Model\\Product\\Action')->updateAttributes($this->attributeHelper->getProductIds(), $attributesData, $storeId);
}
if ($inventoryData) {
// TODO why use ObjectManager?
/** @var \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry */
$stockRegistry = $this->_objectManager->create('Magento\\CatalogInventory\\Api\\StockRegistryInterface');
/** @var \Magento\CatalogInventory\Api\StockItemRepositoryInterface $stockItemRepository */
$stockItemRepository = $this->_objectManager->create('Magento\\CatalogInventory\\Api\\StockItemRepositoryInterface');
foreach ($this->attributeHelper->getProductIds() as $productId) {
$stockItemDo = $stockRegistry->getStockItem($productId, $this->attributeHelper->getStoreWebsiteId($storeId));
if (!$stockItemDo->getProductId()) {
$inventoryData[] = $productId;
}
$stockItemId = $stockItemDo->getId();
$this->dataObjectHelper->populateWithArray($stockItemDo, $inventoryData, '\\Magento\\CatalogInventory\\Api\\Data\\StockItemInterface');
$stockItemDo->setItemId($stockItemId);
$stockItemRepository->save($stockItemDo);
}
$this->_stockIndexerProcessor->reindexList($this->attributeHelper->getProductIds());
}
if ($websiteAddData || $websiteRemoveData) {
/* @var $actionModel \Magento\Catalog\Model\Product\Action */
$actionModel = $this->_objectManager->get('Magento\\Catalog\\Model\\Product\\Action');
$productIds = $this->attributeHelper->getProductIds();
if ($websiteRemoveData) {
$actionModel->updateWebsites($productIds, $websiteRemoveData, 'remove');
}
if ($websiteAddData) {
$actionModel->updateWebsites($productIds, $websiteAddData, 'add');
}
$this->_eventManager->dispatch('catalog_product_to_website_change', ['products' => $productIds]);
}
$this->messageManager->addSuccess(__('A total of %1 record(s) were updated.', count($this->attributeHelper->getProductIds())));
$this->_productFlatIndexerProcessor->reindexList($this->attributeHelper->getProductIds());
if ($this->_catalogProduct->isDataForPriceIndexerWasChanged($attributesData) || !empty($websiteRemoveData) || !empty($websiteAddData)) {
$this->_productPriceIndexerProcessor->reindexList($this->attributeHelper->getProductIds());
}
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addException($e, __('Something went wrong while updating the product(s) attributes.'));
}
return $this->resultRedirectFactory->create()->setPath('catalog/product/', ['store' => $this->attributeHelper->getSelectedStoreId()]);
//.........这里部分代码省略.........
示例4: execute
/**
* Update product attributes
*
* @return void
*/
public function execute()
{
if (!$this->_validateProducts()) {
return;
}
/* Collect Data */
$inventoryData = $this->getRequest()->getParam('inventory', array());
$attributesData = $this->getRequest()->getParam('attributes', array());
$websiteRemoveData = $this->getRequest()->getParam('remove_website_ids', array());
$websiteAddData = $this->getRequest()->getParam('add_website_ids', array());
/* Prepare inventory data item options (use config settings) */
$options = $this->_objectManager->get('Magento\\CatalogInventory\\Helper\\Data')->getConfigItemOptions();
foreach ($options as $option) {
if (isset($inventoryData[$option]) && !isset($inventoryData['use_config_' . $option])) {
$inventoryData['use_config_' . $option] = 0;
}
}
try {
if ($attributesData) {
$dateFormat = $this->_objectManager->get('Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface')->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT);
$storeId = $this->attributeHelper->getSelectedStoreId();
foreach ($attributesData as $attributeCode => $value) {
$attribute = $this->_objectManager->get('Magento\\Eav\\Model\\Config')->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $attributeCode);
if (!$attribute->getAttributeId()) {
unset($attributesData[$attributeCode]);
continue;
}
if ($attribute->getBackendType() == 'datetime') {
if (!empty($value)) {
$filterInput = new \Zend_Filter_LocalizedToNormalized(array('date_format' => $dateFormat));
$filterInternal = new \Zend_Filter_NormalizedToLocalized(array('date_format' => \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT));
$value = $filterInternal->filter($filterInput->filter($value));
} else {
$value = null;
}
$attributesData[$attributeCode] = $value;
} elseif ($attribute->getFrontendInput() == 'multiselect') {
// Check if 'Change' checkbox has been checked by admin for this attribute
$isChanged = (bool) $this->getRequest()->getPost($attributeCode . '_checkbox');
if (!$isChanged) {
unset($attributesData[$attributeCode]);
continue;
}
if (is_array($value)) {
$value = implode(',', $value);
}
$attributesData[$attributeCode] = $value;
}
}
$this->_objectManager->get('Magento\\Catalog\\Model\\Product\\Action')->updateAttributes($this->attributeHelper->getProductIds(), $attributesData, $storeId);
}
if ($inventoryData) {
/** @var \Magento\CatalogInventory\Service\V1\StockItemService $stockItemService */
$stockItemService = $this->_objectManager->create('Magento\\CatalogInventory\\Service\\V1\\StockItemService');
foreach ($this->_helper->getProductIds() as $productId) {
$stockItemDo = $stockItemService->getStockItem($productId);
if (!$stockItemDo->getProductId()) {
$inventoryData[] = $productId;
}
$stockItemService->saveStockItem($this->stockItemBuilder->mergeDataObjectWithArray($stockItemDo, $inventoryData));
}
$this->_stockIndexerProcessor->reindexList($this->_helper->getProductIds());
}
if ($websiteAddData || $websiteRemoveData) {
/* @var $actionModel \Magento\Catalog\Model\Product\Action */
$actionModel = $this->_objectManager->get('Magento\\Catalog\\Model\\Product\\Action');
$productIds = $this->attributeHelper->getProductIds();
if ($websiteRemoveData) {
$actionModel->updateWebsites($productIds, $websiteRemoveData, 'remove');
}
if ($websiteAddData) {
$actionModel->updateWebsites($productIds, $websiteAddData, 'add');
}
$this->_eventManager->dispatch('catalog_product_to_website_change', array('products' => $productIds));
$this->messageManager->addNotice(__('Please refresh "Catalog URL Rewrites" and "Product Attributes" in System -> ' . '<a href="%1">Index Management</a>.', $this->getUrl('adminhtml/process/list')));
}
$this->messageManager->addSuccess(__('A total of %1 record(s) were updated.', count($this->attributeHelper->getProductIds())));
$this->_productFlatIndexerProcessor->reindexList($this->attributeHelper->getProductIds());
if ($this->_catalogProduct->isDataForPriceIndexerWasChanged($attributesData) || !empty($websiteRemoveData) || !empty($websiteAddData)) {
$this->_productPriceIndexerProcessor->reindexList($this->attributeHelper->getProductIds());
}
} catch (\Magento\Framework\Model\Exception $e) {
$this->messageManager->addError($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addException($e, __('Something went wrong while updating the product(s) attributes.'));
}
$this->_redirect('catalog/product/', array('store' => $this->attributeHelper->getSelectedStoreId()));
}