public function testUpdateAttributes() { $productIds = [1, 2, 2, 4]; $productIdsUnique = [0 => 1, 1 => 2, 3 => 4]; $attrData = [1]; $storeId = 1; $this->resource->expects($this->any())->method('updateAttributes')->with($productIds, $attrData, $storeId)->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->eavConfig->expects($this->any())->method('getAttribute')->will($this->returnValue($this->eavAttribute)); $this->eavAttribute->expects($this->any())->method('isIndexable')->will($this->returnValue(false)); $this->assertEquals($this->model, $this->model->updateAttributes($productIds, $attrData, $storeId)); $this->assertEquals($this->model->getDataByKey('product_ids'), $productIdsUnique); $this->assertEquals($this->model->getDataByKey('attributes_data'), $attrData); $this->assertEquals($this->model->getDataByKey('store_id'), $storeId); }
/** * {@inheritdoc} */ public function updateAttributes($productIds, $attrData, $storeId) { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'updateAttributes'); if (!$pluginInfo) { return parent::updateAttributes($productIds, $attrData, $storeId); } else { return $this->___callPlugins('updateAttributes', func_get_args(), $pluginInfo); } }
/** * @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()); } }