从 Magento 订单中的简单产品获取可配置的产品价格
Get Configurable Product Price from Simple Product in Magento Order
我们正在写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
}
}
感谢 StackExchange 网络。我得到我的答案。
在这种情况下,您需要使用调用父项的 row()。根据 magento,当 configurable product
为 ordered
时,则 two rows has been saved
位于 sales_flat_order_item
.一个是可配置的产品数据 product_id 和订单商品价格,另一个是 simple products details
。所以需要数据 fetch data from Configurable products
。
所以需要改
'UnitPrice'=> $orderItem->getParentItem()?$orderItem->getParentItem()-> getPrice():$orderItem-> getPrice(),
来自
UnitPrice' => $orderItem -> getPrice(),
还给:
$linesTaxAmountSum += $orderItem->getParentItem()?$orderItem->getParentItem()->getTaxAmount():$orderItem->getTaxAmount();
发件人:
$linesTaxAmountSum += $orderItem->getTaxAmount();
发件人: magento.stackexchange.com ->Get Configurable Product Price from Simple Product in Magento Order
我们正在写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
}
}
感谢 StackExchange 网络。我得到我的答案。
在这种情况下,您需要使用调用父项的 row()。根据 magento,当 configurable product
为 ordered
时,则 two rows has been saved
位于 sales_flat_order_item
.一个是可配置的产品数据 product_id 和订单商品价格,另一个是 simple products details
。所以需要数据 fetch data from Configurable products
。
所以需要改
'UnitPrice'=> $orderItem->getParentItem()?$orderItem->getParentItem()-> getPrice():$orderItem-> getPrice(),
来自
UnitPrice' => $orderItem -> getPrice(),
还给:
$linesTaxAmountSum += $orderItem->getParentItem()?$orderItem->getParentItem()->getTaxAmount():$orderItem->getTaxAmount();
发件人:
$linesTaxAmountSum += $orderItem->getTaxAmount();
发件人: magento.stackexchange.com ->Get Configurable Product Price from Simple Product in Magento Order