【问题标题】:Get Configurable Product Price from Simple Product in Magento Order从 Magento 订单中的简单产品中获取可配置的产品价格
【发布时间】:2015-05-07 07:22:36
【问题描述】:

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

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

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

希望你能理解我的问题,对英语不好表示抱歉。

这是获取产品的代码的 sn-p。

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

【问题讨论】:

    标签: php magento


    【解决方案1】:

    感谢 StackExchange 网络。我得到了答案。

    在这种情况下,您需要使用调用父项的row()。根据magento,当configurable productordered时,sales_flat_order_item处有two rows has been saved。一个是可配置的产品数据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

    【讨论】:

      猜你喜欢
      • 2013-05-18
      • 2012-08-30
      • 1970-01-01
      • 2021-12-22
      • 1970-01-01
      • 2014-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多