I want to save the custom options that are on the product page in the custom table on click of add to cart in magento2 enter image description here here you can see the options are displaying I want to save it in the database table on add to cart click and also show it in cart page


You can use few events like


And event details:

            ['product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse()]

Or, you can use event checkout_cart_product_add_after .

At this can you can get current cart item if/ quote item id

        ['quote_item' => $result, 'product' => $product]

At Second case, the observer code is that

namespace StackExchange\MagentoAnswer\Observer;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;

class CheckoutCartProductAddAfter implements ObserverInterface

     * @param Observer $observer
     * @return void
    public function execute(Observer $observer)
        $quoteItem = $observer->getEvent()->getData('quote_item');
        $product = $observer->getEvent()->getData('product');
        $requestParams = $quoteItem->getBuyRequest();
        if ($requestParams instanceof \Magento\Framework\DataObject  && is_object($requestParams)) {
            // buyRequestArray is inddex
            $buyRequestArray = $requestParams->toArray();
| improve this answer | |
  • Hii amit can you please provide me whole code with folder struvturr i am new to magento so does now more about ut – Ashish Ramchandani Mar 22 '19 at 7:39
  • after doing this add to cart button is not workin g – Ashish Ramchandani Mar 25 '19 at 12:50
  • It means addtocart post action is not hitting or you don't able to add to cart what is the issue? – Amit Bera Mar 25 '19 at 13:21
  • i don't able to add to cart – Ashish Ramchandani Mar 25 '19 at 13:29
  • its means add to cart button is not clicking? – Amit Bera Mar 25 '19 at 13:30

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.