0

I am getting issue with checkout_cart_product_add_after event. Actually I have created one method with this event which adding dynamic product option during product add. Below is by code:

public function execute(\Magento\Framework\Event\Observer $observer)
{
    $item = $observer->getEvent()->getData('quote_item');
    $data = $this->_request->getPost();

    if(isset($data['mobile'])){
        $additionalOptions = [];
        $additionalOptions[] = array(
            'label' => "Mobile",
            'value' => $data['mobile'],
        );
        $item->addOption(
            array(
                 'code'  => 'additional_options',
                 'value' => $this->_serialize->serialize($additionalOptions),
            )
        );
    }
}

Its working fine when adding product to cart in browsers but the issue is its not working when adding product to cart through rest API.

Can anyone have the same problem? Whats the solution for this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.