Example #1
0
 /**
  * {@inheritdoc}
  */
 public function getLinkedProducts($productSku, $type)
 {
     $output = [];
     $product = $this->productLoader->load($productSku);
     $collection = $this->entityCollectionProvider->getCollection($product, $type);
     foreach ($collection as $item) {
         $output[] = $this->productEntityBuilder->populateWithArray($item)->create();
     }
     return $output;
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function remove($productSku, $linkedProductSku, $type)
 {
     $linkedProduct = $this->productLoader->load($linkedProductSku);
     $product = $this->productLoader->load($productSku);
     $links = $this->entityCollectionProvider->getCollection($product, $type);
     if (!isset($links[$linkedProduct->getId()])) {
         throw new NoSuchEntityException(sprintf('Product with SKU %s is not linked to product with SKU %s', $linkedProductSku, $productSku));
     }
     //Remove product from the linked product list
     unset($links[$linkedProduct->getId()]);
     $this->saveLinks($product, [$type => $links]);
     return true;
 }