Magento – Add Cross Sells to cart sidebar located in header

blockscross-sellslocal.xmlmagento-1.9template

I have moved my cart sidebar to the header using the code below in my local xml. I am now struggling to display crosssells inside this mini cart and am seeking guidance (they display fine on the actual cart page, and I have re-indexed several times).

<default>
    <reference name="left"><action method="unsetChild"><name>cart_sidebar</name></action></reference>
    <reference name="right"><action method="unsetChild"><name>cart_sidebar</name></action></reference>
    <reference name="header">               
        <block type="checkout/cart_sidebar" name="cart_sidebar" as="topcart" template="checkout/cart/topcart.phtml"/>
        <block type="checkout/cart_crosssell" name="checkout.cart.crosssell" as="crosssell" template="checkout/cart/crosssell.phtml"/>
    </reference>
</default>

Products are added to this top cart using ajax (however crosssells don't display in mini cart at any time). I have tried to include the cross sells within my topcart.phtml file using

<?php echo $this->getChildHtml('crosssell') ?>

I have also tried the following in my local.xml to no avail

<checkout_cart_index>
        <reference name="header">
                <block type="checkout/cart_crosssell" name="checkout.cart.crosssell" as="crosssell" template="checkout/cart/crosssell.phtml"/>
     </reference>
    </checkout_cart_index>

And have also experimented using a crosssellhead.phtml file in my themes checkout cart template folder.

Thanks

Best Answer

I just tried this way and works for me:

 <?php echo $this->getLayout()->createBlock('checkout/cart_crosssell')->setTemplate('checkout/cart/crosssell.phtml')->toHtml();?>

Add this code in header.phtml or other file where you want to show the crossells

<div class="top-panel mini-cart pp-shopping-block" data-role="pp-shopping">

      // Calls the mini cart
      <?php echo $this->getLayout()->createBlock('checkout/cart_sidebar')->setTemplate('checkout/cart/sidebar.phtml')->toHtml();?>

      // Calls Cross-Sells
      <?php echo $this->getLayout()->createBlock('checkout/cart_crosssell')->setTemplate('checkout/cart/crosssell.phtml')->toHtml();?>

</div>
Related Topic