From 66f19a8e7a045b0e564aefb00db08ed4829a99ae Mon Sep 17 00:00:00 2001 From: "Cristian O. Balan" Date: Sat, 2 Dec 2023 03:03:52 +0000 Subject: [PATCH] Fix array_key_exists error Error: There is an error in app/code/Macopedia/CategoryImporter/Console/Command/CategoriesCommand.php at line: 159 array_key_exists(): Argument #2 ($array) must be of type array, null given#0 app/code/Macopedia/CategoryImporter/Console/Command/CategoriesCommand.php(159): array_key_exists() #1 vendor/symfony/console/Command/Command.php(298): Macopedia\CategoryImporter\Console\Command\CategoriesCommand->execute() #2 vendor/magento/framework/Interception/Interceptor.php(58): Symfony\Component\Console\Command\Command->run() #3 vendor/magento/framework/Interception/Interceptor.php(138): Macopedia\CategoryImporter\Console\Command\CategoriesCommand\Interceptor->___callParent() #4 vendor/magento/framework/Interception/Interceptor.php(153): Macopedia\CategoryImporter\Console\Command\CategoriesCommand\Interceptor->Magento\Framework\Interception\{closure}() #5 generated/code/Macopedia/CategoryImporter/Console/Command/CategoriesCommand/Interceptor.php(23): Macopedia\CategoryImporter\Console\Command\CategoriesCommand\Interceptor->___callPlugins() #6 vendor/symfony/console/Application.php(1040): Macopedia\CategoryImporter\Console\Command\CategoriesCommand\Interceptor->run() #7 vendor/symfony/console/Application.php(301): Symfony\Component\Console\Application->doRunCommand() #8 vendor/magento/framework/Console/Cli.php(116): Symfony\Component\Console\Application->doRun() #9 vendor/symfony/console/Application.php(171): Magento\Framework\Console\Cli->doRun() #10 bin/magento(23): Symfony\Component\Console\Application->run() #11 {main} The error you're encountering is due to the `array_key_exists` function being called with a null value as the second argument on line 159. This suggests that `$this->headersMap` is null or not an array. To fix this issue, you should ensure that `$this->headersMap` is initialized as an array before using it in `array_key_exists`. You can modify the mapHeaders method to include an initialization for `$this->headersMap`. Here's an updated version of the mapHeaders method. By adding the line `$this->headersMap = [];` at the beginning of the method, you ensure that `$this->headersMap` is always an array, even if it wasn't initialized before. This should resolve the `array_key_exists` error. --- Console/Command/CategoriesCommand.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Console/Command/CategoriesCommand.php b/Console/Command/CategoriesCommand.php index 7aa1289..d69e585 100644 --- a/Console/Command/CategoriesCommand.php +++ b/Console/Command/CategoriesCommand.php @@ -307,6 +307,8 @@ protected function mapHeaders($row) { $headers = array_merge($this->requiredHeaders, $this->optionalHeaders, $this->additionalHeaders); + $this->headersMap = []; // Initialize headersMap as an empty array + foreach ($row as $key => $item) { if (in_array($item, $headers)) { $this->headersMap[$item] = $key;