- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Magento 将可配置产品的选择设置为一系列选择下拉列表 - 其中选择第一个将相关选项添加到第二个,选择第二个选项将相关选项添加到第三个,并且等等。
我想通过使用其他表单对象设置可配置产品的选择选项来覆盖这些下拉菜单,而不是 magento 创建的标准选择下拉菜单。然而,重写 magento 的代码似乎既复杂又冒险,所以我试图隐藏默认的下拉菜单并创建更好看的 css 按钮来替换它们。当点击这些新按钮时,代码将从隐藏的下拉菜单之一中选择相同的选项,读取标准 magento js 打印的结果,并将信息传递回我的脚本。
问题是我无法点击我的按钮来影响下拉菜单 - 我可以让下拉菜单显示新值但似乎无法激活将相关选项添加到下一个选择下拉菜单的磁电机 js。
magento js 是用 prototype.js 编写的,我使用带有 jQuery 库的常规 javascript。
这是 magneto 的可配置产品的原型(prototype)脚本:
/**************************** CONFIGURABLE PRODUCT **************************/
Product.Config = Class.create();
Product.Config.prototype = {
initialize: function(config){
this.config = config;
this.taxConfig = this.config.taxConfig;
this.settings = $$('.super-attribute-select');
this.state = new Hash();
this.priceTemplate = new Template(this.config.template);
this.prices = config.prices;
this.settings.each(function(element){
Event.observe(element, 'change', this.configure.bind(this))
}.bind(this));
// fill state
this.settings.each(function(element){
var attributeId = element.id.replace(/[a-z]*/, '');
if(attributeId && this.config.attributes[attributeId]) {
element.config = this.config.attributes[attributeId];
element.attributeId = attributeId;
this.state[attributeId] = false;
}
}.bind(this))
// Init settings dropdown
var childSettings = [];
for(var i=this.settings.length-1;i>=0;i--){
var prevSetting = this.settings[i-1] ? this.settings[i-1] : false;
var nextSetting = this.settings[i+1] ? this.settings[i+1] : false;
if(i==0){
this.fillSelect(this.settings[i])
}
else {
this.settings[i].disabled=true;
}
$(this.settings[i]).childSettings = childSettings.clone();
$(this.settings[i]).prevSetting = prevSetting;
$(this.settings[i]).nextSetting = nextSetting;
childSettings.push(this.settings[i]);
}
// Set default values - from config and overwrite them by url values
if (config.defaultValues) {
this.values = config.defaultValues;
}
var separatorIndex = window.location.href.indexOf('#');
if (separatorIndex != -1) {
var paramsStr = window.location.href.substr(separatorIndex+1);
var urlValues = paramsStr.toQueryParams();
if (!this.values) {
this.values = {};
}
for (var i in urlValues) {
this.values[i] = urlValues[i];
}
}
this.configureForValues();
document.observe("dom:loaded", this.configureForValues.bind(this));
},
configureForValues: function () {
if (this.values) {
this.settings.each(function(element){
var attributeId = element.attributeId;
element.value = (typeof(this.values[attributeId]) == 'undefined')? '' : this.values[attributeId];
this.configureElement(element);
}.bind(this));
}
},
configure: function(event){
var element = Event.element(event);
this.configureElement(element);
},
configureElement : function(element) {
this.reloadOptionLabels(element);
if(element.value){
this.state[element.config.id] = element.value;
if(element.nextSetting){
element.nextSetting.disabled = false;
this.fillSelect(element.nextSetting);
this.resetChildren(element.nextSetting);
}
}
else {
this.resetChildren(element);
}
this.reloadPrice();
// Calculator.updatePrice();
},
reloadOptionLabels: function(element){
var selectedPrice;
if(element.options[element.selectedIndex].config){
selectedPrice = parseFloat(element.options[element.selectedIndex].config.price)
}
else{
selectedPrice = 0;
}
for(var i=0;i<element.options.length;i++){
if(element.options[i].config){
element.options[i].text = this.getOptionLabel(element.options[i].config, element.options[i].config.price-selectedPrice);
}
}
},
resetChildren : function(element){
if(element.childSettings) {
for(var i=0;i<element.childSettings.length;i++){
element.childSettings[i].selectedIndex = 0;
element.childSettings[i].disabled = true;
if(element.config){
this.state[element.config.id] = false;
}
}
}
},
fillSelect: function(element){
var attributeId = element.id.replace(/[a-z]*/, '');
var options = this.getAttributeOptions(attributeId);
this.clearSelect(element);
element.options[0] = new Option(this.config.chooseText, '');
var prevConfig = false;
if(element.prevSetting){
prevConfig = element.prevSetting.options[element.prevSetting.selectedIndex];
}
if(options) {
var index = 1;
for(var i=0;i<options.length;i++){
var allowedProducts = [];
if(prevConfig) {
for(var j=0;j<options[i].products.length;j++){
if(prevConfig.config.allowedProducts
&& prevConfig.config.allowedProducts.indexOf(options[i].products[j])>-1){
allowedProducts.push(options[i].products[j]);
}
}
} else {
allowedProducts = options[i].products.clone();
}
if(allowedProducts.size()>0){
options[i].allowedProducts = allowedProducts;
element.options[index] = new Option(this.getOptionLabel(options[i], options[i].price), options[i].id);
element.options[index].config = options[i];
index++;
}
}
}
},
getOptionLabel: function(option, price){
var price = parseFloat(price);
if (this.taxConfig.includeTax) {
var tax = price / (100 + this.taxConfig.defaultTax) * this.taxConfig.defaultTax;
var excl = price - tax;
var incl = excl*(1+(this.taxConfig.currentTax/100));
} else {
var tax = price * (this.taxConfig.currentTax / 100);
var excl = price;
var incl = excl + tax;
}
if (this.taxConfig.showIncludeTax || this.taxConfig.showBothPrices) {
price = incl;
} else {
price = excl;
}
var str = option.label;
if(price){
if (this.taxConfig.showBothPrices) {
str+= ' ' + this.formatPrice(excl, true) + ' (' + this.formatPrice(price, true) + ' ' + this.taxConfig.inclTaxTitle + ')';
} else {
str+= ' ' + this.formatPrice(price, true);
}
}
return str;
},
formatPrice: function(price, showSign){
var str = '';
price = parseFloat(price);
if(showSign){
if(price<0){
str+= '-';
price = -price;
}
else{
str+= '+';
}
}
var roundedPrice = (Math.round(price*100)/100).toString();
if (this.prices && this.prices[roundedPrice]) {
str+= this.prices[roundedPrice];
}
else {
str+= this.priceTemplate.evaluate({price:price.toFixed(2)});
}
return str;
},
clearSelect: function(element){
for(var i=element.options.length-1;i>=0;i--){
element.remove(i);
}
},
getAttributeOptions: function(attributeId){
if(this.config.attributes[attributeId]){
return this.config.attributes[attributeId].options;
}
},
reloadPrice: function(){
var price = 0;
var oldPrice = 0;
for(var i=this.settings.length-1;i>=0;i--){
var selected = this.settings[i].options[this.settings[i].selectedIndex];
if(selected.config){
price += parseFloat(selected.config.price);
oldPrice += parseFloat(selected.config.oldPrice);
}
}
optionsPrice.changePrice('config', {'price': price, 'oldPrice': oldPrice});
optionsPrice.reload();
return price;
if($('product-price-'+this.config.productId)){
$('product-price-'+this.config.productId).innerHTML = price;
}
this.reloadOldPrice();
},
reloadOldPrice: function(){
if ($('old-price-'+this.config.productId)) {
var price = parseFloat(this.config.oldPrice);
for(var i=this.settings.length-1;i>=0;i--){
var selected = this.settings[i].options[this.settings[i].selectedIndex];
if(selected.config){
var parsedOldPrice = parseFloat(selected.config.oldPrice);
price += isNaN(parsedOldPrice) ? 0 : parsedOldPrice;
}
}
if (price < 0)
price = 0;
price = this.formatPrice(price);
if($('old-price-'+this.config.productId)){
$('old-price-'+this.config.productId).innerHTML = price;
}
}
}
}
最佳答案
今天我遇到了同样的问题,并且为解决方案做了很多工作。我也尝试向其他人展示我在这里所做的事情。
主要问题是(如您所说)更改事件未正确触发。如果您输入类似 element.change() 的内容,也不会。
于是我找到了这个方法:
function fireEvent(element,event)
{
if (document.createEventObject)
{
// dispatch for IE
var evt = document.createEventObject();
return element.fireEvent('on'+event,evt);
}
else
{
// dispatch for firefox + others
var evt = document.createEvent("HTMLEvents");
evt.initEvent(event, true, true );
return !element.dispatchEvent(evt);
}
}
然后我触发了 change 方法:
var obj = jQuery('#'+parentObj.attr('value')).get();
Event.observe(obj[0],'change',function(){});
fireEvent(obj[0],'change');
这里是 obj 从下拉列表中选择普通的 JS 对象。
希望对你有帮助!
关于magento - 远程操作可配置产品选择下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14306994/
Magento 主题和 Magento 皮肤有什么区别?它们和 Magento 模块之间有什么关系? 最佳答案 主题是创建视觉体验的布局、模板、区域设置和/或外观文件的任意组合... 主题由以下任意或
我想在 Magento 之外获得购物车 Block。这是我的代码。 getLocale()->getLocaleCode(); //Solution Mage::getSingleto
我是 Magento 新手,使用 CE 1.7.0.2 开发了一个网站。现在可以上线了,但我遇到了页面加载缓慢的问题。 我的网站产品主页、列表和详细信息页面最初需要 10-13 秒的时间来加载页面,但
我在 magento 网站上工作。我有 4 个类别,其中两个使用其他主题(不是我的特定 magento 主题)。我如何配置我的主题以从我的默认主题而不是基本主题中获取丢失的文件。 谢谢 最佳答案 通常
我遇到了我的 magento 项目的要求,因此我需要为特定客户群的购买提供特别折扣。此折扣必须显示在客户帐户中,如果他们属于该特定组,并且当用户要使用该特定折扣时,必须根据该折扣优惠对该商品的价格进行
我在 Magento 主题开发中找到的大量教程建议从使用空白作为制作您自己的自定义主题的指南开始。很多这些文章已经很旧了,截至当前版本(1.7),情况仍然如此吗? 附言- 除了 Magento 的 o
似乎这应该是一个可以找到的问题,但我找不到它。 magento 数据库中存储的类别 NAME 在哪里?我可以看到 catalog_category_entity有 key ID,然后还有其他 EAV
我知道 magento 会根据需要调整原始产品图像的大小并以不同的大小对其进行多次缓存。 这些 chached 图像存储在哪里(路径)? 当您从缓存管理中刷新图像缓存时,它们会被删除吗? 如果我要手动
我在我的 magento 网上商店中使用这个扩展 http://www.manadev.com/seo-layered-navigation-plus (分层导航) 此扩展适用于简单的产品。 但就我而
我在 Magento 的一家商店下拥有某些产品的批发属性。我想设置它,以便这些特定属性仅出现在产品页面上,如果客户已登录并且他们在批发客户组中。 这可能吗? 最佳答案 像这样的事情应该可以工作,尽管我
和有什么区别和 在 Magento 中? 我将创建一个新模块,我必须决定在这两个事件中的哪一个事件中挂起我的观察者。 最佳答案 类别(和所有其他对象)保存在事务中。事件catalog_categor
好吧,这是一个似乎很容易解决的问题,但它让我望而却步...... 我的 Magento Web 上有一些类别,每个类别都有一些产品。我希望它们显示为 4 列计数,但它始终显示为 3 列计数,如下所示:
我已经在我的网站上添加了一些成员(member)跟踪代码。为了使跟踪工作正常进行,我需要向关联公司提供确认付款的网址。 我正在使用Magento,我不确定该版本,但几年内未对其进行更新。我需要知道订单
我们的网站遇到了问题。 系统 > 配置屏幕仅显示菜单、侧面菜单和页脚。当我们点击侧边菜单选项时,屏幕仍然黑屏,相关信息也没有出现。请看 this link .这就是出现的情况。当我们点击任何侧面菜单选
我想只使用一个 csv 文件来翻译前端 Magento 商店。所以我这样做了: 我创建了一个名为 Translator 的自定义模块。在其 config.xml 中,我放置了以下几行: ....
我添加了自定义订单状态选项。 有谁知道我如何通过API将其设置为自定义值? 最佳答案 感谢Diglin为我指出的正确位置。只是为了正确地给出答案: 您可以使用addComment方法来执行此操作,该方
目前,Magento 处理大规模操作的方式存在问题。无论分页如何,它都会返回一些 JS,其中包含当前集合和过滤器的每个 db id。这是为了支持网格标题中的“全选”与“全选可见”选项。当您的记录数量较
如何收集具有此角色的所有角色(系统->权限->角色)和用户? 谢谢。 最佳答案 获得所有角色 $roles = Mage::getModel('admin/roles')->getCol
如果能在我网站的各种应用程序之间进行通用登录,那将是一种巨大的用户体验。现在,我有一个 Magento 店面和一个 IPS 板社区。我正在尝试将它们集成到我的用户的一个通用登录中。 IPS 板提供多种
我正在为 Magento 社区 1.4.2 版中的时尚客户开发一个网站,作为该项目的一部分,我需要一些定制的主页促销块来展示特定产品或产品类别。为此,我想我会编写自己的小部件,并且除了如何处理图像外,
我是一名优秀的程序员,十分优秀!