【发布时间】:2014-09-04 15:14:22
【问题描述】:
我正在尝试使用来自网络服务的值创建动态产品折扣。
我在网上搜索了一些关于这个问题的指南,我发现我需要使用checkout_cart_product_add_after和checkout_cart_update_items_after。
但是,我遵循了一些指南。创建了我自己的模块(在 Magento 后台可见:配置 > 高级 > 模块)和该模块的观察者。我没有再创造任何东西,但它不起作用。由于我可以在该菜单中看到模块,我相信问题出在观察者/事件调用上。
这是我的模块的 config.xml(位于 app\code\local\namespace\MyModule\etc 内):
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<namespace_MyModule>
<version>0.1.0</version>
</namespace_MyModule>
</modules>
<global>
<events>
<checkout_cart_product_add_after>
<observers>
<namespace_MyModule_Discount>
<class>MyModule/Observer</class>
<method>MyModulePriceChange</method>
</namespace_MyModule_Discount>
</observers>
</checkout_cart_product_add_after>
</events>
</global>
</config>
这是我的模块的 Observer(位于 app\code\local\namespace\MyModule\Model 内):
<?php
class namespace_MyModule_Model_Observer
{
public function MyModulePriceChange(Varien_Event_Observer $obs)
{
// Get the quote item
$item = $obs->getQuoteItem();
// Ensure we have the parent item, if it has one
$item = ( $item->getParentItem() ? $item->getParentItem() : $item );
// Load the custom price
$price = $this->_getPriceByItem($item);
// Set the custom price
$item->setCustomPrice($price);
$item->setOriginalCustomPrice($price);
// Enable super mode on the product.
$item->getProduct()->setIsSuperMode(true);
}
protected function _getPriceByItem(Mage_Sales_Model_Quote_Item $item)
{
$price = 4;
//use $item to determine your custom price.
return $price;
}
}
?>
另外,是否可以调用soap客户端来使用观察者内部的网络服务?
希望我的问题很清楚,提前感谢您的帮助。
【问题讨论】:
标签: web-services magento soap module observers