Magento2.1.3 – Import Configurable Product Issues

configurable-productimportmagento2virtual-products

I'm trying to import a configurable product using the native import function in M2.

What I have done, is add a product manually using the admin interface, export that .csv file, modify the name/image/pricing, and reimport.

The product I added manually imports fine, but when I export, modify and reimport, the configurable product appears in searches after I reindex, but none of the configurations appear in the frontend dropdown when viewing a product.

  • There are no errors in the file formating
  • Encoded in UTF-8-BOM
  • The products appears in the admin interface via "Products > Catalog"
  • The products are in stock
  • The products are enabled
  • The products have a quantity of 100
  • M2 is set to developer mode

I have gone as far to rebuild static content, with no change. There are no errors/exceptions.

How can I find more information on the issue? I have PMA, is there anything I can check in the database that might cause an issue?

Best Answer

Github issue related :

https://github.com/magento/magento2/issues/6938

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

Remove this when Magento fixed the bug.

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,
            ];
        }
    }
}
Related Topic