【发布时间】:2011-03-31 17:05:41
【问题描述】:
我需要在销售产品时更改一个属性,当订单完成时,我想我可以在某处/某处挂上一些东西,但我不知道在哪里/什么。
谢谢。
【问题讨论】:
-
ooooooooooh~ 啊啊啊鬼代码!!我看不到!!!
标签: php events zend-framework magento attributes
我需要在销售产品时更改一个属性,当订单完成时,我想我可以在某处/某处挂上一些东西,但我不知道在哪里/什么。
谢谢。
【问题讨论】:
标签: php events zend-framework magento attributes
如果您的问题被问到“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);
}
这应该足以让你走上正轨。
【讨论】:
尝试连接到 sales_order_place_after。 Here 是一个关于如何在 Magento 中捕捉事件的好教程。
【讨论】: