1

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?

2

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,
            ];
        }
    }
}
  • Hello, thanks for your reply. The files you mention for me are located at "/var/www/html/magento/vendor/magento/module-configurable-import-export/etc" - I'm going to assume it doesn't matter. For di.xml, is this located at "/etc/di.xml"? Thanks for your time – PublicDisplayName Jan 2 '17 at 15:06
  • You need to create your own module and do not modify core files. – Franck Garnier Jan 4 '17 at 7:05
  • @FranckGarnier is there GitHub issue / pull request for that problem / fix? – FireBear Mar 24 '17 at 13:28
  • @FireBear Yes there is : github.com/magento/magento2/issues/6938 I update my answer too. – Franck Garnier Mar 27 '17 at 8:17
  • Hi @Franck Garnier I have follow above steps but still not working.. I have follow many topics which mentioned in Github but still doesnt work well. I'M using Magento ver. 2.1.2. – Randhir Yadav Apr 27 '17 at 11:00
3

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.

  • In order to import more than 1 variation, the problem is in this file: vendor/magento/module-configurable-import-export/Model/Export/RowCustomizer.php:26 Indeed, the variable $this->configurableData[$product->getId()] is replaced on each loop. – Franck Garnier Jan 2 '17 at 7:14
  • Hello, thanks for your detailed reply @Jai, seems like this is what's causing my issue. I'm trying to import three virtual products each with a different "pack_size". I'm glad that it's not just me! – PublicDisplayName Jan 2 '17 at 14:34
  • Hey again @Jai, I'm still experiencing the issue I posted - I noticed in the links people were talking about two attributes with only one working - I'm only trying to import one attribute (pack_size) and I'm still having issues - is this the same with you? – PublicDisplayName Jan 2 '17 at 23:12

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.