我试图使用webservice中的值创建动态产品折扣。Magento的观察者事件不起作用,并在Observer类中使用webservices
我在网上搜索了一些关于这个问题的指南,我发现我需要使用checkout_cart_product_add_after
和checkout_cart_update_items_after
。
但是,我遵循了一些指南。创建了我自己的模块(在Magento后台可以看到:配置>高级>模块)以及该模块的观察者。我没有创造更多,但它不起作用。由于我可以在该菜单中看到该模块,因此我认为问题出在观察者/事件调用上。
以下是config.xml文件(这是内部应用程序\代码\本地\命名空间\ MyModule的\等)为我的模块:
<?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>
这是我的观察(这是内部应用程序\代码\当地\命名空间\ MyModule的\模型)对我的模块:
<?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服务?
我希望我的问题很清楚,先谢谢您的帮助。