Esempio n. 1
0
 /**
  * @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));
     }
 }
Esempio n. 2
0
 /**
  * {@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);
     }
 }
Esempio n. 3
0
 /**
  * @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);
 }