1

Hi I'm creating a quote manualy.

This quote contains a virtual product (so related to a configurable product).

My quote is submitted, but the options from the parent product is not added to the quote.

I've got this :

   $buyRequest = new \Magento\Framework\DataObject();
   $buyRequest->setData([
       'qty' => $qty,
       'super_attribute' => [
             58 => 328,
       ],
       'options' => [58 => 328,]
        ]);
       $quote->addProduct($product,$buyRequest);

This [58 => 328,] refers to the parent product. Is this why my product doesn't have any option when the quote is submitted ?

(58 is the custom option id and 328 is id of the selected value)

any help would be appreciated.

1
  1. Make sure that the $product refers to the configurable product.
  2. super_attribute refers to the configurable options so make sure to pass the configurable attribute id => configurable option id instead of 58 => 328.
  3. You forgot to pass the product_id.

Here is how it should look

$buyRequest = new \Magento\Framework\DataObject();
   $buyRequest->setData([
       'qty' => $qty,
       'super_attribute' => [
             <configurable attribute id> => <configurable option id>,
       ],
        'product_id' => $product->getId(),
       'options' => [58 => 328]
        ]);
    $quote->addProduct($product,$buyRequest);
  • So in my swatch I've seen this option-label-ambiance-236-item-318, configurable attribute id is 236 and option id is 318 ? PS : when the $product is the configurable product, the product is not added to quote anymore – Morgan Tartreau May 31 at 8:45
  • Yes, it was this. You're my savior and master !!! BTW for the others, for super_attribute, if the field is a multiselect, don't forget to put the values in an array ! – Morgan Tartreau May 31 at 10:13
  • @MorganTartreau - it's great to hear! Can you please kudos me by accepting my answer? – NoamN Jun 4 at 11:25
  • Yes, it's done :) – Morgan Tartreau Jun 4 at 12:08
  • Thanks so much! – NoamN Jun 4 at 12:11

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.