Skip to content

Commit

Permalink
Sync with magento#9600 code
Browse files Browse the repository at this point in the history
  • Loading branch information
kassner authored May 29, 2017
1 parent 3347ede commit eccf87b
Showing 1 changed file with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,22 @@ protected function setProductLinks(\Magento\Catalog\Model\Product $product)

$product = $this->productLinks->initializeLinks($product, $links);
$productLinks = $product->getProductLinks();
$linkTypes = [];

/** @var \Magento\Catalog\Api\Data\ProductLinkTypeInterface $linkTypeObject */
foreach ($this->linkTypeProvider->getItems() as $linkTypeObject) {
$linkTypes[$linkTypeObject->getName()] = $product->getData($linkTypeObject->getName() . '_readonly');
}

// skip linkTypes that were already processed on initializeLinks plugins
foreach ($productLinks as $productLink) {
unset($linkTypes[$productLink->getLinkType()]);
}

/** @var \Magento\Catalog\Api\Data\ProductLinkTypeInterface $linkType */
foreach ($this->linkTypeProvider->getItems() as $linkType) {
$readonly = $product->getData($linkType->getName() . '_readonly');

if (isset($links[$linkType->getName()]) && !$readonly) {
foreach ((array) $links[$linkType->getName()] as $linkData) {
foreach ($linkTypes as $linkType => $readonly) {
if (isset($links[$linkType]) && !$readonly) {
foreach ((array) $links[$linkType] as $linkData) {
if (empty($linkData['id'])) {
continue;
}
Expand All @@ -271,7 +280,7 @@ protected function setProductLinks(\Magento\Catalog\Model\Product $product)
$link = $this->getProductLinkFactory()->create();
$link->setSku($product->getSku())
->setLinkedProductSku($linkProduct->getSku())
->setLinkType($linkType->getName())
->setLinkType($linkType)
->setPosition(isset($linkData['position']) ? (int)$linkData['position'] : 0);
$productLinks[] = $link;
}
Expand Down

0 comments on commit eccf87b

Please sign in to comment.