Skip to content

Commit

Permalink
magento#18624 Refactoring: Extract linkNameToId to di config
Browse files Browse the repository at this point in the history
  • Loading branch information
amenk committed Mar 9, 2019
1 parent 49b62cf commit f8fcb2e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,47 @@ class LinkProcessor
*
* @var array
*/
protected $_linkNameToId = [
'_related_' => \Magento\Catalog\Model\Product\Link::LINK_TYPE_RELATED,
'_crosssell_' => \Magento\Catalog\Model\Product\Link::LINK_TYPE_CROSSSELL,
'_upsell_' => \Magento\Catalog\Model\Product\Link::LINK_TYPE_UPSELL,
];
protected $_linkNameToId = [];

protected $_linkFactory;

protected $_logger;

protected $_resourceHelper;

protected $_dataSourceModel;

protected $skuProcessor;

protected $_connection;

protected $_resource;

public function __construct(
ResourceConnection $resourceConnection,
LinkFactory $linkFactory,
LoggerInterface $logger,
Helper $resourceHelper,
Data $importData,
SkuProcessor $skuProcessor
SkuProcessor $skuProcessor,
\Magento\Framework\App\Arguments\ArgumentInterpreter $argumentInterpreter,
array $linkNameToId
) {
$this->_linkFactory = $linkFactory;
$this->_logger = $logger;
$this->_resourceHelper = $resourceHelper;
$this->_dataSourceModel = $importData;
$this->skuProcessor = $skuProcessor;

$this->_resource = $this->_linkFactory->create();
// Temporary solution: arrays do not seem to support init_parameter,
// so we have to parse the constant by ourselves
$this->_linkNameToId = [];
foreach($linkNameToId as $key=>$value) {
$this->_linkNameToId[$key] = constant($value);
}

$this->_connection = $resourceConnection->getConnection();
$this->_resource = $this->_linkFactory->create();
}

public function saveLinks($entityModel, $productEntityLinkField)
Expand Down
9 changes: 9 additions & 0 deletions app/code/Magento/CatalogImportExport/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,13 @@
</argument>
</arguments>
</type>
<type name="Magento\CatalogImportExport\Model\Import\Product\LinkProcessor">
<arguments>
<argument name="linkNameToId" xsi:type="array">
<item name="_related_" xsi:type="string">Magento\Catalog\Model\Product\Link::LINK_TYPE_RELATED</item>
<item name="_crosssell_" xsi:type="string">Magento\Catalog\Model\Product\Link::LINK_TYPE_CROSSSELL</item>
<item name="_upsell_" xsi:type="string">Magento\Catalog\Model\Product\Link::LINK_TYPE_UPSELL</item>
</argument>
</arguments>
</type>
</config>

0 comments on commit f8fcb2e

Please sign in to comment.