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>
Enterprise_Checkout_CartController
notMage_Checkout_CartController
. 2) Take a look atEnterprise_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.