web-dev-qa-db-fra.com

Magento - Comment obtenir le total des articles du panier dans header.phtml

J'utilise Magento eCommerce et j'ai modifié mon header.phtml via le modèle Blank. Code, ceci est mon code mais il est vide.

 <?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 ?>
16
TheBlackBenzKid

Il y avait une réponse à un lien auparavant par quelqu'un qui s'appelle SUHUR. Je pense que j'allais le récompenser avec la réponse, mais il semble qu'il a supprimé son propre message?

Il a lié à ceci: http://nothingtopost.wordpress.com/tag/how-to-get-total-cart-item-in-magento/

J'ai modifié mon code et cela fonctionne maintenant sur les fichiers .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));
    ?>
38
TheBlackBenzKid
<?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>';
?>

Sortie:

Votre panier
3 articles [$ 32.5]

9
Andres Separ

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

c’est tout ce dont vous avez besoin pour la version 1.7 si vous utilisez déjà le mage: une application sans laquelle vous ne pouvez rien faire.

en outre, cela indique uniquement le nombre d'articles, pas la quantité.

5
dubrod

Vous pouvez trouver votre modèle de panier ici:

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

Dans un intervalle de la classe .count, vous verrez cet extrait:

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

Remplacez-le par cet extrait et vous obtiendrez le total général affiché à la place:

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

Utilisez l'objet d'assistance pour obtenir l'objet de panier actuel, puis comptez le nombre d'articles dans l'objet de panier.

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

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

3
d4nyll

Lorsque vous vous connectez à un panier, vous devriez vraiment utiliser Mage::helper('checkout/cart')->getCartUrl(). L'exemple donné ne fonctionnerait pas si votre site est hébergé dans un sous-domaine.

1
Richard
<?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));
    ?>

cela fonctionne pour moi merci ...

0
user2219206