Skip to content

Commit 095c434

Browse files
committed
Import: Allow injecting own link types to LinkProcessor
1 parent a269519 commit 095c434

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
222222
/**
223223
* Links attribute name-to-link type ID.
224224
*
225+
* @deprecated use DI for LinkProcessor class if you want to add additional types
226+
*
225227
* @var array
226228
*/
227229
protected $_linkNameToId = [
@@ -882,6 +884,8 @@ public function __construct(
882884
->get(StockItemImporterInterface::class);
883885
$this->linkProcessor = $linkProcessor ?? ObjectManager::getInstance()
884886
->get(LinkProcessor::class);
887+
$this->linkProcessor->addNameToIds($this->_linkNameToId);
888+
885889
parent::__construct(
886890
$jsonHelper,
887891
$importExportData,

app/code/Magento/CatalogImportExport/Model/Import/Product/LinkProcessor.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ class LinkProcessor
3030
'_crosssell_' => \Magento\Catalog\Model\Product\Link::LINK_TYPE_CROSSSELL,
3131
'_upsell_' => \Magento\Catalog\Model\Product\Link::LINK_TYPE_UPSELL,
3232
];
33+
/**
34+
* @var array
35+
*/
36+
private $linkNameToId;
3337

3438
/** @var LinkFactory */
3539
private $linkFactory;
@@ -38,21 +42,24 @@ class LinkProcessor
3842
private $resourceHelper;
3943

4044
/** @var SkuProcessor */
41-
protected $skuProcessor;
45+
private $skuProcessor;
4246

4347
/** @var LoggerInterface */
44-
protected $logger;
48+
private $logger;
4549

4650
public function __construct(
4751
LinkFactory $linkFactory,
4852
Helper $resourceHelper,
4953
SkuProcessor $skuProcessor,
50-
LoggerInterface $logger
54+
LoggerInterface $logger,
55+
array $linkNameToId
5156
) {
5257
$this->linkFactory = $linkFactory;
5358
$this->resourceHelper = $resourceHelper;
5459
$this->skuProcessor = $skuProcessor;
5560
$this->logger = $logger;
61+
62+
$this->linkNameToId = $linkNameToId;
5663
}
5764

5865
/**
@@ -92,6 +99,11 @@ public function saveLinks(
9299
return $this;
93100
}
94101

102+
public function addNameToIds($nameToIds)
103+
{
104+
$this->linkNameToId = array_merge($nameToIds, $this->linkNameToId);
105+
}
106+
95107
/**
96108
* Processes link bunches
97109
*

app/code/Magento/CatalogImportExport/etc/di.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,13 @@
2828
</argument>
2929
</arguments>
3030
</type>
31+
<type name="Magento\CatalogImportExport\Model\Import\Product\LinkProcessor">
32+
<arguments>
33+
<argument name="linkNameToId" xsi:type="array">
34+
<item name="_related_" xsi:type="const">Magento\Catalog\Model\Product\Link::LINK_TYPE_RELATED</item>
35+
<item name="_crosssell_" xsi:type="const">Magento\Catalog\Model\Product\Link::LINK_TYPE_CROSSSELL</item>
36+
<item name="_upsell_" xsi:type="const">Magento\Catalog\Model\Product\Link::LINK_TYPE_UPSELL</item>
37+
</argument>
38+
</arguments>
39+
</type>
3140
</config>

0 commit comments

Comments
 (0)