Skip to content

How to create configurable products? #102

Open
@amitnayak1

Description

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

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions