1

I'm working with the Aheadworks Mobile theme and experience a strange issue. If I add a product to cart and open the cart (without page refresh) I just see an empty cart. Only after I refresh the page I see the just added product but it never updates the product via Ajax. However, I tracked down the issue to line #55 in AW/Mobile2/controllers/CartController.php

$cartBlock = $layout->getBlock('checkout.cart');

This is empty! But I'm stuck here and don't know how to debug this further. Any ideas?

Please find complete function below:

require_once 'Mage/Checkout/controllers/CartController.php';
class AW_Mobile2_CartController extends Mage_Checkout_CartController
{
    protected function _ajaxResponse($result = array())
    {
    $this->getResponse()->setBody(Zend_Json::encode($result));
    return;
}

public function addAction()
{
    Mage::register('_no_redirect_flag', true, true);
    parent::addAction();
    $response = array(
        'top_cart_qty' => (int)Mage::getSingleton('checkout/cart')->getSummaryQty(),
        'message_box'  => '',
        'cart'         => ''
    );
    $layout = $this->getLayout();
    $messageBlock = $layout->createBlock('core/messages');
    $messageBlock->addMessages(Mage::getSingleton('checkout/session')->getMessages(true));
    $response['message_box'] = $messageBlock->getGroupedHtml();
    try {
        $update = $layout->getUpdate();
        $update->load('default');
        $layout->generateXml();
        $layout->generateBlocks();
        $cartBlock = $layout->getBlock('checkout.cart');
        if ($cartBlock) {
            $response['cart'] = $cartBlock->toHtml();
        }
    } catch (Exception $e) {
        Mage::logException($e);
    }
    Mage::log(print_r($response,true),true,"addtocart.log");
    $this->_ajaxResponse($response);
}
...

The log file says

2015-12-18T12:28:27+00:00 ALERT (1): Array
(
    [top_cart_qty] => 1
    [message_box] => <ul class="messages"><li class="success-msg"><ul><li><span>Red Taiko Shirt was added to your shopping cart.</span></li></ul></li></ul>
    [cart] => 
)

Any help is much appreciated. Thanks.

2

You should have a look add your modules layout-handles.

The block checkout.cart isn't defined under the default handle anywhere:

It is defined like that checkout_cart_index handle in app/design/frontend/base/default/layout/checkout.xml:

<checkout_cart_index translate="label">
    <reference name="content">
        <block type="checkout/cart" name="checkout.cart">
            <action method="setCartTemplate"><value>checkout/cart.phtml</value></action>
            <action method="setEmptyTemplate"><value>checkout/cart/noItems.phtml</value></action>
            <action method="chooseTemplate"/>
            <action method="addItemRender"><type>simple</type><block>checkout/cart_item_renderer</block><template>checkout/cart/item/default.phtml</template></action>
            <action method="addItemRender"><type>grouped</type><block>checkout/cart_item_renderer_grouped</block><template>checkout/cart/item/default.phtml</template></action>
            <action method="addItemRender"><type>configurable</type><block>checkout/cart_item_renderer_configurable</block><template>checkout/cart/item/default.phtml</template></action>

            <block type="core/text_list" name="checkout.cart.top_methods" as="top_methods" translate="label">
                <label>Payment Methods Before Checkout Button</label>
                <block type="checkout/onepage_link" name="checkout.cart.methods.onepage" template="checkout/onepage/link.phtml"/>
            </block>

            <block type="page/html_wrapper" name="checkout.cart.form.before" as="form_before" translate="label">
                <label>Shopping Cart Form Before</label>
            </block>

            <block type="core/text_list" name="checkout.cart.methods" as="methods" translate="label">
                <label>Payment Methods After Checkout Button</label>
                <block type="checkout/onepage_link" name="checkout.cart.methods.onepage" template="checkout/onepage/link.phtml"/>
                <block type="checkout/multishipping_link" name="checkout.cart.methods.multishipping" template="checkout/multishipping/link.phtml"/>
            </block>

            <block type="checkout/cart_coupon" name="checkout.cart.coupon" as="coupon" template="checkout/cart/coupon.phtml"/>
            <block type="checkout/cart_shipping" name="checkout.cart.shipping" as="shipping" template="checkout/cart/shipping.phtml"/>
            <block type="checkout/cart_crosssell" name="checkout.cart.crosssell" as="crosssell" template="checkout/cart/crosssell.phtml"/>

            <block type="checkout/cart_totals" name="checkout.cart.totals" as="totals" template="checkout/cart/totals.phtml"/>
        </block>
    </reference>
...
</checkout_cart_index>

So you have to make sure, that you define the cart block in your modules layout file in the handle aw_mobile2_cart_add-handle or under default-handle.

| improve this answer | |
  • 1
    By the way: I think one of the nicest way of Debugging Magento is xdebug (xdebug.org). It is relatively easy to setup and after installation you can just put a breakpoint and see whats up in the code on this point of request processing. I recently wrote an article for the installation and usage of xdebug under Linux and PHPStorm. It can be found here: ask-sheldon.com/php-xdebug – Marcel Lange Dec 18 '15 at 13:41
2

checkout.cart is block which does not exits at checkout_cart_add handler.That reason you does not get it content. As per as , default magento this block is element of checkout cart page

For your case,you need call this block at checkout_cart_add handler by adding code layout file(local.xml or checkout.xml) .

<checkout_cart_add>
        <reference name="content">
            <block type="checkout/cart" name="checkout.cart">
                <action method="setCartTemplate"><value>checkout/cart.phtml</value></action>
                <action method="setEmptyTemplate"><value>checkout/cart/noItems.phtml</value></action>
                <action method="chooseTemplate"/>
                <action method="addItemRender"><type>simple</type><block>checkout/cart_item_renderer</block><template>checkout/cart/item/default.phtml</template></action>
                <action method="addItemRender"><type>grouped</type><block>checkout/cart_item_renderer_grouped</block><template>checkout/cart/item/default.phtml</template></action>
                <action method="addItemRender"><type>configurable</type><block>checkout/cart_item_renderer_configurable</block><template>checkout/cart/item/default.phtml</template></action>

                <block type="core/text_list" name="checkout.cart.top_methods" as="top_methods" translate="label">
                    <label>Payment Methods Before Checkout Button</label>
                    <block type="checkout/onepage_link" name="checkout.cart.methods.onepage" template="checkout/onepage/link.phtml"/>
                </block>

                <block type="page/html_wrapper" name="checkout.cart.form.before" as="form_before" translate="label">
                    <label>Shopping Cart Form Before</label>
                </block>

                <block type="core/text_list" name="checkout.cart.methods" as="methods" translate="label">
                    <label>Payment Methods After Checkout Button</label>
                    <block type="checkout/onepage_link" name="checkout.cart.methods.onepage" template="checkout/onepage/link.phtml"/>
                    <block type="checkout/multishipping_link" name="checkout.cart.methods.multishipping" template="checkout/multishipping/link.phtml"/>
                </block>

                <block type="checkout/cart_coupon" name="checkout.cart.coupon" as="coupon" template="checkout/cart/coupon.phtml"/>
                <block type="checkout/cart_shipping" name="checkout.cart.shipping" as="shipping" template="checkout/cart/shipping.phtml"/>
                <block type="checkout/cart_crosssell" name="checkout.cart.crosssell" as="crosssell" template="checkout/cart/crosssell.phtml"/>

                <block type="checkout/cart_totals" name="checkout.cart.totals" as="totals" template="checkout/cart/totals.phtml"/>
            </block>
        </reference>

    </checkout_cart_add>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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