Recent Topics

How to insert configurable product programmatically?



  • I would like to insert product and its attribute and variation by code. I am actually creating an custom API through which I can migrate products from my other source to bagisto. So I need some code reference to insert product variations into DB.



  • Hi @ttm-sanjay,

    For configurable products, you just need additional data,

    For e.g.,

    For creating product,

    $request = [
        "type" => "simple",
        "attribute_family_id" => "1",
        "sku" => "90"
    ];
    

    On second phase you just edit the product,

    $request = [
      "channel" => "default",
      "locale" => "en",
      "sku" => "90",
      "name" => "Product 1",
      "url_key" => "product-1",
      "tax_category_id" => "",
      "new" => "1",
      "featured" => "1",
      "visible_individually" => "1",
      "status" => "1",
      "color" => "1",
      "size" => "6",
      "brand" => "10",
      "short_description" => "<p>Lorem Ipsum</p>",
      "description" => "<p>Lorem Ipsum</p>",
      "meta_title" => "Lorem Ipsum",
      "meta_keywords" => "Lorem Ipsum",
      "meta_description" => "Lorem Ipsum",
      "price" => "100.0000",
      "cost" => "",
      "special_price" => "",
      "special_price_from" => "",
      "special_price_to" => "",
      "width" => "",
      "height" => "",
      "depth" => "",
      "weight" => "90",
      "inventories" => [
        1 => "100"
      ],
      "images" => [
        389 => ""
      ],
      "categories" => [
        0 => "1"
      ],
      "channels" => [
        0 => "1"
      ]
    ];
    

    For programmatically I suggest you check this file method,
    packages/Webkul/Product/src/Http/Controllers/ProductController.php update() method.


Log in to reply