【问题标题】:Magento : Reorder item with custom price, price always 0Magento:以自定义价格重新订购商品,价格始终为 0
【发布时间】:2012-03-06 00:31:47
【问题描述】:

我有一些具有自定义价格的产品。根据选择的选项,应用了一个为产品增加费用的公式,因此价格永远不会相同。我的问题是,当您重新订购时,重新订购产品的价格始终为 0。

在 sales/controllers/OrderController 中,在 reorder 函数中,有这个:

$order = Mage::registry('current_order');
$items = $order->getItemsCollection();
foreach ($items as $item) {
    try {
        $cart->addOrderItem($item);
        ...

如果我添加这些行,我可以检索自定义价格,但我找不到编辑项目的方法,因此这是重新订购中添加的价格。

$options = $item->getProductOptions();
$options = $options['info_buyRequest'];
$customPrice = $options['custom_price'];

我已经尝试过(在循环中,在 $cart->addOrderItem($item) 之前),但没有成功。

$item->setSpecialPrice($customPrice);
$item->setCustomPrice($customPrice);
$item->setOriginalPrice($customPrice);
$item->setBaseOriginalPrice($customPrice);
$item->setBaseCost($customPrice);
$item->setBaseRowInvoiced($customPrice);
$item->setRowInvoiced($customPrice);
$item->save();

有什么帮助吗?

【问题讨论】:

    标签: magento


    【解决方案1】:

    几种可能性。我会为checkout_cart_product_add_after 事件尝试一个事件观察者。

    // observer method:
    public function checkoutCartProductAddAfter(Varien_Event_Observer $observer)
    {
        $action = Mage::app()->getFrontController()->getAction();
        if ($action->getFullActionName() == 'sales_order_reorder')
        {
            $buyInfo = $observer->getQuoteItem()->getBuyRequest();
            if ($customPrice = $buyInfo->getCustomPrice())
            {
                $observer->getQuoteItem()->setCustomPrice($customPrice)
                     ->setOriginalCustomPrice($customPrice);
            }
        }
    }
    

    【讨论】:

    • 谢谢!我会试试这个,但是你的 $item 是从哪里来的?
    • Ups,对不起,那是$observer->getQuoteItem()。我更新了示例代码。
    • 是的,我在你回答之前就想通了,它工作正常。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多