2

I'm using Magento EE 1.13.2 and use jQuery to add products to the cart:

var url = "/checkout/cart/add?product=" + productId + "&qty=" + qty + "&form_key=" + formKey;
$j.get(url, "", function(data,status){
    if(status == "success") {
        // Retrieve updated cart block
        $j.post('/coreoverrides/checkout_cart/minicart', "", function(data, status) {
            if(status == "success") {
            // use jQuery to update mini cart
        });
    } else {

    }
});

After the item is successfully added to the cart (which works), I attempt to retrieve the mini cart block in a controller I created:

class Derp_CoreOverrides_Checkout_CartController extends Mage_Checkout_CartController
{
    public function minicartAction()
    {
        $response = array();
        $response['status'] = 'SUCCESS';
        $response['message'] = $this->getLayout()->createBlock('checkout/cart_sidebar')->setTemplate('checkout/cart/topcart.phtml')->toHtml();
        $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
        return;
    }

But the data returned json does not have the added product in there. Am I missing something to invalidate some sort of cache or signal something that a product was added to the cart? In my development environment I have all of the cache disabled and do not use varnish, memcached, etc.

When I go directly to /coreoverrides/checkout_cart/minicart in a browser window I see the updated block.

In my local.xml I have this:

<default>
        <reference name="header">
            <block type="checkout/cart_sidebar" name="topcart_mini" as="topcart" template="checkout/cart/topcart.phtml" />
        </reference>
</default>
1
  • Unfortunatly I don't have time to dive into this, but hopefully I can give you some leads. 1) You might want to have your class extend Enterprise_Checkout_CartController not Mage_Checkout_CartController. 2) Take a look at Enterprise_PageCache_Model_Container_Minicart Maybe you can extend that, and change the block template to something that just spits out JSON, but otherwise takes advantage of cache hole punching.
    – Tyler V.
    Mar 17, 2015 at 23:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.