I have an observer checkout_cart_add_product_complete
which gives me a product. But not the cart. I want to add data to the cart based on the product.
My observer definition.
<?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_lease_controller_front_send_response_before" instance="Test\Lease\Observer\AddtoCart"/>
</event>
</config>
The class:
<?php
namespace Test\Lease\Observer;
use \Magento\Framework\Event\Observer;
use \Magento\Framework\Event\ObserverInterface;
class AddtoCart implements ObserverInterface {
public function execute(Observer $observer) {
/** @var \Magento\Catalog\Model\Product\Interceptor $product */
$product = $observer->getProduct();
// need cart here
}
}
I know the way to do this is dependency injection but I just can't figure it out.
I've red a few things but can't figure it out.
Can somebody help me get started?