Beispiel #1
0
 /**
  * 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;
 }
Beispiel #2
0
 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\DataObject(['id' => 33]);
     $product->expects($this->any())->method('getStore')->will($this->returnValue($productStore));
     $this->collection->setProduct($product);
     $this->assertEquals(33, $this->collection->getStoreId());
 }
 /**
  * @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;
 }
Beispiel #4
0
 /**
  * Adds filtering for collection to return only in stock products
  *
  * @param \Magento\Catalog\Model\ResourceModel\Product\Link\Product\Collection $collection
  * @return void
  */
 public function addInStockFilterToCollection($collection)
 {
     $manageStock = $this->scopeConfig->getValue(\Magento\CatalogInventory\Model\Configuration::XML_PATH_MANAGE_STOCK, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     $cond = ['{{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) . ')');
 }
Beispiel #5
0
 /**
  * Apply `position` filter to cross-sell grid.
  *
  * @param \Magento\Catalog\Model\ResourceModel\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;
 }