2

My fellow devs!

I am attempting to change the standard "add to cart" functionality to include AJAX. I've taken on board advice that overloading addAction method in the Checkout/CartController.php methods is bad so I am now trying to do it via the events system.

I need to return a JSON response to my AJAX request. The response must have things like grand total, num items etc which I see I can get from the event checkout_cart_save_after (Ln 464 - Checkout/Model/Cart.php) but I cannot access the response object as this event is executed within Model. Event checkout_cart_add_product_complete (Ln 230 - Checkout/controllers/CartController.php) does appear to have access to this so as I see it the logical thing to do would be to share the data between my event handlers.

I've only been using Magento for a few weeks now so does this logic sound correct and can I share this data?

3
  • you can share data using Register Design patter of Magento
    – Keyul Shah
    Sep 23, 2014 at 5:53
  • @KeyulShah could you please elaborate with an example. Sep 23, 2014 at 5:58
  • yes sure ...........
    – Keyul Shah
    Sep 23, 2014 at 5:58

1 Answer 1

2

I will give you example of Register Design Pattern In Magento.

All the singletons are stored in the internal registry: a global scoped container for storing data. It is not only for internal use.

Set data from Registry via Register Design Pattern.

Mage::register($key, $value);

Get data from Registry via Register Design Pattern.

Mage::registry($key) ;

remove data from Registry via Register Design Pattern.

Mage::unregister($key);

The registry is often used for transferring data between scopes when they cannot be passed on, otherwise.

1
  • you are welcome :)
    – Keyul Shah
    Sep 23, 2014 at 6:07

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.