Example #1
0
 /**
  *  Test reindex for configurable product with both disabled and enabled variations.
  */
 public function testReindexEntitiesForConfigurableProduct()
 {
     /** @var \Magento\Catalog\Model\Resource\Eav\Attribute $attr **/
     $attr = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Eav\\Model\\Config')->getAttribute('catalog_product', 'test_configurable');
     $attr->setIsFilterable(1)->save();
     $this->_eavIndexerProcessor->reindexAll();
     /** @var \Magento\Eav\Model\Resource\Entity\Attribute\Option\Collection $options **/
     $options = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Eav\\Model\\Resource\\Entity\\Attribute\\Option\\Collection');
     $options->setAttributeFilter($attr->getId())->load();
     $optionIds = $options->getAllIds();
     $adapter = $this->productResource->getReadConnection();
     $select = $adapter->select()->from($this->productResource->getTable('catalog_product_index_eav'))->where('entity_id = ?', 1)->where('attribute_id = ?', $attr->getId())->where('value IN (?)', $optionIds);
     $result = $adapter->fetchAll($select);
     $this->assertCount(2, $result);
     /** @var \Magento\Catalog\Model\Product $product1 **/
     $product1 = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Catalog\\Model\\Product');
     $product1 = $product1->load(10);
     $product1->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED)->save();
     /** @var \Magento\Catalog\Model\Product $product2 **/
     $product2 = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Catalog\\Model\\Product');
     $product2 = $product2->load(20);
     $product2->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED)->save();
     $result = $adapter->fetchAll($select);
     $this->assertCount(0, $result);
 }
Example #2
0
 /**
  * @magentoDbIsolation enabled
  * @magentoDataFixture Magento/Store/_files/second_store.php
  * @magentoDataFixture Magento/Catalog/_files/product_without_options.php
  * @dataProvider saveTitleDataProvider
  */
 public function testSavePrice($options, $storeId, $result)
 {
     $productId = 1;
     $store = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Store\\Model\\Store');
     $store->load('fixture_second_store');
     $price = $options[0]['values'][0]['price'];
     $priceType = $options[0]['values'][0]['price_type'];
     $product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product');
     $product->load($productId);
     $product->setStoreIds([$storeId]);
     $product->setProductOptions($options);
     $product->setCanSaveCustomOptions(true);
     $product->save();
     $typePrice = $this->productResource->getTable('catalog_product_option_type_price');
     $typeValue = $this->productResource->getTable('catalog_product_option_type_value');
     $typeOption = $this->productResource->getTable('catalog_product_option');
     $select = $this->productResource->getReadConnection()->select()->from(['p' => $typePrice], ['price', 'price_type'])->join(['ov' => $typeValue], 'p.option_type_id = ov.option_type_id')->join(['o' => $typeOption], 'ov.option_id = o.option_id')->where('o.product_id = ?', $productId)->where('p.store_id = ?', $storeId)->where('p.price = ?', $price)->where('p.price_type = ?', $priceType);
     $testResult = $this->productResource->getReadConnection()->fetchOne($select);
     $this->assertEquals($result, (bool) $testResult);
 }
Example #3
0
 /**
  * Get attribute set id for product
  *
  * @param int $productId
  * @return string
  */
 protected function _getAttributeSetId($productId)
 {
     return $this->_productResource->getReadConnection()->fetchOne($this->_productResource->getReadConnection()->select()->distinct()->from($this->_productResource->getTable('catalog_product_entity'), array('attribute_set_id'))->where('entity_id = ?', $productId));
 }
Example #4
0
 /**
  * Clear index data
  */
 protected function clearIndex()
 {
     $this->productResource->getWriteConnection()->delete($this->productResource->getTable('catalog_category_product_index'));
     $actualResult = $this->productResource->getReadConnection()->fetchOne($this->productResource->getReadConnection()->select()->from($this->productResource->getTable('catalog_category_product_index'), 'product_id'));
     $this->assertFalse($actualResult);
 }