Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create configurable products? #102

Open
amitnayak1 opened this issue Jan 2, 2020 · 2 comments
Open

How to create configurable products? #102

amitnayak1 opened this issue Jan 2, 2020 · 2 comments

Comments

@amitnayak1
Copy link

amitnayak1 commented Jan 2, 2020

I am trying to create configurable products using below code and products array which is given in the demo module.

<?php
use \Magento\Framework\App\Bootstrap;
include('app/bootstrap.php');
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$importModel = $objectManager->create('FireGento\FastSimpleImport\Model\Importer');

$products = [];
$products [] = [
    'sku' => "SIMPLE-BLUE-SMALL",
    'attribute_set_code' => 'Default',
    'product_type' => 'simple',
    'product_websites' => 'base',
    'name' => 'FireGento Simple Product Blue,Size Small',
    'price' => '1.0000',
    'color' => 'blue',
    'size' => 'S'
];
$products [] = [
    'sku' => "SIMPLE-RED-MIDDLE",
    'attribute_set_code' => 'Default',
    'product_type' => 'simple',
    'product_websites' => 'base',
    'name' => 'FireGento Simple Product Red,Size Middle',
    'price' => '1.0000',
    'color' => 'red',
    'size' => 'M'
];

$products [] = [
    'sku' => 'CONFIG-Product',
    'attribute_set_code' => 'Default',
    'product_type' => 'configurable',
    'product_websites' => 'base',
    'name' => 'FireGento Test Product Configurable',
    'price' => '10.000',
    'configurable_variation_labels' => 'Color',
    'configurable_variations' => [
        [
            'sku' => 'SIMPLE-BLUE-SMALL',
            'color' => 'blue',
            'size' => 'S'],
        [
            'sku' => 'SIMPLE-RED-MIDDLE',
            'color' => 'red',
            'size' => 'M'],
    ]

];
$importModel->processImport($products);
print_r($importModel->getLogTrace());
print_r($importModel->getErrorMessages());

It is giving the error

PHP Warning: explode() expects parameter 2 to be string, array given in /var/www/html/magento23/vendor/magento/module-configurable-import-export/Model/Import/Product/Type/Configurable.php on line 569

At line 569, below code is present.
$variations = explode(ImportProduct::PSEUDO_MULTI_LINE_SEPARATOR, $rowData['configurable_variations']);

How to create a configurable product? Magento version is 2.3.1

@erfanimani
Copy link

Have you tried writing it as a string instead of an array?

i.e. configurable_variations => 'sku=SIMPLE-BLUE-SMALL,color=blue,size=S\|sku=SIMPLE-RED-MIDDLE,color=red,size=M'

@norgeindian
Copy link
Contributor

@amitnayak1 , you surely found a solution in the meantime, but maybe worth writing down the solution for others anyway.
This change from an array to the string, @erfanimani mentioned, can actually automatically be done, by including the NestedArrayAdapterFactory in the following way in your custom di.xml:

    <type name="FireGento\FastSimpleImport\Model\Importer">
        <arguments>
            <argument name="importAdapterFactory" xsi:type="object">FireGento\FastSimpleImport\Model\Adapters\NestedArrayAdapterFactory</argument>
        </arguments>
    </type>

Then, you can process the configurable variations like you did and they will be correctly transformed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants