2012-01-19 20 views
14

Magento eCommerce kullanıyorum ve boş şablonumdan header.phtml dosyasını değiştirdim. Kod, bu benim kodum ama boş gösteriliyor.Magento - Sepette toplam öğe sayısı header.phtml olarak alınabilir

<?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 ?> 
+0

Var_dump $ cartQty? –

+0

Miktarı nasıl alabilirim? Lütfen yardım edebilirim –

cevap

36

bence sahur denilen biri tarafından daha önce bir bağlantı bir cevap, ben cevap onu ödüllendirmek gidiyordu ama o kendi yayın sildi görünüyor Orada edildi?

O, bu bağlantılı: http://nothingtopost.wordpress.com/tag/how-to-get-total-cart-item-in-magento/

Kodumu değiştirilebilir ve bu .phtml dosyalar şimdi çalışır.

<?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)); 
    ?> 
+0

Yukarıdakiler benim için işe yaramadı, ancak şunu yaptı: http://www.richardcastera.com/blog/magento-get-the-total-price-of-items -kullanıcı-in-the-cart –

+0

Selam gönderi ve bağlantı için teşekkürler, umarım diğerleri yararlı bulur. Bana hangi versiyonu anlatabilir misin? – TheBlackBenzKid

+1

Benim için çalıştım Magento 1.6 –

1

bir sepete bağlayan, gerçekten Mage::helper('checkout/cart')->getCartUrl() kullanmalıdır. Siteniz bir alt alanda barındırılıyorsa verilen örnek işe yaramaz. senin zaten mage çalışan bu teşekkürler benim için çalışıyor

+1

Kimin umurunda? Magento, bugüne dek karşılaştığım en büyük e-ticaret sistemi yığını. Bunun için planlarımızı kazıdık. – TheBlackBenzKid

0
<?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)); 
    ?> 

...

5

<?php $_cartQty = Mage::getSingleton('checkout/cart')->getItemsCount(); echo $_cartQty; ?>

thats bütün 1.7 için gereken: Eğer gerçekten olmadan bir şey yapamaz app.

Ayrıca, bu sadece miktar değil "öğe" sayısını gösterir.

8
<?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>'; 
?> 

Çıktı:

Sepetiniz
3 Öğeler [$ 32.5]

+1

Kod boyunca ilerlemek için bir metin ekleyin veya çıkışın bir örneğini ekleyin. – JoshDM

+0

Miktarı nasıl alabilirim? –

+1

yardımcı olabilir @JenithSamuel öğelerin sayısı $ cartItemsCount –

3

den

echo Mage::helper('checkout/cart')->getCart()->getItemsCount(); 

Daha Burada sepetinize şablonu bulabilirsiniz:

YOURSITE/app/design/frontend/YOURTHEME/default/template/checkout/cart/minicart.phtml 

.count sınıfına sahip bir zaman dilimi içinde bu pasajı görürsünüz:

<span class="count"><?php echo $_cartQty; ?></span> 

Bu snippet ile değiştirin ve büyük toplamın yerine görüntülenmesini sağlayabilirsiniz:

<?php echo $this->helper('checkout')->formatPrice(Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal()); ?> 
İlgili konular