I am using Magento eCommerce and I have modified my header.phtml via the Blank template. Code, this is my code but it shows blank.
<?php $cartQty = $this->getSummaryCount() ?>
<?php if ($cartQty>0): ?>
<?php if ($cartQty==1): ?>
<?php echo $this->__('<a class="cartgo" href="%s">(1 ITEM)</a>', $this->getUrl('checkout/cart')) ?>
<?php else: ?>
<?php echo $this->__('<a class="cartgo" href="%s">(%s ITEMS)</a>', $this->getUrl('checkout/cart')) ?>
<?php endif ?>
<?php endif ?>
Get the number of items in cart and total quantity in cart. $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $cart = $objectManager->get('\Magento\Checkout\Model\Cart'); $totalItems = $cart->getQuote()->getItemsCount(); $totalQuantity = $cart->getQuote()->getItemsQty();
Root template <Magento_Theme_module_dir>/view/base/templates/root. phtml is the root template for all storefront pages in the Magento application. This file can be overridden in a theme just like any other template file. Unlike other templates, root.
There was an answer to a link before by someone called SUHUR I think, I was going to reward him with the answer but it seems he deleted his own post?
He linked to this: http://nothingtopost.wordpress.com/tag/how-to-get-total-cart-item-in-magento/
I modified my code and this works now on .phtml files.
<?php
$count = $this->helper('checkout/cart')->getSummaryCount(); //get total items in cart
$total = $this->helper('checkout/cart')->getQuote()->getGrandTotal(); //get total price
if($count==0)
{
echo $this->__('<a href="/checkout/cart" class="cartgo">(0 ITEMS)</a>',$count);
}
if($count==1)
{
echo $this->__('<a href="/checkout/cart" class="cartgo">(1 ITEM)</a>',$count);
}
if($count>1)
{
echo $this->__('<a href="/checkout/cart" class="cartgo">(%s ITMES)</a>',$count);
}
echo $this->__('', $this->helper('core')->formatPrice($total, false));
?>
<?php
$cartTotal = $this->helper('checkout/cart')->getQuote()->getGrandTotal();
$cartItemsCount = Mage::helper('checkout/cart')->getCart()->getItemsCount();
$cartSuffix = ($cartItemsCount != 1) ? 's' : '';
echo '<a class="cartgo" href="'.$this->getUrl('checkout/cart').'">
<strong>'.$this->__('Your basket').'</strong><br />'.
$this->__('(%s) Item%s', $cartItemsCount, $cartSuffix).
'<span>[$'.$this->helper('core')->formatPrice($cartTotal, false).']</span>
</a>';
?>
Output:
Your basket
3 Items [$32.5]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With