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.
Obtain information about all products in the shopping cart.
The Code is as follows: |
Copy code |
// $ Items = Mage: getModel ('checkout/cart')-> getQuote ()-> getAllItems (); $ Items = Mage: getSingleton ('checkout/session')-> getQuote ()-> getAllItems (); foreach ($ items as $ item ){ Echo 'id: '. $ item-> getProductId ().' <br> '; Echo 'name: '. $ item-> getName ().' <br> '; Echo 'sku: '. $ item-> getSku ().' <br> '; Echo 'quantity: '. $ item-> getQty ().' <br> '; Echo 'price: '. $ item-> getPrice ().' <br> '; Echo "<br> "; } |
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: |
Copy code |
$ 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: |
Copy code |
$ 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!