【问题标题】:How to change a given attribute a product is sold? (When the order is completed)如何更改产品销售的给定属性? (订单完成时)
【发布时间】:2011-03-31 17:05:41
【问题描述】:

我需要在销售产品时更改一个属性,当订单完成时,我想我可以在某处/某处挂上一些东西,但我不知道在哪里/什么。

谢谢。

【问题讨论】:

  • ooooooooooh~ 啊啊啊鬼代码!!我看不到!!!

标签: php events zend-framework magento attributes


【解决方案1】:

如果您的问题被问到“magento 方式”,当您说“订单已完成”时,这意味着它的状态是“完成”。已在前端站点订购了一个状态为“完成”的订单,然后从管理员处开具发票并发货。

我的回答是基于这个术语,因此可以在订单完成后为您提供更改产品属性的线索(再次以 magento 方式)。

为你编写整个代码并不是很好的帮助而且很长,所以这里是路径(在我看来):)

  • 创建一个模块 (谷歌是你的朋友)

  • 将观察者附加到此模块并使其观察事件“sales_order_save_after” (谷歌是你的朋友)

  • 在观察者文件/方法中,检索订单及其状态

            $order = $observer->getEvent()->getOrder();
            $orderStatus = $order->getStatus();
    
  • 如果订单状态为“已完成”,则创建一个 foreach 来更新所有商品所需的属性

这将为所有产品提供相同的属性值。在此示例中,已完成订单的所有产品都将重命名为“已售产品”。

            if ($orderStatus == 'complete') {
                $items = $order->getAllItems();
                foreach ($items as $item) {
                    $productsToUpdate[] = $item->getProductId();
                }
                $theAttributeToUpdate = 'name';
                $theAttributeValue = 'Sold Product';
                Mage::getSingleton('catalog/product_action')->updateAttributes($productsToUpdate, array($theAttributeToUpdate => $theAttributeValue), 0);
            }

这应该足以让你走上正轨。

【讨论】:

  • 我最终采取了一些不同的方法,并挂钩了以下事件:checkout_(onepage|multishipping)_controller_success_action。谢谢
  • 好的!因此,一旦将订单放在前端,而不是在后端“完成”时,您需要更改属性:) 很高兴我能提供帮助。
  • 是的,我需要在销售产品时更改特殊状态,无论它是“完成”还是“不”。
【解决方案2】:

尝试连接到 sales_order_place_afterHere 是一个关于如何在 Magento 中捕捉事件的好教程。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-05
    • 1970-01-01
    相关资源
    最近更新 更多