首页 文章

从Magento订单中的简单产品中获取可配置的产品价格

提问于
浏览
1

我们正在编写Magento和MAS90 ERP系统的同步 . 我们正在将订单从Magento转移到ERP系统 . 我们为order_save_after添加了观察者 .

每个Magento Simple产品都有UPC代码,需要在ERP系统中添加项目 . 简单的产品会根据可配置的项目自动添加到Magento Order,但问题是简单产品的实际价格,数量,税额...存储在可配置产品中,但UPC存储在简单产品中 . 为了解决这个问题,我们决定从Magento Order获得简单的产品(以获得正确的UPC) .

我们的问题是,如何获得自动添加简单产品的正确价格,数量,税额 . (如何在Magento订单中链接可配置产品并自动添加简单产品 . )

希望你能理解我的问题并抱歉英语不好 .

以下是获取产品的代码片段 .

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 回答

  • 1

    谢谢StackExchange Network . 我得到了答案 .

    在这种情况下,你需要使用呼叫父项的行() . 按照当 configurable productordered Magento的,然后有 two rows has been savedsales_flat_order_item . 一是配置产品数据的product_id和订单项目的价格和另一个是S imple products details . 所以需要数据 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

相关问题