2012-01-19 14 views
14

में कार्ट आइटम कुल कैसे प्राप्त करें I 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 ?> 
+0

यदि आप var_dump $ cartQty करते हैं तो आपको क्या मिलता है? –

+0

मुझे मात्रा कैसे मिलती है ?? कृपया –

उत्तर

36

वहाँ गया था suhur कहा जाता है मुझे लगता है कि किसी के द्वारा पहले एक लिंक का जवाब, मैं उसे जवाब के साथ पुरस्कृत करने के लिए जा रहा था लेकिन ऐसा लगता है वह अपने ही पोस्ट को हटा दिया?

वह इस से जुड़ा हुआ: 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)); 
    ?> 
+0

मदद कर सकते हैं उपर्युक्त मेरे लिए काम नहीं करता है, लेकिन ऐसा हुआ: http://www.richardcastera.com/blog/magento-get-the-total-price-of-items -सुरेंटली-इन-द-कार्ट –

+0

पोस्ट और लिंक के लिए हाय धन्यवाद, मुझे आशा है कि दूसरों को यह उपयोगी लगेगा। क्या आप मुझे बता सकते हैं कि संस्करण क्या है? – TheBlackBenzKid

+1

Magento 1.6 –

1

जब एक गाड़ी को जोड़ने, तुम सच में Mage::helper('checkout/cart')->getCartUrl() उपयोग करना चाहिए। यदि आपका साइट उप-डोमेन में होस्ट की गई है तो दिया गया उदाहरण काम नहीं करेगा।

+1

पर मेरे लिए काम किया कौन परवाह करता है? मैगेंटो बकवास ईकामर्स सिस्टम का सबसे बड़ा ढेर है जो मैं आज तक आया हूं। हमने इसके लिए हमारी योजनाओं को तोड़ दिया। – 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)); 
    ?> 

यह मेरे लिए काम करता है thanx ...

5

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

thats सब आप 1.7 के लिए की जरूरत है अपने पहले से ही दाना चल रहा है, तो: एप्लिकेशन है जो आप वास्तव में बिना कुछ नहीं कर सकते।

इसके अलावा, यह केवल "आइटम" गिनती दिखाता है, मात्रा नहीं।

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

आउटपुट:

आपका टोकरी
3 आइटम [$ 32.5]

+1

कोड के माध्यम से चलने के लिए कुछ पाठ जोड़ें, या शायद आउटपुट का नमूना। – JoshDM

+0

मुझे मात्रा कैसे मिलती है ??कृपया –

+1

मदद करें हाय @ जेनिथसमुएल आइटम की संख्या $ कार्ट में संग्रहीत की जाती है ITemsCount –

3

उपयोग वर्तमान गाड़ी वस्तु मिलता है, और उसके बाद की संख्या की गणना करने के लिए सहायक ऑब्जेक्ट कार्ट ऑब्जेक्ट में आइटम।

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

http://www.douglasradburn.co.uk/how-to-get-number-of-cart-items-in-magento/

+0

मुझे मात्रा कैसे मिलती है ?? कृपया मदद कर सकते हैं –

3

से अधिक आप यहाँ अपनी गाड़ी टेम्पलेट पा सकते हैं:

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

.count के वर्ग के साथ अवधि में आप इस टुकड़ा दिखाई देंगे:

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

इसे इस स्निपेट के साथ बदलें और आपको इसके बजाय कुल मिलाकर कुल मिलाकर मिलेगा:

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

 संबंधित मुद्दे