What's the differences for those get price functions in Mage_Sales_Model_Quote_Item_Abstract in Magento

StackOverflow https://stackoverflow.com/questions/22156885

  •  19-10-2022
  •  | 
  •  

Question

getBaseCalculationPrice (line 315) Get calculation price used for quote calculation in base currency.

getBaseOriginalPrice (line 389) Get Original item price (got from product) in base website currency.

getCalculationPrice (line 296) Get item price used for quote calculation process.

getConvertedPrice (line 434) Get item price converted to quote currency

getOriginalPrice (line 363) Get original price (retrieved from product) for item.

getPrice (line 412) Get item price. Item price currency is website base currency.

I am trying to get the final price that is displayed in the shopping cart, the price that is already been discounted if there are any promotions. Should I use getPrice or getCalculationPrice or getBaseCalculationPrice or any other? What are differences of all these different get price functions in Magento.

Was it helpful?

Solution 2

In the shopping cart are the cart totals displayed, not the prices. So i think you should use the following methods if Mage_Sales_Model_Quote_Item:

  • getRowTotal()
  • getRowTotalInclTax()
  • getRowTotalWithDiscount()

OTHER TIPS

Complicated isn't it? But it has to be complicated so that Magento can cover every possible way to calculate and display a price.

The quick answer is: getCalculationPrice()

I recommend studying the .phtml files that display the prices in the cart because in your question you write 'I am trying to get the final price that is displayed in the shopping cart' and to do that you need to follow the logic through those .phtml files. You need to apply tax logic, tax display logic, currency conversion and display formatting. Set aside a couple of day's time for code reading and testing.

There are a number of price calculations (these do not map one-to-one to the functions you listed above, this just sets the scene). The price might be displayed as:

//price excluding discount without tax in default currency
//price excluding discount without tax in local currency

//price excluding discount with tax in default currency
//price excluding discount with tax in local currency

//price including discount without tax in default currency
//price including discount without tax in local currency

//price including discount with tax in default currency
//price including discount with tax in local currency

Tax is complicated because Magento has WEEE tax and sales tax (WEEE might not apply in your store but the WEEE logic messes up the .phtml files discussed below). AND in your store you might choose to display the price in your cart with or without tax already included. AND the original product price might have been entered including tax.

So Magento is jumping through hoops to, for example, take the price of the product that includes tax in a default currency, subtract the tax, apply discounts, add the local tax for the current locale and convert to the currency of the current locale.

The functions you list are sort-of as you describe them above but think really hard about the different ways a price can be stored and changed and you need to read the code and apply the logic of each situation: a product might have a custom price for example. Most of the function do return the same number or one of two numbers (original price or discounted price)

getBaseCalculationPrice() : includes discounts, no currency conversion, may or may not include tax. Is the same as calling getPrice() if there is no custom price

getBaseOriginalPrice() : excludes discounts, no currency conversion, may or may not include tax

getCalculationPrice() is the same as getConvertedPrice() if there is no custom price

getConvertedPrice() returns the result of getPrice() with a currency conversion applied

getPrice() : includes discounts (I think), no currency conversion, may or may not include tax

getOriginalPrice() : currency conversion of getBaseOriginalPrice()

Which probably doesn't help. You have to read the code.

If you want to to get the price that is displayed in the shopping cart, you should look to follow the logic in those .phtml files that make up the cart layout.

For non-bundled products, see

app/design/frontend/themename/default/template/checkout/cart/item/default.phtml

For bundled products, see

app/design/frontend/themename/default/template/bundle/catalog/product/price.phtml

And note for bundles the function $_priceModel->getTotalPrices() to add to your large collection of pricing functions (it returns the maximum and minimum prices of the bundle (including or excluding tax), so isn't used in the cart display).

So there is a lot of code reading to do. But if you read through all the functions (starting from the .phtml files, not the abstract class - it is easier to work up than try to track down from the abstract class) then you will know what each function does. If you read the functions and set up some test code to output all the different values you will get to the bottom of it.

The tax helper, $_taxHelper = Mage::helper('tax'); also has a function $_taxHelper->getPrice();

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top