magepal / magento2-link-product

Custom Product Relation for Magento 2.2.x and 2.3.x sample extension
https://www.magepal.com
53 stars 20 forks source link

Need modification for Bulk Import since Magento 2.4.1 #9

Open 0-Sony opened 3 years ago

0-Sony commented 3 years ago

Magento version : 2.4.1

Edition (EE, CE, OS, etc): CE, EE

Expected behavior: bulk import works

Actual behavior: can't bulk import accessory product link type

Steps to reproduce:

Just import a csv file using the out of the box bulk import feature

Preconditions

Magento 2.4.1 php 7.4

Hi Magepal,

Currently working on Magento 2.4.1, you would need to update your module in order to make it working with this new Magento version. The current patch needed for the import that you provide don't work anymore since the codebase has changed in Magento Core.

I suggest that you need to make a plugin to this method \Magento\CatalogImportExport\Model\Import\Product\LinkProcessor::addNameToIds in order to add your accessory product type

if you take a look on this class : \Magento\CatalogImportExport\Model\Import\Product

you will see this from line 225 :

    /**
     * Links attribute name-to-link type ID.
     *
     * @deprecated 101.1.0 use DI for LinkProcessor class if you want to add additional types
     *
     * @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,
    ];

Regards.

srenon commented 3 years ago

@0-Sony ... thanks for reporting this issue.

Can you try this solution and let me know if it works?

In app/code/MagePal/LinkProduct/etc/di.xml

add

    <type name="Magento\CatalogImportExport\Model\Import\Product\LinkProcessor">
        <arguments>
            <argument name="linkNameToId" xsi:type="array">
                <item name="_accessory_" xsi:type="const">MagePal\LinkProduct\Model\Product\Link::LINK_TYPE_ACCESSORY</item>
            </argument>
        </arguments>
    </type>

Let me know so I can release a new version

0-Sony commented 3 years ago

Hi @srenon ,

you would need also to add new key/value in this array \Magento\CatalogImportExport\Model\Import\Product::$_fieldsMap You need to add a new Model Type in import.xml and use customFieldsMapping method. Check this class \Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType

it's used here $this->_fieldsMap = array_merge($this->_fieldsMap, $model->getCustomFieldsMapping()); line 1236 in \Magento\CatalogImportExport\Model\Import\Product

Regards

srenon commented 3 years ago

@0-Sony ... This going to take a while for me to get set up and figure out. Since you already have a handle on this you are more than welcome to create a Pull Request and I will merge it in.

lbauche commented 3 years ago

Hello,

I've got the same issue on same magento version.

I've simply overrided Class Magento\CatalogImportExport\Model\Import\Product througth di.xml to add : in $_linkNameToId : '_accessory_' => \MagePal\LinkProduct\Model\Product\Link::LINK_TYPE_ACCESSORY, in $_fieldsMap : '_accessory_sku' => 'accessory_skus', '_accessory_position' => 'accessory_position',

And it's working fine on v2.4.1 CE.

Regards,