/** * @magentoDataFixture Magento/Catalog/_files/products_crosssell.php */ public function testAddLinkAttributeToFilterNoResults() { $om = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $link = $om->get('\\Magento\\Catalog\\Model\\Product\\Link')->useCrossSellLinks(); $this->collection->setLinkModel($link); $this->collection->addLinkAttributeToFilter('position', array('from' => 2, 'to' => 3)); $product = $om->get('Magento\\Catalog\\Model\\Product')->load(2); $this->collection->setProduct($product); $this->collection->load(); $this->assertCount(0, $this->collection->getItems()); }
/** * @dataProvider setOrderDataProvider */ public function testSetOrder($order, $expectedOrder) { $this->_collection->setOrder($order); $this->_collection->load(); // perform real SQL query $selectOrder = $this->_collection->getSelect()->getPart(\Zend_Db_Select::ORDER); foreach ($expectedOrder as $field) { $orderBy = array_shift($selectOrder); $this->assertArrayHasKey(0, $orderBy); $this->assertTrue(false !== strpos($orderBy[0], $field), 'Ordering by same column more than once is restricted by multiple RDBMS requirements.'); } }
/** * @return $this */ protected function _prepareData() { $product = $this->_coreRegistry->registry('product'); /* @var $product \Magento\Catalog\Model\Product */ $this->_itemCollection = $product->getRelatedProductCollection()->addAttributeToSelect('required_options')->setPositionOrder()->addStoreFilter(); if ($this->moduleManager->isEnabled('Magento_Checkout')) { $this->_addProductAttributesAndPrices($this->_itemCollection); } $this->_itemCollection->setVisibility($this->_catalogProductVisibility->getVisibleInCatalogIds()); $this->_itemCollection->load(); foreach ($this->_itemCollection as $product) { $product->setDoNotUseCategoryId(true); } return $this; }
/** * @return $this */ protected function _prepareData() { $product = $this->_coreRegistry->registry('product'); /* @var $product \Magento\Catalog\Model\Product */ $this->_itemCollection = $product->getUpSellProductCollection()->setPositionOrder()->addStoreFilter(); if ($this->moduleManager->isEnabled('Magento_Checkout')) { $this->_addProductAttributesAndPrices($this->_itemCollection); } $this->_itemCollection->setVisibility($this->_catalogProductVisibility->getVisibleInCatalogIds()); $this->_itemCollection->load(); /** * Updating collection with desired items */ $this->_eventManager->dispatch('catalog_product_upsell', ['product' => $product, 'collection' => $this->_itemCollection, 'limit' => null]); foreach ($this->_itemCollection as $product) { $product->setDoNotUseCategoryId(true); } return $this; }