I have a custom_field on the product details page( Like a hidden field ). Which is not a product attribute. I can get this field value using checkout_cart_product_add_after event using an observer like this.

<event name="checkout_cart_product_add_after">
    <observer name="CartProductAddAfter" instance="Ayakil\ProductsSubscription\Observer\Checkout\CartProductAddAfter"/>

Observer file

class CartProductAddAfter implements \Magento\Framework\Event\ObserverInterface
public function __construct(
    \Psr\Log\LoggerInterface $logger,
    \Magento\Framework\App\RequestInterface $request
) {
    $this->_logger = $logger;
    $this->_request = $request;
}public function execute(
    \Magento\Framework\Event\Observer $observer
) {               
    $postData = $this->_request->getParams();       
    $frequencies = $postData['frequencies'];


My question is I have a custom field( subcribe_frequency ) in quote_item, How can I set this $frequencies quote items after adding the products to the cart?

Please someone help me in this?

1 Answer 1


Simply use the following code:

public function execute(
    \Magento\Framework\Event\Observer $observer
) {

    $postData = $this->_request->getParams();
    $frequencies = $postData['frequencies'];
    $item = $observer->getQuoteItem();
  • can i use checkout_cart_product_add_after for $observer->getQuoteItem() ?
    – Mujahidh
    Nov 22, 2020 at 11:12
  • Yes, this example for checkout_cart_product_add_after event
    – Sohel Rana
    Nov 22, 2020 at 11:38

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.