Skip to content

Instantly share code, notes, and snippets.

@FactoryAidan
Last active June 23, 2023 04:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FactoryAidan/a8d5db00eb0bc4cac792adf2364ff698 to your computer and use it in GitHub Desktop.
Save FactoryAidan/a8d5db00eb0bc4cac792adf2364ff698 to your computer and use it in GitHub Desktop.
Magento 2.4.0 update of `vendor/magento/module-catalog-import-export/Model/Import/Product.php::_prepareRowForDb()` to handle both `array|null` return types from `$this->skuProcessor->getNewSku()`
diff --git a/vendor/magento/module-catalog-import-export/Model/Import/Product.php b/vendor/magento/module-catalog-import-export/Model/Import/Product.php
index 25bbecdce..1c50196a2 100644
--- a/vendor/magento/module-catalog-import-export/Model/Import/Product.php
+++ b/vendor/magento/module-catalog-import-export/Model/Import/Product.php
@@ -1278,8 +1278,11 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
if ($this->isSkuExist($lastSku)) {
$newSku = $this->skuProcessor->getNewSku($lastSku);
- $rowData[self::COL_ATTR_SET] = $newSku['attr_set_code'];
- $rowData[self::COL_TYPE] = $newSku['type_id'];
+ // 👆 can return array|null but null is not handled.
+ if( is_array($newSku) ){
+ $rowData[self::COL_ATTR_SET] = $newSku['attr_set_code'];
+ $rowData[self::COL_TYPE] = $newSku['type_id'];
+ }
}
return $rowData;
@FactoryAidan
Copy link
Author

FactoryAidan commented Oct 7, 2020

  1. Place file in {your_web_root}/m2-hotfixes/*
  2. Install with {your_web_root}/composer.json:
{
    "require": {
        "cweagans/composer-patches": "^1.6"
    },
    "extra": {
        "patches": {
            "magento/module-catalog-import-export": {
                "getNewSku returns array or null but null is not handled": "m2-hotfixes/AG_MAGE_EE_2.4.0_COMPOSER_v1.patch"
            }
        }
    }
}
  1. Run composer update; to reinstall the magento/module-catalog-import-export module with the patch applied.

@dfelton
Copy link

dfelton commented Oct 8, 2020

Alternate Solution (also I've added this to my question on magento.stackexchange.com, thanks again for your response):

app/code/VendorName/ModuleName/etc/di.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Firebear\ImportExport\Model\Import\Product" type="VendorName\ModuleName\Model\Import\Product"/>
</config>

app/code/VendorName/ModuleName/Model/Import/Product.php:

<?php

declare(strict_types=1);

namespace VendorName\ModuleName\Model\Import;

class Product extends \Firebear\ImportExport\Model\Import\Product
{
    protected function _prepareRowForDb(array $rowData): array
    {
        $level = error_reporting();
        if (E_NOTICE & $level === 0) {
            return parent::_prepareRowForDb($rowData);
        }

        error_reporting($level & ~E_NOTICE);
        $rowData = parent::_prepareRowForDb($rowData);
        error_reporting($level);

        return $rowData;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment