【发布时间】:2012-03-29 08:20:01
【问题描述】:
我正在寻找一种方法来为可配置产品的价格添加价值所有必需的选项都被选中。我需要匹配所选简单产品的完整 SKU,因此每个选项的价格不合适
我已经使用 SKU - 价格对构建了一个 JSON,现在正在寻找一个 JS 事件来干净利落地完成任务,并在添加到购物车和结帐阶段保留新价格
提前感谢您的任何见解
【问题讨论】:
标签: javascript magento product configurable
我正在寻找一种方法来为可配置产品的价格添加价值所有必需的选项都被选中。我需要匹配所选简单产品的完整 SKU,因此每个选项的价格不合适
我已经使用 SKU - 价格对构建了一个 JSON,现在正在寻找一个 JS 事件来干净利落地完成任务,并在添加到购物车和结帐阶段保留新价格
提前感谢您的任何见解
【问题讨论】:
标签: javascript magento product configurable
您可以使用观察者类收听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,对不起,我不太确定!
【讨论】:
sales_quote_merge_after 事件中的定价问题,这是匿名客户购物车转换为登录客户的地方。至于 JS,我已经为管理值对构建了一个完整的选项 ID JSON,收集了完整的简单 SKU 并为最终价格增加了价值(再次来自 JSON)