/** * 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)); } }
/** * 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); } else { if ($type == 'remove') { $this->_productWebsiteFactory->create()->removeProducts($websiteIds, $productIds); } } $this->setData(array('product_ids' => array_unique($productIds), 'website_ids' => $websiteIds, 'action_type' => $type)); // register mass action indexer event $this->_indexIndexer->processEntityAction($this, \Magento\Catalog\Model\Product::ENTITY, \Magento\Index\Model\Event::TYPE_MASS_ACTION); if (!$this->getCategoryIndexer()->isScheduled()) { $this->getCategoryIndexer()->reindexList(array_unique($productIds)); } }