Magento - 如何在 header.phtml 中获取购物车项目总数

2024-03-03

我正在使用 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 ?>

我想,之前有一个叫 SUHUR 的人回答了一个链接,我本来打算用答案奖励他,但似乎他删除了自己的帖子?

他链接到此:http://nothingtopost.wordpress.com/tag/how-to-get-total-cart-item-in-magento/ http://nothingtopost.wordpress.com/tag/how-to-get-total-cart-item-in-magento/

我修改了代码,现在可以在 .phtml 文件上使用。

<?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));
    ?>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Magento - 如何在 header.phtml 中获取购物车项目总数 的相关文章

随机推荐