bot_insane
bot_insane

Reputation: 2604

Get Configurable Product Price from Simple Product in Magento Order

We are writing synchronization of Magento and MAS90 ERP system. We are transfering Orders from Magento to ERP system. We have added observer for order_save_after.

Each of Magento Simple product has UPC code that needed to add item in ERP system. Simple products are automatically added to Magento Order based on configurable item, but problem is that simple product's real price, quantity, tax amount...are stored in configurable product, but UPC is stored in simple product. For resolving this problem, we decide to get simple products from Magento Order ( to get right UPC ).

Our question is, how to get RIGHT price, quantity, tax amount of automatically added simple product. ( How in Magento order are linked configurable product and automatically added simple product. )

Hope you will understand my question and sorry for bad English.

Here is snippet of Code that is getting products.

    foreach ($order->getAllItems() as $orderItem){
        $tmpMAS90OrderItem = NULL; 
        if($orderItem->getProductType() == 'simple'){
            $tmpMAS90OrderItem = $orderItem -> getUpc();
        }   
        if($tmpMAS90OrderItem != NULL) { 
            $setChildValuesArray = array(
                'ItemCode'            => $tmpMAS90OrderItem,
                'UnitPrice'           => $orderItem -> getPrice(), // THIS IS WRONG PRICE, right price is in configurable item
                'QuantityOrdered'     => $orderItem -> getQtyToInvoice() 
            );
            $querySO->setChildFieldValues($setChildValuesArray,$childSequence); //child sequence ( line sequence )
            $childSequence++;
             $linesTaxAmountSum += $orderItem->getTaxAmount(); // THIS IS WRONG TAX AMOUNT, right amount is in configurable item
        }
    }

Upvotes: 1

Views: 2543

Answers (1)

bot_insane
bot_insane

Reputation: 2604

Thank you StackExchange Network. I get my answer.

In this case you need to use call parent item's row().As per magento when a configurable product is ordered,then there are two rows has been saved at sales_flat_order_item.One is configurable product data product_id and order item prices and another is simple products details.So need data fetch data from Configurable products.

So need to change

'UnitPrice'=> $orderItem->getParentItem()?$orderItem->getParentItem()-> getPrice():$orderItem-> getPrice(),

From

UnitPrice'           => $orderItem -> getPrice(),

Also To:

$linesTaxAmountSum += $orderItem->getParentItem()?$orderItem->getParentItem()->getTaxAmount():$orderItem->getTaxAmount();

From:

$linesTaxAmountSum += $orderItem->getTaxAmount(); 

From: magento.stackexchange.com ->Get Configurable Product Price from Simple Product in Magento Order

Upvotes: 1

Related Questions