We are writing synchronization of Magento and MAS90 ERP system. We are transferring 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. )
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
}
}