2012-01-19 22 views
14

Sto usando Magento eCommerce e ho modificato il mio header.phtml tramite il modello vuoto. Codice, questo è il mio codice ma mostra vuoto.Magento - Come ottenere gli elementi del carrello totale in 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

cosa ottieni se var_dump $ cartQty? –

+0

Come ottengo la quantità può aiutare per favore –

risposta

36

C'è stata una risposta a un collegamento prima da qualcuno chiamato Suhur credo, stavo per ricompensarlo con la risposta, ma sembra che cancellato il suo post?

Ha legato a questo: http://nothingtopost.wordpress.com/tag/how-to-get-total-cart-item-in-magento/

ho modificato il mio codice e questo funziona ora in file .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

Quanto sopra non ha funzionato per me, ma questo ha fatto: http://www.richardcastera.com/blog/magento-get-the-total-price-of-items -currently-nel-cart –

+0

Ciao grazie per il post e il link, spero che gli altri lo trovino utile. Puoi dirmi quale versione? – TheBlackBenzKid

+1

Ha funzionato per me su Magento 1.6 –

1

Quando si collega ad un carrello, si dovrebbe davvero utilizzare Mage::helper('checkout/cart')->getCartUrl(). L'esempio fornito non funzionerebbe se il tuo sito è ospitato in un sottodominio.

+1

A chi importa? Magento è il più grande mucchio di sistema di e-commerce di merda che ho incontrato fino ad oggi. Abbiamo cancellato i nostri piani per questo. – 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)); 
    ?> 

questo funziona per me thanx ...

5

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

questo è tutto ciò che serve per 1,7 se il vostro già in esecuzione il mago: app che non si può fare nulla senza realmente.

inoltre, questo mostra solo il conteggio "articolo", non la quantità.

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

uscita:

Il Carrello
3 articoli [$ 32.5]

+1

Aggiungere del testo per esaminare il codice o un esempio dell'output. – JoshDM

+0

Come ottengo la quantità ??può aiutarmi per favore –

+1

Ciao @JenithSamuel il numero di elementi sono memorizzati in $ cartItemsCount –

3

È possibile trovare il modello di spesa qui:

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

Entro un arco con la classe di .count vedrete questo frammento:

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

Sostituiscilo con questo frammento e visualizzerai il totale generale:

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