1

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
        }
    }

1 Answer 1

2

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(); 
2
  • Thank you for answer. It mean that each parent(up) row of simple product is configurable item ? ( In case that we ordered configurable product ) First I need to get product data from configurable item, and put it in next row? ( Is there any way that when a configurable product will be ordered no second row will be added ? ) May 7, 2015 at 7:42
  • may use getAllVisibleItems() instead getAllItems() better idea
    – Amit Bera
    May 7, 2015 at 7:49

Your Answer

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

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