/**
  * @covers \Magento\Catalog\Model\Product::getUpSellProducts
  * @covers \Magento\Catalog\Model\Product::getUpSellProductIds
  * @covers \Magento\Catalog\Model\Product::getUpSellProductCollection
  * @covers \Magento\Catalog\Model\Product::getUpSellLinkCollection
  */
 public function testUpSellProductsApi()
 {
     $this->assertEquals([], $this->_model->getUpSellProducts());
     $this->assertEquals([], $this->_model->getUpSellProductIds());
     $collection = $this->_model->getUpSellProductCollection();
     $this->assertInstanceOf('Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection', $collection);
     $this->assertSame($this->_model, $collection->getProduct());
     $linkCollection = $this->_model->getUpSellLinkCollection();
     $this->assertInstanceOf('Magento\\Catalog\\Model\\ResourceModel\\Product\\Link\\Collection', $linkCollection);
     $this->assertSame($this->_model, $linkCollection->getProduct());
 }
Example #2
0
 /**
  * Build product links
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param \Magento\Catalog\Model\Product $duplicate
  * @return void
  */
 public function build(\Magento\Catalog\Model\Product $product, \Magento\Catalog\Model\Product $duplicate)
 {
     $data = array();
     $link = $product->getLinkInstance();
     $link->useUpSellLinks();
     $attributes = array();
     foreach ($link->getAttributes() as $attribute) {
         if (isset($attribute['code'])) {
             $attributes[] = $attribute['code'];
         }
     }
     /** @var \Magento\Catalog\Model\Product\Link $link  */
     foreach ($product->getUpSellLinkCollection() as $link) {
         $data[$link->getLinkedProductId()] = $link->toArray($attributes);
     }
     $duplicate->setUpSellLinkData($data);
 }
 /**
  * {@inheritdoc}
  */
 public function getUpSellLinkCollection()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getUpSellLinkCollection');
     if (!$pluginInfo) {
         return parent::getUpSellLinkCollection();
     } else {
         return $this->___callPlugins('getUpSellLinkCollection', func_get_args(), $pluginInfo);
     }
 }