Javascript Magento-重新加载价格()修改
我的客户需要对产品定制选项进行操作 使用Magento CE,我创建了一个产品,并在“管理产品”>“添加新产品”中的内置左侧菜单中为其提供了一些自定义选项,例如“mm”(毫米)和“mt”(米) 此产品将具有无线电选项和textbot输入 假设我们有Javascript Magento-重新加载价格()修改,javascript,php,magento,Javascript,Php,Magento,我的客户需要对产品定制选项进行操作 使用Magento CE,我创建了一个产品,并在“管理产品”>“添加新产品”中的内置左侧菜单中为其提供了一些自定义选项,例如“mm”(毫米)和“mt”(米) 此产品将具有无线电选项和textbot输入 假设我们有 Base price: 0 MM: Radio option A which costs 0,9 Radio option B which costs 1,2 Radio option C which costs 2,3 MT: Textbo
Base price: 0
MM:
Radio option A which costs 0,9
Radio option B which costs 1,2
Radio option C which costs 2,3
MT:
Textbox value = unknown yet
假设用户选择单选选项B
,并在文本字段中输入10
价格应更新如下:
1,2 * 10 + 0
那是
radio value cost * textbox value + base price
有没有办法告诉代码取单选按钮的值,将其乘以文本框的值,并将其全部相加到基价
在哪里可以查看产品自定义选项的当前行为
编辑
我看到每当选择一个值时,就会调用reloadPrice()
函数
我想检查两个输入是否都是收音机和文本,然后得到文本的值并乘以收音机的值
是这样吗?你能告诉我更多吗 reloadPrice()
不会在服务器级别更新产品价格。执行此产品价格更新的一种方法是在事件后实现结帐\购物车\产品\添加\ u
- 您是否在详细信息页面中使用javascript在客户端级别自定义逻辑。将此值指定给
产品\u添加到零件\u表单
下的某个隐藏变量。更好的方法是保存到会话以减少客户端漏洞,或者您可以找到自己更好的方法。或者只在Observer方法中实现您的登录。只要你觉得安全
- 重写类
Mage\u Checkout\u Model\u Cart
以修改为
public function addProduct($productInfo, $requestInfo=null)
{
...
Mage::dispatchEvent('checkout_cart_product_add_after', array('quote_item' => $result, 'product' => $product,'request_data'=>$request));
...
}
- 在yourmodule/etc/config.xml中:
<config>
...
<frontend>
...
<events>
<checkout_cart_product_add_after>
<observers>
<unique_name>
<class>modulename/observer</class>
<method>customPrice</method>
</unique_name>
</observers>
</checkout_cart_product_add_after>
</events>
...
</frontend>
...
</config>
...
...
模名/观察者
海关价格
...
...
- 然后在yourmodule/Model/Observer.php上创建一个Observer类
class <namespace>_<modulename>_Model_Observer
{
public function customPrice(Varien_Event_Observer $observer)
{
// Get the quote item
$item = $observer->getQuoteItem();
$request=$observer->getRequestData();
// Ensure we have the parent item, if it has one
$item = ( $item->getParentItem() ? $item->getParentItem() : $item );
// Load the custom price
$price = "custom price logic";//whatever from your hidden value or by some other mean.
// Set the custom price
$item->setCustomPrice($price);
$item->setOriginalCustomPrice($price);
// Enable super mode on the product.
$item->getProduct()->setIsSuperMode(true);
}
class\uuuu模型\u观察者
{
公共功能自定义价格(Varien_Event_Observer$Observer)
{
//获取报价项
$item=$observer->getQuoteItem();
$request=$observer->getRequestData();
//确保我们有父项(如果有)
$item=($item->getParentItem()?$item->getParentItem():$item);
//加载自定义价格
$price=“custom price logic”;//无论是从隐藏值还是通过其他方式。
//设定自定义价格
$item->setCustomPrice($price);
$item->setOriginalCustomPrice($price);
//在产品上启用超级模式。
$item->getProduct()->setIsSuperMode(true);
}
}
欲了解更多信息,请查看这对我有帮助,我希望这对您也有帮助
initialize : function(config){
this.config = config;
this.reloadPrice();
document.observe("dom:loaded", this.reloadPrice.bind(this));
},
reloadPrice : function(){
price = new Number();
config = this.config;
skipIds = [];
skipIds = [];
relatedword = [];
relatedvalue = [];
relatedid = [];
counter_each=0;
counter=1;
first=0;
areaValue=1;
submitbutton=true;
$$('body .product-custom-option').each(function(element){
var optionId = 0;
element.name.sub(/[0-9]+/, function(match){
optionId = match[0];
});
if (this.config[optionId]) {
if (element.type == 'checkbox' || element.type == 'radio')
{
if (element.checked)
{
if (config[optionId][element.getValue()])
{
<?php if(Mage::getVersion() >= 1.7): ?>
price += parseFloat(config[optionId][element.getValue()].price);
<?php else: ?>
price += parseFloat(this.config[optionId][selectOption.value]);
<?php endif; ?>
}
}
}
}
初始化:函数(配置){
this.config=config;
此参数为.reloadPrice();
document.observe(“dom:loaded”,this.reloadPrice.bind(this));
},
重载价格:函数(){
价格=新编号();
config=this.config;
skipIds=[];
skipIds=[];
关联词=[];
relatedvalue=[];
relatedid=[];
计数器_各=0;
计数器=1;
第一个=0;
面积值=1;
submitbutton=true;
$$('body.product自定义选项')。每个(函数(元素){
var optionId=0;
element.name.sub(/[0-9]+/,函数(匹配){
optionId=匹配[0];
});
if(this.config[optionId]){
if(element.type==“checkbox”| | element.type==“radio”)
{
如果(元素已选中)
{
if(config[optionId][element.getValue())
{
price+=parseFloat(配置[optionId][element.getValue()].price);
price+=parseFloat(this.config[optionId][selectOption.value]);
}
}
}
}
我认为这是因为你的信息太少。你真的需要解释你使用的是什么样的购物车,或者插件,提供代码示例。Magento不是一种语言,它是一个平台。你的问题不能用信息回答。我没有为购物车使用任何插件,它只是Magento的默认设置。我无法给出任何代码示例,因为我没有设想我应该把自定义代码放在哪里让自定义选项像我希望的那样运行。我会尝试提供更多的信息,但是实际上没有很多。你考虑过QTY字段的可配置产品而不是附加的文本字段吗?不,实际上我没有,但是这是可能的吗?我的意思是,属性是什么?文本框是什么?对立?