1

Magento 2.2.7

Trying to export customers and get the error,

Please correct the data sent value.

Exception log says,

main.CRITICAL: Notice: Undefined offset: 14 in /home/public_html/vendor/magento/module-customer-import-export/Model/Export/Customer.php on line 163 {"exception":"[object] (Exception(code: 0): Notice: Undefined offset: 14 in /home/public_html/vendor/magento/module-customer-import-export/Model/Export/Customer.php on line 163 at /home/public_html/vendor/magento/framework/App/ErrorHandler.php:61)"} []

Contents of Customer.php

/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\CustomerImportExport\Model\Export;

/**
 * Export entity customer model
 *
 * @api
 *
 * @method \Magento\Customer\Model\ResourceModel\Attribute\Collection getAttributeCollection() getAttributeCollection()
 * @since 100.0.2
 */
class Customer extends \Magento\ImportExport\Model\Export\Entity\AbstractEav
{
    /**#@+
     * Permanent column names.
     *
     * Names that begins with underscore is not an attribute. This name convention is for
     * to avoid interference with same attribute name.
     */
    const COLUMN_EMAIL = 'email';

    const COLUMN_WEBSITE = '_website';

    const COLUMN_STORE = '_store';

    /**#@-*/

    /**#@+
     * Attribute collection name
     */
    const ATTRIBUTE_COLLECTION_NAME = \Magento\Customer\Model\ResourceModel\Attribute\Collection::class;

    /**#@-*/

    /**#@+
     * XML path to page size parameter
     */
    const XML_PATH_PAGE_SIZE = 'export/customer_page_size/customer';

    /**#@-*/

    /**#@-*/
    protected $_attributeOverrides = [
        'created_at' => ['backend_type' => 'datetime'],
        'reward_update_notification' => ['source_model' => \Magento\Eav\Model\Entity\Attribute\Source\Boolean::class],
        'reward_warning_notification' => ['source_model' => \Magento\Eav\Model\Entity\Attribute\Source\Boolean::class],
    ];

    /**
     * Array of attributes codes which are disabled for export
     *
     * @var string[]
     */
    protected $_disabledAttributes = ['default_billing', 'default_shipping'];

    /**
     * Attributes with index (not label) value.
     *
     * @var string[]
     */
    protected $_indexValueAttributes = ['group_id', 'website_id', 'store_id'];

    /**
     * Permanent entity columns.
     *
     * @var string[]
     */
    protected $_permanentAttributes = [self::COLUMN_EMAIL, self::COLUMN_WEBSITE, self::COLUMN_STORE];

    /**
     * Customers whose data is exported
     *
     * @var \Magento\Customer\Model\ResourceModel\Customer\Collection
     */
    protected $_customerCollection;

    /**
     * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
     * @param \Magento\Store\Model\StoreManagerInterface $storeManager
     * @param \Magento\ImportExport\Model\Export\Factory $collectionFactory
     * @param \Magento\ImportExport\Model\ResourceModel\CollectionByPagesIteratorFactory $resourceColFactory
     * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
     * @param \Magento\Eav\Model\Config $eavConfig
     * @param \Magento\Customer\Model\ResourceModel\Customer\CollectionFactory $customerColFactory
     * @param array $data
     */
    public function __construct(
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        \Magento\ImportExport\Model\Export\Factory $collectionFactory,
        \Magento\ImportExport\Model\ResourceModel\CollectionByPagesIteratorFactory $resourceColFactory,
        \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
        \Magento\Eav\Model\Config $eavConfig,
        \Magento\Customer\Model\ResourceModel\Customer\CollectionFactory $customerColFactory,
        array $data = []
    ) {
        parent::__construct(
            $scopeConfig,
            $storeManager,
            $collectionFactory,
            $resourceColFactory,
            $localeDate,
            $eavConfig,
            $data
        );

        $this->_customerCollection = isset(
            $data['customer_collection']
        ) ? $data['customer_collection'] : $customerColFactory->create();

        $this->_initAttributeValues()->_initAttributeTypes()->_initStores()->_initWebsites(true);
    }

    /**
     * Export process.
     *
     * @return string
     */
    public function export()
    {
        $this->_prepareEntityCollection($this->_getEntityCollection());
        $writer = $this->getWriter();

        // create export file
        $writer->setHeaderCols($this->_getHeaderColumns());
        $this->_exportCollectionByPages($this->_getEntityCollection());

        return $writer->getContents();
    }

    /**
     * Get customers collection
     *
     * @return \Magento\Customer\Model\ResourceModel\Customer\Collection
     */
    protected function _getEntityCollection()
    {
        return $this->_customerCollection;
    }

    /**
     * {@inheritdoc}
     */
    protected function _getHeaderColumns()
    {
        $validAttributeCodes = $this->_getExportAttributeCodes();
        return array_merge($this->_permanentAttributes, $validAttributeCodes, ['password']);
    }

    /**
     * Export given customer data
     *
     * @param \Magento\Customer\Model\Customer $item
     * @return void
     */
    public function exportItem($item)
    {
        $row = $this->_addAttributeValuesToRow($item);
        $row[self::COLUMN_WEBSITE] = $this->_websiteIdToCode[$item->getWebsiteId()];
        $row[self::COLUMN_STORE] = $this->_storeIdToCode[$item->getStoreId()];

        $this->getWriter()->writeRow($row);
    }

    /**
     * Clean up already loaded attribute collection.
     *
     * @param \Magento\Framework\Data\Collection $collection
     * @return \Magento\Framework\Data\Collection
     */
    public function filterAttributeCollection(\Magento\Framework\Data\Collection $collection)
    {
        /** @var $attribute \Magento\Customer\Model\Attribute */
        foreach (parent::filterAttributeCollection($collection) as $attribute) {
            if (!empty($this->_attributeOverrides[$attribute->getAttributeCode()])) {
                $data = $this->_attributeOverrides[$attribute->getAttributeCode()];

                if (isset($data['options_method']) && method_exists($this, $data['options_method'])) {
                    $data['filter_options'] = $this->{$data['options_method']}();
                }
                $attribute->addData($data);
            }
        }
        return $collection;
    }

    /**
     * EAV entity type code getter.
     *
     * @return string
     */
    public function getEntityTypeCode()
    {
        return $this->getAttributeCollection()->getEntityTypeCode();
    }

    /**
     * Retrieve list of overridden attributes
     *
     * @return array
     */
    public function getOverriddenAttributes()
    {
        return $this->_attributeOverrides;
    }
}
3
  • It's working fine in Default Magento ver. 2.2.7 Have you installed any custom modules ? Apr 4, 2019 at 5:20
  • Please share the code of /home/public_html/vendor/magento/module-customer-import-export/Model/Export/Customer.php
    – Amit Bera
    Apr 4, 2019 at 7:50
  • added contents of Customer.php to original post Apr 4, 2019 at 17:28

2 Answers 2

0

Facing same problem in magento 2.2.1 here is the code of /home/public_html/vendor/magento/module-customer-import-export/Model/Export/Customer.php customer.php ... Thanks in Advance

namespace Magento\CustomerImportExport\Model\Export;

    /**
     * Export entity customer model
     *
     * @api
     *
     * @method \Magento\Customer\Model\ResourceModel\Attribute\Collection getAttributeCollection() getAttributeCollection()
     * @since 100.0.2
     */
    class Customer extends \Magento\ImportExport\Model\Export\Entity\AbstractEav
    {
        /**#@+
         * Permanent column names.
         *
         * Names that begins with underscore is not an attribute. This name convention is for
         * to avoid interference with same attribute name.
         */
        const COLUMN_EMAIL = 'email';

        const COLUMN_WEBSITE = '_website';

        const COLUMN_STORE = '_store';

        /**#@-*/

        /**#@+
         * Attribute collection name
         */
        const ATTRIBUTE_COLLECTION_NAME = \Magento\Customer\Model\ResourceModel\Attribute\Collection::class;

        /**#@-*/

        /**#@+
         * XML path to page size parameter
         */
        const XML_PATH_PAGE_SIZE = 'export/customer_page_size/customer';

        /**#@-*/

        /**#@-*/
        protected $_attributeOverrides = [
            'created_at' => ['backend_type' => 'datetime'],
            'reward_update_notification' => ['source_model' => \Magento\Eav\Model\Entity\Attribute\Source\Boolean::class],
            'reward_warning_notification' => ['source_model' => \Magento\Eav\Model\Entity\Attribute\Source\Boolean::class],
        ];

        /**
         * Array of attributes codes which are disabled for export
         *
         * @var string[]
         */
        protected $_disabledAttributes = ['default_billing', 'default_shipping'];

        /**
         * Attributes with index (not label) value.
         *
         * @var string[]
         */
        protected $_indexValueAttributes = ['group_id', 'website_id', 'store_id'];

        /**
         * Permanent entity columns.
         *
         * @var string[]
         */
        protected $_permanentAttributes = [self::COLUMN_EMAIL, self::COLUMN_WEBSITE, self::COLUMN_STORE];

        /**
         * Customers whose data is exported
         *
         * @var \Magento\Customer\Model\ResourceModel\Customer\Collection
         */
        protected $_customerCollection;

        /**
         * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
         * @param \Magento\Store\Model\StoreManagerInterface $storeManager
         * @param \Magento\ImportExport\Model\Export\Factory $collectionFactory
         * @param \Magento\ImportExport\Model\ResourceModel\CollectionByPagesIteratorFactory $resourceColFactory
         * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
         * @param \Magento\Eav\Model\Config $eavConfig
         * @param \Magento\Customer\Model\ResourceModel\Customer\CollectionFactory $customerColFactory
         * @param array $data
         */
        public function __construct(
            \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
            \Magento\Store\Model\StoreManagerInterface $storeManager,
            \Magento\ImportExport\Model\Export\Factory $collectionFactory,
            \Magento\ImportExport\Model\ResourceModel\CollectionByPagesIteratorFactory $resourceColFactory,
            \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
            \Magento\Eav\Model\Config $eavConfig,
            \Magento\Customer\Model\ResourceModel\Customer\CollectionFactory $customerColFactory,
            array $data = []
        ) {
            parent::__construct(
                $scopeConfig,
                $storeManager,
                $collectionFactory,
                $resourceColFactory,
                $localeDate,
                $eavConfig,
                $data
            );

            $this->_customerCollection = isset(
                $data['customer_collection']
            ) ? $data['customer_collection'] : $customerColFactory->create();

            $this->_initAttributeValues()->_initAttributeTypes()->_initStores()->_initWebsites(true);
        }

        /**
         * Export process.
         *
         * @return string
         */
        public function export()
        {
            $this->_prepareEntityCollection($this->_getEntityCollection());
            $writer = $this->getWriter();

            // create export file
            $writer->setHeaderCols($this->_getHeaderColumns());
            $this->_exportCollectionByPages($this->_getEntityCollection());

            return $writer->getContents();
        }

        /**
         * Get customers collection
         *
         * @return \Magento\Customer\Model\ResourceModel\Customer\Collection
         */
        protected function _getEntityCollection()
        {
            return $this->_customerCollection;
        }

        /**
         * {@inheritdoc}
         */
        protected function _getHeaderColumns()
        {
            $validAttributeCodes = $this->_getExportAttributeCodes();
            return array_merge($this->_permanentAttributes, $validAttributeCodes, ['password']);
        }

        /**
         * Export given customer data
         *
         * @param \Magento\Customer\Model\Customer $item
         * @return void
         */
        public function exportItem($item)
        {
            $row = $this->_addAttributeValuesToRow($item);
            $row[self::COLUMN_WEBSITE] = $this->_websiteIdToCode[$item->getWebsiteId()];
            $row[self::COLUMN_STORE] = $this->_storeIdToCode[$item->getStoreId()];

            $this->getWriter()->writeRow($row);
        }

        /**
         * Clean up already loaded attribute collection.
         *
         * @param \Magento\Framework\Data\Collection $collection
         * @return \Magento\Framework\Data\Collection
         */
        public function filterAttributeCollection(\Magento\Framework\Data\Collection $collection)
        {
            /** @var $attribute \Magento\Customer\Model\Attribute */
            foreach (parent::filterAttributeCollection($collection) as $attribute) {
                if (!empty($this->_attributeOverrides[$attribute->getAttributeCode()])) {
                    $data = $this->_attributeOverrides[$attribute->getAttributeCode()];

                    if (isset($data['options_method']) && method_exists($this, $data['options_method'])) {
                        $data['filter_options'] = $this->{$data['options_method']}();
                    }
                    $attribute->addData($data);
                }
            }
            return $collection;
        }

        /**
         * EAV entity type code getter.
         *
         * @return string
         */
        public function getEntityTypeCode()
        {
            return $this->getAttributeCollection()->getEntityTypeCode();
        }

        /**
         * Retrieve list of overridden attributes
         *
         * @return array
         */
        public function getOverriddenAttributes()
        {
            return $this->_attributeOverrides;
        }
    }
0

I also got this exact error when exporting.

Looking at line 163 in Customer.php file, we get this:

$row[self::COLUMN_WEBSITE] = $this->_websiteIdToCode[$item->getWebsiteId()];

So its something its not liking regarding the store id's, possibly due to multi-site setup.

I found that if you exclude the 'store_id' attribute when exporting, it doesnt throw the error and will download the file. This attribute is easy to add back in later, as it should still tell you which storeview name the customer belongs to.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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