45 $linkTypes = $this->linkTypeProvider->getLinkTypes();
47 if (!isset($linkTypes[
$type])) {
49 __(
'The "%1" link type is unknown. Verify the type and try again.', (
string)
$type)
52 $product = $this->productRepository->get($sku);
70 $linkTypes = $this->linkTypeProvider->getLinkTypes();
74 foreach (
$items as $newLink) {
75 $type = $newLink->getLinkType();
79 if (!isset($linkTypes[
$type])) {
81 __(
'The "%1" link type wasn\'t found. Verify the type and try again.',
$type)
87 $product = $this->productRepository->get($sku);
90 $existingLinks =
$product->getProductLinks();
92 if (!empty($existingLinks)) {
93 foreach ($existingLinks as
$link) {
104 $this->productRepository->save(
$product);
105 }
catch (\Exception $exception) {
__construct(\Magento\Catalog\Api\ProductRepositoryInterface $productRepository, \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider)
setProductLinks($sku, array $items)
getLinkedItemsByType($sku, $type)