Refreshing Add To Cart Page When Attaching an Observer/Plugin
Can anyone help me troubleshoot an issue with a Magento plugin? I'm trying to run a function after an item is added to cart, and I've added a plugin for the type Magento\Checkout\Model\Cart in my di.xml file. In the plugin file, I've created a function named afterAddToCart() that should run after the addToCart() function, but when I enable the plugin and try to add an item to the cart, the page refreshes and the plugin doesn't work.
I've also tried using an observer and have attempted to observe the events checkout_cart_add_product_complete, checkout_cart_product_add_after, checkout_cart_save_before, and checkout_cart_save_after, but each time I add an item to the cart, the page refreshes and the observer doesn't work either. Can anyone help me figure out what might be causing this issue?
I am using the latest version of Magento
di.xml file
<config xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd'>
<type name='Magento\Checkout\Model\Cart'>
<plugin name='Adithya_Test_Plugin' type='Adithya\Test\Plugin\CartPlugin' sortOrder='10' disabled='false' />
</type>
</config>
events.xml file
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="checkout_cart_save_before">
<observer name="AdithyaProductData" instance="Adithya\Test\Observer\Product\ProductObserver" disabled="false"/>
</event>
</config>
