0

I'm creating quote and order programmaticaly.

I can't figure out why options product are not added to my order / quote.

See :

$superAttr = $item["super_attribute"];
if(!empty($superAttr)){
    $opts = [];
    foreach ($superAttr as $va) {
        foreach ($va as $k => $v) {
            $opts[$k] = $v;
        }
    }
    $temp = array(
        "product_id" => $product->getId(),
        "qty" => $qty,
        "super_attribute" => $opts,
    );
    $buyRequest = new \Magento\Framework\DataObject($temp);
    $this->nice($buyRequest);
    $quote->addProduct($product,$buyRequest);
}else{
    $quote->addProduct(
        $product,
        $qty);
}

And my $buyRequest :

Magento\Framework\DataObject Object(
    [_data:protected] => Array(
        [product_id] => 1739
        [qty] => 1
        [super_attribute] => Array( //keys = id of the options
            [56] => 325 //multiselect id option value
            [58] => 339 // dropdown id option value
            [57] => 334 //dropodow id option value
            [61] => Semaine 20 //textfield
        )
    )
)
0

I think you are missing 'selected_configurable_option' parameter in your $buyRequest, this parameter should include product_id of the simple product which match all selected configurable options

You can check here a piece of working code for programmatically add to cart configurable products

  • It seems to be for the cart, not for the quote. Will this works for the quote ? (i'm trying this right now) – Morgan Tartreau May 20 at 15:18
  • I suppose it should work, as the result of adding a product to cart will result the same in quote assigned to cart – Raul Sanchez May 20 at 16:05
  • Thanks but can't make it works – Morgan Tartreau May 21 at 6:45
  • Are you sure all that attributes inside 'super_attribute' are really attributes used for configurable products? I don't think text attributes are allowed for that (nor multiselect) – Raul Sanchez May 21 at 7:26
  • Yes, I've dumped the result of a query that fetch the options data – Morgan Tartreau May 21 at 7:51

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.