Skip to main content
Participant
March 31, 2023
Answered

Refreshing Add To Cart Page When Attaching an Observer/Plugin

  • March 31, 2023
  • 1 reply
  • 1247 views

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>

 

This topic has been closed for replies.
Correct answer Kevin Stohlmeyer

Hi @Jinali2917196558mn you can find support directly on the Magento forums. This forum is for Creative Cloud users.

https://community.magento.com/

 

1 reply

Ashish_Harrison
Adobe Employee
Adobe Employee
March 31, 2023
Participant
April 2, 2023

Greetings, I appreciate your response. I followed your instructions, but unfortunately, I am unable to locate the support ticket option. Is it possible that this feature is only available for paid members?

 

 

Kevin Stohlmeyer
Community Expert
Kevin StohlmeyerCommunity ExpertCorrect answer
Community Expert
April 3, 2023

Hi @Jinali2917196558mn you can find support directly on the Magento forums. This forum is for Creative Cloud users.

https://community.magento.com/