Magento - 如何在 header.phtml 中获取购物车项目总数
我正在使用 Magento 电子商务,并且我已通过空白模板修改了 header.phtml。代码,这是我的代码,但它显示为空白。
<?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 ?>
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 ?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我想,之前有一个叫 SUHUR 的人回答了一个链接,我本来打算用答案奖励他,但似乎他删除了自己的帖子?
他链接到此:http://nothingtopost .wordpress.com/tag/how-to-get-total-cart-item-in-magento/
我修改了我的代码,现在可以在 .phtml 文件上使用。
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.
输出:
Output:
<代码>getItemsCount();
回显$_cartQty;
?>
如果你已经运行了 mage:app,那么这就是 1.7 所需要的,没有它你什么也做不了。
此外,这仅显示“项目”计数,而不显示数量。
<?php
$_cartQty = Mage::getSingleton('checkout/cart')->getItemsCount();
echo $_cartQty;
?>
thats all you need for 1.7 if your already running the mage:app which you can't do anything without really.
furthermore, this only shows "item" count, not quantity.
使用辅助对象获取当前购物车对象,然后计算购物车对象中的商品数量。
更多信息来自 http://www. douglasradburn.co.uk/how-to-number-of-cart-items-in-magento/
Use the helper object to get the current cart object, and then count the number of items in the cart object.
More from http://www.douglasradburn.co.uk/how-to-get-number-of-cart-items-in-magento/
您可以在此处找到您的购物车模板:
在
.count
类的范围内,您将看到此代码段:将其替换为此代码段,您将看到显示的总计:
You can find your cart template here:
Within a span with the class of
.count
you'll see this snippet:Replace it with this snippet and you'll get the grand total displayed instead:
链接到购物车时,您确实应该使用
Mage::helper('checkout/cart')->getCartUrl()
。如果您的网站托管在子域中,则给出的示例将不起作用。When linking to a cart, you should really use
Mage::helper('checkout/cart')->getCartUrl()
. The example given would not work if your site is hosted in a sub-domain.这对我有用,谢谢...
this works for me thanx...
在 phtml 文件中使用以下代码来获取购物车中的商品数量。
Use the below code in phtml file to get the no of items in cart.