2

Magento CE 1.9.1.9

I'm in the process of modifying a custom module that gets item information form the Mage_Sales_Model_Order_Item model when an order is placed. Currently I'm getting pricing information like this:

    'sell_price' => $this->_getBaseAmt('row_total', $item),
    'original_price' => $item->getOriginalPrice(),

I'm attempting to get either the discount amount or if possible, the price before discount. Here is an example of my attempt:

'price_before_discount' => $item->getPrice(),

But all I can ever seem to return is the sale price (aka "special price"). Can someone provide an example of the correct way to get this information? I need the original price of item that has been ordered.

3 Answers 3

2

Inspecting the object I have the original price in all of these:

$orderItem->getPriceInclTax();
$orderItem->getBasePriceInclTax();
$orderItem->getRowTotalInclTax();
$orderItem->getBaseRowTotalInclTax();

While these gets the discounted price:

$orderItem->getPrice();
$orderItem->getBasePrice();
$orderItem->getRowTotal();
$orderItem->getBaseRowTotal();
1

Similar solution found on Stack Overflow: https://stackoverflow.com/questions/10368757/how-to-show-the-original-price-in-the-shopping-cart-in-magento

This will pull the non-discounted price in my scenario:

$item->getProduct()->getPrice(),
2
  • 2
    Keep in mind that if the product's price has changed this will give you the new price not the original price at time of purchase - which I believe it is not possible to reconstruct. Feb 13, 2015 at 20:33
  • What about with a method like this? $this->_getBaseAmt('row_total', $item)
    – sparecycle
    Feb 13, 2015 at 20:34
1

Unfortunately this information is not stored. In app/code/core/Mage/Sales/Model/Quote/Address/Total/Subtotal.php you have

        $finalPrice = $product->getFinalPrice($quoteItem->getQty());
        $item->setPrice($finalPrice)
            ->setBaseOriginalPrice($finalPrice);
        $item->calcRowTotal();

which uses the final discounted, specially priced amount including potential tier/group pricing.

Your answer to look up the original product can work if the pricing doesn't change and you also need to be careful of catalog promotions. Depending on your requirements you might want to create an extension that saves the price information at the time the order is placed with the order item (you might even want to keep this in a separate product attribute (standard price for example).

3
  • This looks interesting. Trying it now!
    – sparecycle
    Feb 13, 2015 at 20:46
  • Doesn't seem to work for me. Will keep trying. Getting this error: PHP Fatal error: Call to a member function getFinalPrice() on a non-object
    – sparecycle
    Feb 13, 2015 at 21:01
  • The code is quoted from github.com/OpenMage/magento-mirror/blob/magento-1.9/app/code/… to highlight where this information is NOT stored. To implement what I suggested you would need to build out an extension that adds a new product attribute and a way to store this when converted from a quote to order in the database. Best of luck. Feb 13, 2015 at 21:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.