Home  >  Article  >  Backend Development  >  Magento Get Shopping Cart Product Quantity and Price Program Code_PHP Tutorial

Magento Get Shopping Cart Product Quantity and Price Program Code_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 16:57:18977browse

This article will introduce to friends who use Magento how to get the quantity and price of shopping cart products and display them. Now I will give you a detailed introduction.

Get all product information in the shopping cart

The code is as follows
 代码如下 复制代码

// $items = Mage::getModel('checkout/cart')->getQuote()->getAllItems();
$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();foreach($items as $item) {
    echo 'ID: '.$item->getProductId().'
';
    echo 'Name: '.$item->getName().'
';
    echo 'Sku: '.$item->getSku().'
';
    echo 'Quantity: '.$item->getQty().'
';
    echo 'Price: '.$item->getPrice().'
';
    echo "
";
}

Copy code

 代码如下 复制代码

$totalItems = Mage::getModel('checkout/cart')->getQuote()->getItemsCount();
$totalQuantity = Mage::getModel('checkout/cart')->getQuote()->getItemsQty();

// $items = Mage::getModel('checkout/cart')->getQuote()->getAllItems();
$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();foreach($items as $item) {
echo 'ID: '.$item->getProductId().'
';
echo 'Name: '.$item->getName().'
';
echo 'Sku: '.$item->getSku().'
';
echo 'Quantity: '.$item->getQty().'
';
echo 'Price: '.$item->getPrice().'
';
echo "
";
}

 代码如下 复制代码

$subTotal = Mage::getModel('checkout/cart')->getQuote()->getSubtotal();
$grandTotal = Mage::getModel('checkout/cart')->getQuote()->getGrandTotal()

Of course, you can also quickly get the number of all items and products of the current user! Below is a quick function from magento!

The code is as follows Copy code
$totalItems = Mage::getModel('checkout/cart')->getQuote()->getItemsCount();
$totalQuantity = Mage::getModel('checkout/cart')->getQuote()->getItemsQty();

Here’s how to get the subtotal price and grand price
The code is as follows Copy code
$subTotal = Mage::getModel('checkout/cart')->getQuote()->getSubtotal();
$grandTotal = Mage::getModel('checkout/cart')->getQuote()->getGrandTotal()
In this way, you can quickly get the detailed information of the current shopping cart, conveniently operate the data, and display the shopping cart information! ! Generally used for shopping cart information in the upper right corner, or ajax shopping cart!
http://www.bkjia.com/PHPjc/631526.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631526.htmlTechArticleThis article will introduce to friends who use Magento how to get the quantity and price of shopping cart products and display them, as follows Let me give you a detailed introduction. Get all products in shopping cart...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn