我試圖使用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服務?
我希望我的問題很清楚,先謝謝您的幫助。