Magento get the quantity and price of shopping cart. code _ PHP Tutorial

Source: Internet
Author: User
Magento obtains the number and price code of the shopping cart product. This article will show you how to get the quantity and price of the shopping cart products and how to use Magento. I will give you a detailed introduction below. This article will show you how to get the quantity and price of all products in the shopping cart and show them to anyone who uses Magento. next I will give you a detailed introduction.

Obtain information about all products 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"
";
}

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

The code is as follows:

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

The following method is used to obtain the subtotal price and grand price.

The code is as follows:

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

In this way, you can quickly obtain the details of the current shopping cart to facilitate data operations and display the information of the shopping cart !!

It is generally used for shopping cart information in the upper right corner, or ajax shopping cart!

Bytes. Get all products in the shopping cart...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.