2

I tried to export all the customers in the form of csv from a Magento 2.1.3 site.

enter image description here

But after I clicked export this will be the outcome:

enter image description here

1 exception(s): Exception #0 (Exception): Notice: Undefined offset: 0 in /var/www/DEVELOPMENT/html/vendor/magento/module-customer/Ui/Component/DataProvider/Document.php on line 135

Any ideas what's wrong with this one?

Thanks!

1

@MazeStricks,

A similar issue is reported on the Magento forums at:

I also faced the same issue while exporting customers from the admin panel via CSV and XML on Magento EE 2.2.3

{
  "0": "Notice: Undefined offset: 7 in /vendor/magento/module-customer/Ui/Component/DataProvider/Document.php on line 136",
  "1": "#0 /vendor/magento/module-customer/Ui/Component/DataProvider/Document.php(136): Magento\\Framework\\App\\ErrorHandler->handler(8, 'Undefined offse...', '/app/wtzyes327l...', 136, Array)\n#1 /vendor/magento/module-customer/Ui/Component/DataProvider/Document.php(102): Magento\\Customer\\Ui\\Component\\DataProvider\\Document->setGenderValue()\n#2 /vendor/magento/module-ui/Model/Export/MetadataProvider.php(159): Magento\\Customer\\Ui\\Component\\DataProvider\\Document->getCustomAttribute('gender')\n#3 /vendor/magento/module-ui/Model/Export/ConvertToCsv.php(84): Magento\\Ui\\Model\\Export\\MetadataProvider->getRowData(Object(Magento\\Customer\\Ui\\Component\\DataProvider\\Document), Array, Array)\n#4 /vendor/magento/module-ui/Controller/Adminhtml/Export/GridToCsv.php(72): Magento\\Ui\\Model\\Export\\ConvertToCsv->getCsvFile()\n#5 /vendor/magento/framework/App/Action/Action.php(107): Magento\\Ui\\Controller\\Adminhtml\\Export\\GridToCsv->execute()\n#6 /vendor/magento/module-backend/App/AbstractAction.php(229): Magento\\Framework\\App\\Action\\Action->dispatch(Object(Magento\\Framework\\App\\Request\\Http))\n#7 /vendor/magento/framework/Interception/Interceptor.php(58): Magento\\Backend\\App\\AbstractAction->dispatch(Object(Magento\\Framework\\App\\Request\\Http))\n#8 /vendor/magento/framework/Interception/Interceptor.php(138): Magento\\Ui\\Controller\\Adminhtml\\Export\\GridToCsv\\Interceptor->___callParent('dispatch', Array)\n#9 /vendor/magento/module-backend/App/Action/Plugin/Authentication.php(143): Magento\\Ui\\Controller\\Adminhtml\\Export\\GridToCsv\\Interceptor->Magento\\Framework\\Interception\\{closure}(Object(Magento\\Framework\\App\\Request\\Http))\n#10 /vendor/magento/framework/Interception/Interceptor.php(135): Magento\\Backend\\App\\Action\\Plugin\\Authentication->aroundDispatch(Object(Magento\\Ui\\Controller\\Adminhtml\\Export\\GridToCsv\\Interceptor), Object(Closure), Object(Magento\\Framework\\App\\Request\\Http))\n#11 /vendor/magento/framework/Interception/Interceptor.php(153): Magento\\Ui\\Controller\\Adminhtml\\Export\\GridToCsv\\Interceptor->Magento\\Framework\\Interception\\{closure}(Object(Magento\\Framework\\App\\Request\\Http))\n#12 /generated/code/Magento/Ui/Controller/Adminhtml/Export/GridToCsv/Interceptor.php(26): Magento\\Ui\\Controller\\Adminhtml\\Export\\GridToCsv\\Interceptor->___callPlugins('dispatch', Array, NULL)\n#13 /vendor/magento/framework/App/FrontController.php(55): Magento\\Ui\\Controller\\Adminhtml\\Export\\GridToCsv\\Interceptor->dispatch(Object(Magento\\Framework\\App\\Request\\Http))\n#14 /vendor/magento/framework/Interception/Interceptor.php(58): Magento\\Framework\\App\\FrontController->dispatch(Object(Magento\\Framework\\App\\Request\\Http))\n#15 /vendor/magento/framework/Interception/Interceptor.php(138): Magento\\Framework\\App\\FrontController\\Interceptor->___callParent('dispatch', Array)\n#16 /vendor/magento/framework/Interception/Interceptor.php(153): Magento\\Framework\\App\\FrontController\\Interceptor->Magento\\Framework\\Interception\\{closure}(Object(Magento\\Framework\\App\\Request\\Http))\n#17 /generated/code/Magento/Framework/App/FrontController/Interceptor.php(26): Magento\\Framework\\App\\FrontController\\Interceptor->___callPlugins('dispatch', Array, Array)\n#18 /vendor/magento/framework/App/Http.php(135): Magento\\Framework\\App\\FrontController\\Interceptor->dispatch(Object(Magento\\Framework\\App\\Request\\Http))\n#19 /vendor/magento/framework/App/Bootstrap.php(256): Magento\\Framework\\App\\Http->launch()\n#20 /pub/index.php(37): Magento\\Framework\\App\\Bootstrap->run(Object(Magento\\Framework\\App\\Http\\Interceptor))\n#21 {main}",
  "url": "/admin/mui/export/gridToCsv/key/4b1c73d5e71f0802f16b0380aecd481a7ec5f2b6a45b7006a243d13dd3ce9be4/?filters%5Bplaceholder%5D=true&search=&namespace=customer_listing&selected=false",
  "script_name": "/index.php"
}

For me though, the issue was caused during setting Gender of the customer in "Magento\Customer\Ui\Component\DataProvider\Document.php"

at $option = $attributeMetadata->getOptions()[$value];

The following was the piece of code with error:

   /**
     * Update customer gender value
     * Method set gender label instead of id value
     * @return void
     */
    private function setGenderValue()
    {
        $value = $this->getData(self::$genderAttributeCode);

        if (!$value) {
            $this->setCustomAttribute(self::$genderAttributeCode, 'N/A');
            return;
        }

        try {
            $attributeMetadata = $this->customerMetadata->getAttributeMetadata(self::$genderAttributeCode);
            $option = $attributeMetadata->getOptions()[$value];
            $this->setCustomAttribute(self::$genderAttributeCode, $option->getLabel());
        } catch (NoSuchEntityException $e) {
            $this->setCustomAttribute(self::$genderAttributeCode, 'N/A');
        }
    }

The fixed code was :

   /**
     * Update customer gender value
     * Method set gender label instead of id value
     * @return void
     */
    private function setGenderValue()
    {
        $value = $this->getData(self::$genderAttributeCode);


        if (!$value) {
            $this->setCustomAttribute(self::$genderAttributeCode, 'N/A');
            return;
        }

        try {
            $attributeMetadata = $this->customerMetadata->getAttributeMetadata(self::$genderAttributeCode);

            foreach ($attributeMetadata->getOptions() as $option) {
                if ($option->getValue() == $value) {
                    $this->setCustomAttribute(self::$genderAttributeCode, $option->getLabel());
                    break;
                }
            }
        } catch (NoSuchEntityException $e) {
            $this->setCustomAttribute(self::$genderAttributeCode, 'N/A');
        }
    }
  • Hello Shahab, Thanks for this one. I'll try this. – MazeStricks Jan 5 at 2:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.