在选择了所有必需的选项后,我正在寻找一种为可配置产品的价格增加价值的方法。我需要匹配所选简单产品的完整 SKU,因此每个选项的价格不合适
我已经用 SKU - 价格对构建了一个 JSON,现在正在寻找一个 JS 事件来干净地完成任务,并在添加到购物车和结帐阶段保留新价格
提前感谢您的任何见解
在选择了所有必需的选项后,我正在寻找一种为可配置产品的价格增加价值的方法。我需要匹配所选简单产品的完整 SKU,因此每个选项的价格不合适
我已经用 SKU - 价格对构建了一个 JSON,现在正在寻找一个 JS 事件来干净地完成任务,并在添加到购物车和结帐阶段保留新价格
提前感谢您的任何见解
您可以使用观察者类来收听checkout_cart_product_add_after
,并使用产品的“超级模式”针对报价项目设置自定义价格。
在您的 /app/code/local/{namespace}/{yourmodule}/etc/config.xml 中:
<config>
...
<frontend>
...
<events>
<checkout_cart_product_add_after>
<observers>
<unique_event_name>
<class>{{modulename}}/observer</class>
<method>modifyPrice</method>
</unique_event_name>
</observers>
</checkout_cart_product_add_after>
</events>
...
</frontend>
...
</config>
然后在 /app/code/local/{namespace}/{yourmodule}/Model/Observer.php 创建一个 Observer 类
class <namespace>_<modulename>_Model_Observer
{
public function modifyPrice(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;
//use $item and maybe your json object to determine the correct price
return $price;
}
}
这将处理来自后端的价格变化。至于javascript,我很抱歉,但我不太确定!