1

I want to add product to cart with some product already create custom option values put. So what happen current magento create new product in cart while same product different custom options or values. I need same product but values increment.

Product in already created 2 custom options and not required so Add to cart before I want to put both custom options custom values. thanks

1 Answer 1

0

You can use catalog_product_type_prepare_full_options event to add custom option before adding product into cart.

In this event you will get product object like this,

$product = $observer->getEvent()->getProduct();

and then you can set your custom condition If its satisfy then you can add your custom option

      if (someconditon == true) {
        $infoOptions[] = array(
            'label' => "YOUR_LABEL",
            'value' => "YOUR_VALUE",
        );
        $product->addCustomOption('additional_options', serialize($infoOptions));
    }
6
  • Hi but in cart page showing me error like that - Exception #0 (InvalidArgumentException): Unable to unserialize value. Commented Feb 7, 2018 at 5:19
  • yes magento2.2.2.magento.stackexchange.com/questions/194010/… - is useful? Commented Feb 7, 2018 at 5:50
  • thanks answer works but cart page two seprated product created. - nimb.ws/vFUtlK Commented Feb 7, 2018 at 6:09
  • Where is this additional information saved, in quote_item_option? Commented Apr 7, 2018 at 3:15
  • @Magento2Devloper did you find any solution?
    – sivakumar
    Commented Apr 16, 2018 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.