/** * @magentoDataFixture Magento/Catalog/_files/product_simple.php * @magentoDataFixture Magento/Store/_files/core_second_third_fixturestore.php * @magentoAppArea adminhtml * @magentoDbIsolation enabled * @magentoAppIsolation enabled */ public function testUpdateWebsites() { /** @var \Magento\Store\Api\WebsiteRepositoryInterface $websiteRepository */ $websiteRepository = $this->objectManager->create(\Magento\Store\Api\WebsiteRepositoryInterface::class); /** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */ $productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class); /** @var \Magento\Framework\App\CacheInterface $cacheManager */ $pageCache = $this->objectManager->create(\Magento\PageCache\Model\Cache\Type::class); /** @var \Magento\Catalog\Model\Product $product */ $product = $productRepository->get('simple'); foreach ($product->getCategoryIds() as $categoryId) { $pageCache->save('test_data', 'test_data_category_id_' . $categoryId, [\Magento\Catalog\Model\Category::CACHE_TAG . '_' . $categoryId]); $this->assertEquals('test_data', $pageCache->load('test_data_category_id_' . $categoryId)); } $websites = $websiteRepository->getList(); $websiteIds = []; foreach ($websites as $websiteCode => $website) { if (in_array($websiteCode, ['secondwebsite', 'thirdwebsite'])) { $websiteIds[] = $website->getId(); } } $this->action->updateWebsites([$product->getId()], $websiteIds, 'add'); foreach ($product->getCategoryIds() as $categoryId) { $this->assertEmpty($pageCache->load('test_data_category_id_' . $categoryId)); } }
/** * @param ProductAction $object * @param ProductAction $result * @return ProductAction * * @SuppressWarnings(PHPMD.UnusedFormatParameter) * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function afterUpdateAttributes(ProductAction $object, ProductAction $result) { $data = $result->getAttributesData(); if (!empty($data['price'])) { $this->productRuleProcessor->reindexList($result->getProductIds()); } return $result; }
/** * {@inheritdoc} */ public function updateWebsites($productIds, $websiteIds, $type) { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'updateWebsites'); if (!$pluginInfo) { return parent::updateWebsites($productIds, $websiteIds, $type); } else { return $this->___callPlugins('updateWebsites', func_get_args(), $pluginInfo); } }
/** * @param $type * @param $methodName * @dataProvider updateWebsitesDataProvider */ public function testUpdateWebsites($type, $methodName) { $productIds = [1, 2, 2, 4]; $productIdsUnique = [0 => 1, 1 => 2, 3 => 4]; $websiteIds = [1]; $this->productWebsite->expects($this->any())->method($methodName)->with($websiteIds, $productIds)->will($this->returnSelf()); $this->categoryIndexer->expects($this->any())->method('isScheduled')->will($this->returnValue(false)); $this->categoryIndexer->expects($this->any())->method('reindexList')->will($this->returnValue($productIds)); $this->prepareIndexer(); $this->model->updateWebsites($productIds, $websiteIds, $type); $this->assertEquals($this->model->getDataByKey('product_ids'), $productIdsUnique); $this->assertEquals($this->model->getDataByKey('website_ids'), $websiteIds); $this->assertEquals($this->model->getDataByKey('action_type'), $type); }
/** * @magentoDbIsolation disabled * @magentoAppIsolation enabled * @magentoDataFixture Magento/Catalog/_files/product_simple.php */ public function testUpdateAttributes() { /** @var \Magento\Catalog\Model\Resource\Eav\Attribute $attr **/ $attr = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Eav\\Model\\Config')->getAttribute('catalog_product', 'weight'); $attr->setIsFilterable(1)->save(); $this->assertTrue($attr->isIndexable()); $this->_productAction->updateAttributes([1], ['weight' => 11], 1); $categoryFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Catalog\\Model\\CategoryFactory'); /** @var \Magento\Catalog\Block\Product\ListProduct $listProduct */ $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(); $productCollection->addAttributeToSelect('weight'); $this->assertCount(1, $productCollection); /** @var $product \Magento\Catalog\Model\Product */ foreach ($productCollection as $product) { $this->assertEquals('Simple Product', $product->getName()); $this->assertEquals('Short description', $product->getShortDescription()); $this->assertEquals(11, $product->getWeight()); } }
/** * {@inheritdoc} */ public function offsetGet($offset) { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'offsetGet'); if (!$pluginInfo) { return parent::offsetGet($offset); } else { return $this->___callPlugins('offsetGet', func_get_args(), $pluginInfo); } }