0

I am using magento 1.9.2

I have configurable product product 'whey'

I want to get price for simple product

enter image description here

I used getPrice(); in sales_order_place_before event

But it is giving me 1196.25 (wrong price)

I want 1595, How can I get it

Please help.

I make this changes in database

ALTER TABLE sales_flat_order_item ADD COLUMN product_mrp DECIMAL(12,4) NULL;
ALTER TABLE sales_flat_invoice_item ADD COLUMN product_mrp DECIMAL(12,4) NULL;
ALTER TABLE sales_flat_shipment_item ADD COLUMN product_mrp DECIMAL(12,4) NULL;

Then in Mage_Sales_Model_Observer

public function saveProductMrpInOrder(Varien_Event_Observer $observer) {
        $order = $observer->getEvent()->getOrder();
        foreach($order->getAllItems() as $item) {
            $price = Mage::getModel('catalog/product')->load($item->getId())->getPrice();
            $item->setProductMrp($price);
            Mage::log("Order placed successfully with getOrder event '$price'");
        }
      return $this;
    }

    public function saveProductMrpInInvoice(Varien_Event_Observer $observer) {
        $invoice = $observer->getEvent()->getInvoice();
        foreach($invoice->getAllItems() as $item) {
            $price = Mage::getModel('catalog/product')->load($item->getProductId())->getPrice();
            $item->setProductMrp($price);
            Mage::log("Order placed successfully with with getInvoice event '$price'");
        }
    }
      return $this;
    }

    public function saveProductMrpInShipment(Varien_Event_Observer $observer)
    {
        $shipment = $observer->getEvent()->getShipment();
        foreach($shipment->getAllItems() as $item) {               
            $product = Mage::getModel('catalog/product')->load($item->getProductId());
            $price = $product->getPrice();
            $item->product_mrp = $price;
            Mage::log("Order placed successfully with with getShipment event '$price'");
        }
    }

Then in invoice I am using getProductMrp() to get price

0

If you use getPrice() use then it will given you Cart item price.

In order to get Simple product price use getProduct()->gePrice() or getProduct()->geFinalPrice() .Those are given product price which shown at product page,category pages because of getProduct() object of model class (Mage_Catalog_Model_Product) \ edit:

saveProductMrpInOrder function

change

$price = Mage::getModel('catalog/product')->load($item->getId())->getPrice();
            $item->setProductMrp($price);

to

$price = Mage::getModel('catalog/product')->load($item->getProductId())->getPrice();
/* load Sales Order item model */
$TemOrderItem=Mage::getModel('sales/order_item')->load$item->getId())   ;       
$TemOrderItem->setProductMrp($price);
$TemOrderItem->save();

Explain u later

  • Its's not working @AmitBera – Jatin Raikwar Mar 30 '16 at 8:27
  • Can you plz share your code? – Amit Bera Mar 30 '16 at 8:38
  • I added code in question @AmitBera Please help – Jatin Raikwar Mar 30 '16 at 9:21
  • saveProductMrpInOrder is working but saveProductMrpInInvoice is not working , showing wrong price for getProductMrp @AmitBera – Jatin Raikwar Mar 30 '16 at 10:28
  • please help @AmitBera – Jatin Raikwar Mar 31 '16 at 7:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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