Skip to content

Commit 0c6c8a2

Browse files
Merge pull request #1174 from magento-engcom/2.1-develop-prs
[EngCom] Public Pull Requests - 2.1 - MAGETWO-69665: Backport of MAGETWO-59089 for Magento 2.1: Magento 2.1.1 Problem with change currency #9841 - MAGETWO-69543: Fixes regression bug introduced in Magento 2.1.6 where the layered navigation options are sometimes being cached using the wrong store id. #9704 - MAGETWO-69151: Do not hardcode product link types [2.1 backport] #9601 - MAGETWO-69691: Travis build failures because the job exceeded the maximum time limit for jobs - 2.1-develop
2 parents 118a197 + 7294054 commit 0c6c8a2

File tree

6 files changed

+321
-40
lines changed

6 files changed

+321
-40
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ class Helper
7474
* @var \Magento\Framework\Stdlib\DateTime\Filter\DateTime
7575
*/
7676
private $dateTimeFilter;
77+
78+
/**
79+
* @var \Magento\Catalog\Model\Product\LinkTypeProvider
80+
*/
81+
private $linkTypeProvider;
7782

7883
/**
7984
* Helper constructor.
@@ -83,21 +88,25 @@ class Helper
8388
* @param ProductLinks $productLinks
8489
* @param \Magento\Backend\Helper\Js $jsHelper
8590
* @param \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter
91+
* @param \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider
8692
*/
8793
public function __construct(
8894
\Magento\Framework\App\RequestInterface $request,
8995
\Magento\Store\Model\StoreManagerInterface $storeManager,
9096
StockDataFilter $stockFilter,
9197
\Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks $productLinks,
9298
\Magento\Backend\Helper\Js $jsHelper,
93-
\Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter
99+
\Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter,
100+
\Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider = null
94101
) {
95102
$this->request = $request;
96103
$this->storeManager = $storeManager;
97104
$this->stockFilter = $stockFilter;
98105
$this->productLinks = $productLinks;
99106
$this->jsHelper = $jsHelper;
100107
$this->dateFilter = $dateFilter;
108+
$this->linkTypeProvider = $linkTypeProvider ?: \Magento\Framework\App\ObjectManager::getInstance()
109+
->get(\Magento\Catalog\Model\Product\LinkTypeProvider::class);
101110
}
102111

103112
/**
@@ -247,11 +256,17 @@ protected function setProductLinks(\Magento\Catalog\Model\Product $product)
247256

248257
$product = $this->productLinks->initializeLinks($product, $links);
249258
$productLinks = $product->getProductLinks();
250-
$linkTypes = [
251-
'related' => $product->getRelatedReadonly(),
252-
'upsell' => $product->getUpsellReadonly(),
253-
'crosssell' => $product->getCrosssellReadonly()
254-
];
259+
$linkTypes = [];
260+
261+
/** @var \Magento\Catalog\Api\Data\ProductLinkTypeInterface $linkTypeObject */
262+
foreach ($this->linkTypeProvider->getItems() as $linkTypeObject) {
263+
$linkTypes[$linkTypeObject->getName()] = $product->getData($linkTypeObject->getName() . '_readonly');
264+
}
265+
266+
// skip linkTypes that were already processed on initializeLinks plugins
267+
foreach ($productLinks as $productLink) {
268+
unset($linkTypes[$productLink->getLinkType()]);
269+
}
255270

256271
foreach ($linkTypes as $linkType => $readonly) {
257272
if (isset($links[$linkType]) && !$readonly) {

0 commit comments

Comments
 (0)