cancel
Showing results for 
Search instead for 
Did you mean: 

Need to display totals and shipping in header, almost there...

Need to display totals and shipping in header, almost there...

Edit: Please see the edit at the bottom of this post. Problem solved, I think. Leaving this post here in case anyone runs into a similar thing in the future.

 

I work on a few Magento stores every now and then and consider myself an intermediate level developer. Right now I'm working on expanding the mini cart that I've put in the header (it's in the sidebar by default). I've added a dropdown to it, containing the products and totals. I've got this to work, but one small thing is missing.

 

See the store here: http://www.hecospecialist.nl/

 

You'll see a block titled "Winkelwagen" in the top right - this is the mini cart. After adding a product to the cart, clicking this block shows the dropdown panel.

 

The problem: Shipping costs don't show up in the dropdown, but they do show up on the full cart page.

 

Shipping costs are calculated based on table rates, using the default country when one has not been specified. This works well on the cart page itself, and after visiting the cart page, the shipping amount suddenly does show up in the dropdown as well. I just need the shipping costs to show up at all times. I figure there must be a calculation that gets done on the cart page, that I now need to execute for all pages so that it populates the totals and shipping in my created dropdown. I just can't figure out how to get this done.

 

Additional info:

  • Using Magento CE 1.8.1.0.
  • The dropdown is made up of the "sidebar cart" template (app/design/frontend/[package]/[theme]/template/checkout/cart/sidebar.phtml) combined with the cart totals template from the cart page (checkout/cart/totals.phtml). I've added the latter to the first via local.xml, with "checkout/cart_totals" as the block type (same way it gets added to the cart page itself).
  • I'd rather not use an extension for this dropdown functionality, especially after having gotten so far on my own.

Thanks in advance to anyone who can help. If you need more info, let me know.

 

Edit: Wow, after posting this I happened upon the solution on StackExchange. Wishing now I'd have searched better beforehand - my apologies. Anyway, adding the following code to the template seems to have worked:

 

Mage::getSingleton('checkout/session')->getQuote()->setTotalsCollectedFlag(false)->collectTotals()->save();

I know I should put this in an extension and not in the template, but for now I'm just glad it works.