/** * Get crosssell items * * @return array */ public function getItems() { $items = $this->getData('items'); if (is_null($items)) { $items = array(); $ninProductIds = $this->_getCartProductIds(); if ($ninProductIds) { $lastAdded = (int) $this->_getLastAddedProductId(); if ($lastAdded) { $collection = $this->_getCollection()->addProductFilter($lastAdded); if (!empty($ninProductIds)) { $collection->addExcludeProductFilter($ninProductIds); } $collection->setPositionOrder()->load(); foreach ($collection as $item) { $ninProductIds[] = $item->getId(); $items[] = $item; } } if (count($items) < $this->_maxItemCount) { $filterProductIds = array_merge($this->_getCartProductIds(), $this->_itemRelationsList->getRelatedProductIds($this->getQuote()->getAllItems())); $collection = $this->_getCollection()->addProductFilter($filterProductIds)->addExcludeProductFilter($ninProductIds)->setPageSize($this->_maxItemCount - count($items))->setGroupBy()->setPositionOrder()->load(); foreach ($collection as $item) { $items[] = $item; } } } $this->setData('items', $items); } return $items; }
/** * @covers \Magento\Sales\Model\Quote\Item\RelatedProducts::getRelatedProductIds */ public function testGetRelatedProductIdsNoOptions() { $quoteItemMock = $this->getMock('\\Magento\\Sales\\Model\\Quote\\Item', array(), array(), '', false); $quoteItemMock->expects($this->once())->method('getOptionByCode')->with('product_type')->will($this->returnValue(new \stdClass())); $this->assertEquals(array(), $this->model->getRelatedProductIds(array($quoteItemMock))); }