Magento obtains the number and price code of the shopping cart products.

Source: Internet
Author: User

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!

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.