For call observer checkout_cart_add_product_complete you need to create a module and create event.xml file in frontend area
etc/frontend/event.xml
<?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"/>
</event>
</config>
2) Now call Cartitems in path Test\Callobserver\Observer\
<?php
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.
$item1->getId();