3

I have installed Magento 2.1.3 with sample data, and export one configurable product with attribute size and color.

Next, I change necessary fields and import this file but product imported with the only size attribute color attribute not come.

By manually fixing the data I got import to work.

The export I got as below

sku=TEST-CONFIG-1-Blue-Small,size=Small|
sku=TEST-CONFIG-1-Blue-Medium,size=Medium|
sku=TEST-CONFIG-1-Orange-Small,size=Small|
sku=TEST-CONFIG-1-Orange-Medium,size=Medium

The export I wanted

sku=TEST-CONFIG-1-Blue-Small,color=Blue,size=Small|
sku=TEST-CONFIG-1-Blue-Medium,color=Blue,size=Medium|
sku=TEST-CONFIG-1-Orange-Small,color=Orange,size=Small|
sku=TEST-CONFIG-1-Orange-Medium,color=Orange,size=Medium

It is looking like Magento 2 bug.

Has anyone a solution for the same?

marked as duplicate by Rakesh Jesadiya, Siarhey Uchukhlebau, Keyul Shah, Ashish Jagnani, Murtuza Zabuawala Mar 28 '17 at 8:33

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Have you check system.log file after importing ? – Hardik Visa Jan 6 '17 at 12:40
  • Not find any log related to this issue. – Nikunj Vadariya Jan 9 '17 at 4:43
  • I tried to create configuration product with simple prodcut its work in my case in Magento 2.1.2. – Hardik Visa Jan 9 '17 at 5:01
0

In order to export configurable products with more than 1 variation, you can use this workaround. You will be able to export / reimport the csv file from Magento 2 backoffice.

Keep in mind to remove this fix when Magento will fix it.

di.xml

<preference for="Magento\ConfigurableImportExport\Model\Export\RowCustomizer" type="Vendor\ImportExport\Model\Export\RowCustomizer" />

app/code/Vendor/ImportExport/Model/Export/RowCustomizer.php

<?php
namespace Vendor\ImportExport\Model\Export;

use \Magento\CatalogImportExport\Model\Import\Product as ImportProduct;
use \Magento\ImportExport\Model\Import;

class RowCustomizer extends \Magento\ConfigurableImportExport\Model\Export\RowCustomizer
{
    /**
     * Prepare configurable data for export
     *
     * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
     * @param int[] $productIds
     * @return void
     */
    public function prepareData($collection, $productIds)
    {
        $productCollection = clone $collection;
        $productCollection->addAttributeToFilter(
            'entity_id',
            ['in' => $productIds]
        )->addAttributeToFilter(
            'type_id',
            ['eq' => \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE]
        );

        while ($product = $productCollection->fetchItem()) {
            $productAttributesOptions = $product->getTypeInstance()->getConfigurableOptions($product);

            $variations = [];
            $variationsLabels = [];

            foreach ($productAttributesOptions as $productAttributeOption) {
                $this->configurableData[$product->getId()] = [];

                foreach ($productAttributeOption as $optValues) {
                    $variations[$optValues['sku']][] =
                        $optValues['attribute_code'] . '=' . $optValues['option_title'];
                    if (!empty($optValues['super_attribute_label'])) {
                        $variationsLabels[$optValues['attribute_code']] =
                            $optValues['attribute_code'] . '=' . $optValues['super_attribute_label'];
                    }
                }
            }

            foreach ($variations as $sku => $values) {
                $variations[$sku] =
                    'sku=' . $sku . Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR
                    . implode(Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $values);
            }
            $variations = implode(ImportProduct::PSEUDO_MULTI_LINE_SEPARATOR, $variations);
            $variationsLabels = implode(Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $variationsLabels);

            $this->configurableData[$product->getId()] = [
                'configurable_variations' => $variations,
                'configurable_variation_labels' => $variationsLabels,
            ];
        }
    }
}

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