Example #1
0
 /**
  * @expectedException \Magento\Framework\Exception\NoSuchEntityException
  * @expectedExceptionMessage Unknown link type: wrong_type
  */
 public function testGetLinkedItemsByTypeWithWrongType()
 {
     $productSku = 'product';
     $linkType = 'wrong_type';
     $this->productRepositoryMock->expects($this->once())->method('get')->with($productSku)->willReturn($this->productMock);
     $this->collectionProviderMock->expects($this->once())->method('getCollection')->with($this->productMock, $linkType)->willThrowException(new NoSuchEntityException('Collection provider is not registered'));
     $this->model->getLinkedItemsByType($productSku, $linkType);
 }
Example #2
0
 /**
  * @expectedException \Magento\Framework\Exception\NoSuchEntityException
  * @expectedExceptionMessage Unknown link type: bad type
  */
 public function testGetLinkedItemsByTypeWithWrongType()
 {
     $productSku = 'Simple Product 1';
     $linkType = 'bad type';
     $this->productRepositoryMock->expects($this->never())->method('get')->with($productSku)->willReturn($this->productMock);
     $inputRelatedLink = $this->objectManager->getObject('Magento\\Catalog\\Model\\ProductLink\\Link');
     $inputRelatedLink->setProductSku($productSku);
     $inputRelatedLink->setLinkType($linkType);
     $inputRelatedLink->setData("sku", "Simple Product 2");
     $inputRelatedLink->setData("type_id", "simple");
     $inputRelatedLink->setPosition(0);
     $links = [$inputRelatedLink];
     $linkTypes = ['related' => 1, 'upsell' => 4, 'crosssell' => 5, 'associated' => 3];
     $this->linkTypeProviderMock->expects($this->once())->method('getLinkTypes')->willReturn($linkTypes);
     $this->productMock->expects($this->never())->method('getProductLinks')->willReturn($links);
     $this->model->getLinkedItemsByType($productSku, $linkType);
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function deleteById($sku, $type, $linkedProductSku)
 {
     $linkItems = $this->linkManagement->getLinkedItemsByType($sku, $type);
     /** @var \Magento\Catalog\Api\Data\ProductLinkInterface $linkItem */
     foreach ($linkItems as $linkItem) {
         if ($linkItem->getLinkedProductSku() == $linkedProductSku) {
             return $this->delete($linkItem);
         }
     }
     throw new NoSuchEntityException(__('Product %1 doesn\'t have linked %2 as %3', [$sku, $linkedProductSku, $type]));
 }