I tried,

 $items = $item->getQuote()->getAllItems();

 foreach($items as $item1)
      $productId = $item1->getProductId();
      $itemId = $item1->getItemId();

I am getting blank value.

Can anyone tell me how to call checkout_cart_add_product_complete event in observer ?


1 Answer 1


For call observer checkout_cart_add_product_complete you need to create a module and create event.xml file in frontend area


<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="checkout_cart_add_product_complete">
         <observer name="test_callobserver" instance="Test\Callobserver\Observer\Cartitems"/>

2) Now call Cartitems in path Test\Callobserver\Observer\

namespace Test\Callobserver\Observer;

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

use \Magento\Checkout\Model\Session as CheckoutSession;

class Cartitems implements ObserverInterface {

    /** @var CheckoutSession */
    protected $checkoutSession;

     * @param CheckoutSession $checkoutSession
    public function __construct(CheckoutSession $checkoutSession) {
        $this->checkoutSession = $checkoutSession;

    public function execute(Observer $observer) {
        /** @var \Magento\Catalog\Model\Product\Interceptor $product */
        $product = $observer->getProduct();

        /** @var \Magento\Quote\Model\Quote  */
        $quote = $this->checkoutSession->getQuote(); //here you will get quote data

This code help you.

  • How to update custom attribute in given quote item table
    – jassi
    Sep 12, 2017 at 5:57
  • 1
    First You need to find $quoteItem from above code then simply set custom attribute with code $quoteItem->setCustomAttribute($product->getCustomAttribute());
    – akgola
    Sep 12, 2017 at 7: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.