2

I have the same problem as described here: Mini-Cart displaying Parent Product Image instead of Product Image. However, I cannot get the accepted solution to work. The problem is that when I add a product to my cart via AJAX the parent product image is shown. Only when I refresh the page is the correct simple product image shown. What am I missing?!?


Layout

app/design/frontend/mymodule/mytheme/layout/mymodule_ajax.xml

<?xml version="1.0"?>
<layout>
    <ajax_checkout_minicart>
        <block type="checkout/cart_sidebar" name="root" output="toHtml" template="checkout/minicart.phtml">
            <action method="addItemRender"><type>simple</type><block>checkout/cart_item_renderer</block><template>checkout/minicart/item/default.phtml</template></action>
            <action method="addItemRender"><type>grouped</type><block>checkout/cart_item_renderer_grouped</block><template>checkout/minicart/item/default.phtml</template></action>
            <action method="addItemRender"><type>configurable</type><block>checkout/cart_item_renderer_configurable</block><template>checkout/minicart/item/default.phtml</template></action>
        </block>
    </ajax_checkout_minicart>
</layout>

Controller

app/code/local/MyModule/Ajax/controllers/CheckoutController.php

class MyModule_Ajax_CheckoutController extends Mage_Core_Controller_Front_Action
{
    public function miniCartAction() {

        $layout = $this->getLayout();
        $update = $layout->getUpdate();
        $update->load('ajax_checkout_minicart'); //load the layout
        $layout->generateXml();
        $layout->generateBlocks();
        $html = $layout->getOutput();
        return $html;
    }
}

Templates

app/design/frontend/mymodule/mytheme/template/checkout/minicart.phtml

<?
$_items = $this->getRecentItems();
$_cartItemsCount = $this->getSummaryCount();
?>
<ul id="minicart">    
    <? foreach ($_items as $item) : ?>
        <?= $this->getItemHtml($item) ?>
    <? endforeach; ?>    
</ul>

app/design/frontend/mymodule/mytheme/template/checkout/minicart/item/default.phtml

<?
$_templateHelper = Mage::helper('templates');
$_item = $this->getItem();
?>
<li>
    <a href="<?= $this->getProductUrl() ?>">
        <img src="<?= $this->getProductThumbnail()->resize(100); ?>">           
    </a>
</li>

1 Answer 1

2

Refresh your session, after adding product to cart. This is dirty solution, but in my case it works.

$session = Mage::getSingleton('checkout/session');
$quoteId = $session->getQuote()->getId();
$session->clear();
$session->setQuoteId($quoteId);
1
  • Can confirm this hack is working on Magento 1.9.3.9
    – puntable
    Aug 17, 2018 at 6:56

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.