Magento Forum

   
Show quantity, total price and shipping price in my header.phtml? 
 
marcfalk
Sr. Member
 
Total Posts:  87
Joined:  2008-11-22
 

Hey guys,

Thanks for a great forum, I’ve found a lot of great answers in here.
Questions I cannot get an answer for are as following:

How do I show the quantity of a cart in my header?
How do I show the total price of a cart in my header?
How do I show the total shipping price in my header?

I’ve looked for answers in:
\app\blank\default\template\checkout\cart

But I can’t figure out why I get an error, when I try to implement php from the cart-directory into header.phtml.

Thanks in advance!

 
Magento Community Magento Community
Magento Community
Magento Community
 
marcfalk
Sr. Member
 
Total Posts:  87
Joined:  2008-11-22
 

Does anyone have a clue?

 
Magento Community Magento Community
Magento Community
Magento Community
 
marcfalk
Sr. Member
 
Total Posts:  87
Joined:  2008-11-22
 

Is this impossible?

 
Magento Community Magento Community
Magento Community
Magento Community
 
marcfalk
Sr. Member
 
Total Posts:  87
Joined:  2008-11-22
 

Does it make any difference if I want to show it elsewhere?

 
Magento Community Magento Community
Magento Community
Magento Community
 
marcfalk
Sr. Member
 
Total Posts:  87
Joined:  2008-11-22
 

Weehuu, finally I figured something out…

How do I show the quantity of a cart in my header?

Add the following code to app/design/frontend/[theme]/default/template/page/html/header.phtml:

<? if(Mage::getSingleton('checkout/session')->getQuote()->getItemsSummaryQty() > 0{ ?>
<?
=__(Mage::getSingleton('checkout/session')->getQuote()->getItemsSummaryQty())?> 
<? } 
else { ?>

<? } ?>

How do I show the total price of a cart in my header?

I have only found a solution for the subtotal, and to show this, you need to add the following to app/design/frontend/[theme]/default/template/page/html/header.phtml (or wherever you need it):

<? if(Mage::getSingleton('checkout/session')->getQuote()->getSubtotal() > 0{ ?>
<?
=__(number_format(Mage::getSingleton('checkout/session')->getQuote()->getSubtotal(),2))?> 
<? } 
else { ?>

<? } ?>

How do I show the total shipping price in my header?

Still trying to figure this out…

 
Magento Community Magento Community
Magento Community
Magento Community
 
mrjohnnycake
Member
 
Avatar
Total Posts:  35
Joined:  2007-10-28
Arcata, CA. USA
 

Here’s what I came up with:

http://www.magentocommerce.com/boards/viewthread/32320/

Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
ben_marks
Guru
 
Avatar
Total Posts:  449
Joined:  2008-10-09
Charleston, SC
 

The gist of what you are trying to do is provide info from the cart sidebar in the header.  mrjohnnycake’s link is a good step in the right direction.  I just want to point out that when you know of a block that has what you want, you can just create a new block to use of that same block type (in this case type="checkout/cart_sidebar” which corresponds to checkout/cart/sidebar.phtml) , and make it available inside the block in which you wish to display it (the header block in your case).  I recommend copying the template file and naming it cart_widget.phtml.

HTH

 
Magento Community Magento Community
Magento Community
Magento Community
 
nplanet
Member
 
Avatar
Total Posts:  31
Joined:  2008-11-19
 

@ marcfalk

If I follow your tips to add Quantity and Sub Total to Header Magento Crashes. Here is the Crash Dump:

Warningarray_key_exists() [function.array-key-exists]The first argument should be either a string or an integer  in C:\xampp\htdocs\edmegastore\app\code\core\Mage\Core\Model\Translate.php on line 546
Trace
:
#0 C:\xampp\htdocs\edmegastore\app\code\core\Mage\Core\Model\Translate.php(546): mageCoreErrorHandler(2, 'array_key_exist...', 'C:\xampp\htdocs...', 546, Array)
#1 C:\xampp\htdocs\edmegastore\app\code\core\Mage\Core\Model\Translate.php(387): Mage_Core_Model_Translate->_getTranslatedString(207, Array)
#2 C:\xampp\htdocs\edmegastore\app\code\core\Mage\Core\functions.php(106): Mage_Core_Model_Translate->translate(207, 'frontend/defaul...')
#3 C:\xampp\htdocs\edmegastore\app\design\frontend\Edmegastore\Edmegastore\template\page\html\header.phtml(58): __()
#4 C:\xampp\htdocs\edmegastore\app\code\core\Mage\Core\Block\Template.php(144): include('C:\xampp\htdocs...')
#5 C:\xampp\htdocs\edmegastore\app\code\core\Mage\Core\Block\Template.php(176): Mage_Core_Block_Template->fetchView(Array)
#6 C:\xampp\htdocs\edmegastore\app\code\core\Mage\Core\Block\Template.php(193): Mage_Core_Block_Template->renderView(207)
#7 C:\xampp\htdocs\edmegastore\app\code\core\Mage\Core\Block\Abstract.php(643): Mage_Core_Block_Template->_toHtml('frontend\Edmega...')
#8 C:\xampp\htdocs\edmegastore\app\code\core\Mage\Core\Block\Abstract.php(503): Mage_Core_Block_Abstract->toHtml()
#9 C:\xampp\htdocs\edmegastore\app\code\core\Mage\Core\Block\Abstract.php(454): Mage_Core_Block_Abstract->_getChildHtml()
#10 C:\xampp\htdocs\edmegastore\app\design\frontend\Edmegastore\Edmegastore\template\page\2columns-left.phtml(42): Mage_Core_Block_Abstract->getChildHtml()
#11 C:\xampp\htdocs\edmegastore\app\code\core\Mage\Core\Block\Template.php(144): include('C:\xampp\htdocs...')
#12 C:\xampp\htdocs\edmegastore\app\code\core\Mage\Core\Block\Template.php(176): Mage_Core_Block_Template->fetchView('header', true)
#13 C:\xampp\htdocs\edmegastore\app\code\core\Mage\Core\Block\Template.php(193): Mage_Core_Block_Template->renderView('header')
#14 C:\xampp\htdocs\edmegastore\app\code\core\Mage\Core\Block\Abstract.php(643): Mage_Core_Block_Template->_toHtml('frontend\Edmega...')
#15 C:\xampp\htdocs\edmegastore\app\code\core\Mage\Core\Model\Layout.php(525): Mage_Core_Block_Abstract->toHtml()
#16 C:\xampp\htdocs\edmegastore\app\code\core\Mage\Core\Controller\Varien\Action.php(326): Mage_Core_Model_Layout->getOutput()
#17 C:\xampp\htdocs\edmegastore\app\code\core\Mage\Cms\Helper\Page.php(92): Mage_Core_Controller_Varien_Action->renderLayout()
#18 C:\xampp\htdocs\edmegastore\app\code\core\Mage\Cms\controllers\IndexController.php(32): Mage_Cms_Helper_Page->renderPage()
#19 C:\xampp\htdocs\edmegastore\app\code\core\Mage\Core\Controller\Varien\Action.php(349): Mage_Cms_IndexController->indexAction()
#20 C:\xampp\htdocs\edmegastore\app\code\core\Mage\Core\Controller\Varien\Router\Standard.php(163): Mage_Core_Controller_Varien_Action->dispatch(Object(Mage_Cms_IndexController), 'Edmegastore')
#21 C:\xampp\htdocs\edmegastore\app\code\core\Mage\Core\Controller\Varien\Front.php(174): Mage_Core_Controller_Varien_Router_Standard->match()
#22 C:\xampp\htdocs\edmegastore\app\Mage.php(447): Mage_Core_Controller_Varien_Front->dispatch('index')
#23 C:\xampp\htdocs\edmegastore\index.php(52): Mage::run(Object(Mage_Core_Controller_Request_Http))
#24 {main}
What must be the problem? Can you please help me solve this.

 
Magento Community Magento Community
Magento Community
Magento Community
 
marye27
Jr. Member
 
Total Posts:  9
Joined:  2009-08-07
 

I search hi and low before I found a solution and then had to do a lot of tweeking before it worked but here is what I did:

1.  Add an action method to get the subtotal in the checkout.xml file (found in app/design/frontend/default/[YOUR THEME]/layout)

Look for
<reference name="top.links">
<block type="checkout/links" name="checkout_cart_link">
<action method="addCartLink"></action>
<action method="addCheckoutLink"></action>
</block>

And change to

<reference name="top.links">
<block type="checkout/links" name="checkout_cart_link">
<action method="addCartLink"></action>
<action method="ADDSUBTOTALCODE"></action>
<action method="addCheckoutLink"></action>
</block>

Notice all I did was to add
<action method="ADDSUBTOTALCODE"></action>

2.  Open links.php found in app/code/core/Mage/Checkout/Block) and Add a function to get the cart subtotal

public function ADDSUBTOTALCODE ()
{
if ($parentBlock = $this->getParentBlock())
{
$amount = __(number_format(Mage::getSingleton(’checkout/session’)->getQuote()->getSubtotal(),2));
$text = __(’Amount $%s’, $amount);
$parentBlock->addLink($text, ‘checkout/cart’, $text, true, array(), 50,null,’class="top-link-cart"’);
}

return $this;

}

3.  Save files and upload them back to the server.

**Please ntoe to first make a backup of all the files being updated before changes are made as core files are being changed**

 
Magento Community Magento Community
Magento Community
Magento Community
 
Paragon
Jr. Member
 
Total Posts:  5
Joined:  2009-09-23
 

The solution above by ‘marye27’ works with Magento CE 1.4.0.1, however, the currency symbol is shown as $

Currency symbols everywhere else in Magento show as £, and Locales are set accordingly.

Does anyone have any ideas how the currency symbol can be changed? Any help greatly appreciated.

 
Magento Community Magento Community
Magento Community
Magento Community
 
nabler
Sr. Member
 
Total Posts:  80
Joined:  2010-07-27
 

you rock this work pretty fine in mine.....

 
Magento Community Magento Community
Magento Community
Magento Community
 
Cawe
Sr. Member
 
Total Posts:  109
Joined:  2009-09-11
 
marye27 - 15 September 2009 10:35 AM

I search hi and low before I found a solution and then had to do a lot of tweeking before it worked but here is what I did:

1.  Add an action method to get the subtotal in the checkout.xml file (found in app/design/frontend/default/[YOUR THEME]/layout)

Look for
<reference name="top.links">
<block type="checkout/links" name="checkout_cart_link">
<action method="addCartLink"></action>
<action method="addCheckoutLink"></action>
</block>

And change to

<reference name="top.links">
<block type="checkout/links" name="checkout_cart_link">
<action method="addCartLink"></action>
<action method="ADDSUBTOTALCODE"></action>
<action method="addCheckoutLink"></action>
</block>

Notice all I did was to add
<action method="ADDSUBTOTALCODE"></action>


2.  Open links.php found in app/code/core/Mage/Checkout/Block) and Add a function to get the cart subtotal

public function ADDSUBTOTALCODE ()
{
if ($parentBlock = $this->getParentBlock())
{
$amount = __(number_format(Mage::getSingleton(’checkout/session’)->getQuote()->getSubtotal(),2));
$text = __(’Amount $%s’, $amount);
$parentBlock->addLink($text, ‘checkout/cart’, $text, true, array(), 50,null,’class="top-link-cart"’);
}

return $this;

}


3.  Save files and upload them back to the server.

**Please ntoe to first make a backup of all the files being updated before changes are made as core files are being changed**

THANKS FOR THAT!

 
Magento Community Magento Community
Magento Community
Magento Community
 
erwinsmit
Jr. Member
 
Total Posts:  2
Joined:  2011-06-26
 
Paragon - 31 July 2010 05:05 AM

The solution above by ‘marye27’ works with Magento CE 1.4.0.1, however, the currency symbol is shown as $

Currency symbols everywhere else in Magento show as £, and Locales are set accordingly.

Does anyone have any ideas how the currency symbol can be changed? Any help greatly appreciated.

I had the same problem, I fixed it by changing the public function addCartLink() to:

public function addCartLink()
    
{
        $parentBlock 
$this->getParentBlock();
        if (
$parentBlock && Mage::helper('core')->isModuleOutputEnabled('Mage_Checkout')) {
            $count 
$this->helper('checkout/cart')->getSummaryCount();
            
$amount __(number_format(Mage::getSingleton('checkout/session')->getQuote()->getSubtotal(),2));
            
            if( 
$count == {
                $text 
$this->__('My Cart (%s) items <span>'Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol() .''$amount .'</span>'$count);
            
elseif( $count {
                $text 
$this->__('My Cart (%s) items <span>'Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol() .''$amount .'</span>'$count);
            
else {
                $text 
$this->__('My Cart (0) items <span>'Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol() .' 0.00</span>'$count);
            
}
            
            $parentBlock
->addLink($text'checkout/cart'$texttrue, array(), 50null'class="top-link-cart"');
        
}
        
return $this;
    
}

Just make sure you copy the links.php with the changes to app/code/local/Mage/Checkout/Block/links.php.

 
Magento Community Magento Community
Magento Community
Magento Community
 
ashishkhadpe
Member
 
Total Posts:  50
Joined:  2011-08-22
 

For showing Quantity in header you can use this code
Blog Link : Magento Coders

 
Magento Community Magento Community
Magento Community
Magento Community
 
SteveBerrill
Member
 
Avatar
Total Posts:  35
Joined:  2010-09-21
Preston
 
ashishkhadpe - 21 November 2011 04:51 PM

For showing Quantity in header you can use this code
Blog Link : Magento Coders

This is truly the best solution for me

thanks alot!

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top