/** * Prepare crosssell items data * * @return \Magento\Catalog\Block\Product\ProductList\Crosssell */ protected function _prepareData() { $product = $this->_coreRegistry->registry('product'); /* @var $product \Magento\Catalog\Model\Product */ $this->_itemCollection = $product->getCrossSellProductCollection()->addAttributeToSelect($this->_catalogConfig->getProductAttributes())->setPositionOrder()->addStoreFilter(); $this->_itemCollection->load(); foreach ($this->_itemCollection as $product) { $product->setDoNotUseCategoryId(true); } return $this; }
public function testSetProduct() { /** @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject $product */ $product = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false); $product->expects($this->any())->method('getId')->will($this->returnValue('5')); $productStore = new \Magento\Framework\Object(['id' => 33]); $product->expects($this->any())->method('getStore')->will($this->returnValue($productStore)); $this->collection->setProduct($product); $this->assertEquals(33, $this->collection->getStoreId()); }
/** * Apply `position` filter to cross-sell grid. * * @param \Magento\Catalog\Model\Resource\Product\Link\Product\Collection $collection * @param \Magento\Backend\Block\Widget\Grid\Column\Extended $column * @return $this */ public function filterProductPosition($collection, $column) { $collection->addLinkAttributeToFilter($column->getIndex(), $column->getFilter()->getCondition()); return $this; }
/** * @inheritdoc */ public function _initSelect() { parent::_initSelect(); $this->setProduct($this->_getProduct())->addAttributeToSelect('name')->addAttributeToSelect('price')->addAttributeToSelect('sku')->addFilterByRequiredOptions()->addAttributeToFilter('type_id', $this->_config->getComposableTypes()); return $this; }
/** * Add join to select only in stock products * * @param \Magento\Catalog\Model\Resource\Product\Link\Product\Collection $collection * @return $this */ public function setInStockFilterToCollection($collection) { $manageStock = $this->_scopeConfig->getValue(\Magento\CatalogInventory\Model\Stock\Item::XML_PATH_MANAGE_STOCK, \Magento\Store\Model\ScopeInterface::SCOPE_STORE); $cond = array('{{table}}.use_config_manage_stock = 0 AND {{table}}.manage_stock=1 AND {{table}}.is_in_stock=1', '{{table}}.use_config_manage_stock = 0 AND {{table}}.manage_stock=0'); if ($manageStock) { $cond[] = '{{table}}.use_config_manage_stock = 1 AND {{table}}.is_in_stock=1'; } else { $cond[] = '{{table}}.use_config_manage_stock = 1'; } $collection->joinField('inventory_in_stock', 'cataloginventory_stock_item', 'is_in_stock', 'product_id=entity_id', '(' . join(') OR (', $cond) . ')'); return $this; }