Question

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?

Was it helpful?

Solution

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

OTHER TIPS

Import a configurable products in magento doesnt work well.

Configurable products Import works if there is only one attribute. ie Color or size. It doesnt work with color and size.

I did some efforts on this and above is result of all work. Here are below topics and links which will help you to understand this. It seems this is bug in magento.

Threads:

1. https://github.com/magento/magento2/issues/5876
2. https://github.com/magento/magento2/issues/2703
3. https://www.lexiconn.com/blog/2016/01/magento-2-import-configurable-products/
4. http://magento.stackexchange.com/q/150940/29175
5. http://magento.stackexchange.com/q/15134/29175

Comment if more details required and I try to help you from what i already learned.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top