2013-07-30 55 views
0

我正在尝试使用jquery加载可配置产品的选项以使模板更快。这个想法是显示默认选项并让客户选择他们想要更改的项目。但是,我找不到有关magento模块如何将某些内容返回给jQuery函数的任何指示。有任何想法吗?如何使用jQuery获取magento可配置属性项目

<?php foreach($_attributes as $_attribute): ?> 
     <dt><label class="required"><em>*</em><?php echo $_attribute->getLabel() ?></label></dt> 
     <dd<?php if ($_attribute->decoratedIsLast){?> class="last"<?php }?>> 
      <div class="input-box"> 
       <select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select"> 
        <option><?php echo $this->__('Choose an Option...') ?></option> 
        </select> 
       </div> 
     </dd> 
    <?php endforeach; ?> 

回答

2

所有的项目的选项,在本机的magento,包含在spConfig javascript对象,它的上目录/产品/视图/类型/选项/ configurable.phtml

var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>); 

随着该定义对象,您可以获取所有选项,对于属性使用,spConfig.config.attributes,对于属性ID和代码列表,使用spConfig.config.attributes [“attrId”]。选项,您将获得该属性的选项作为与该选项有关的产品,请将spConfig.config.attributes [“attrId”]。选项输出到控制台,您将得到几个对象,每个对象都包含如下内容:

id 
    "1221" 

label 
    "Gris" 

oldPrice 
    "650" 

price 
    "650" 

products 
    ["1137"] 

ID是属性ID标签是选项标签,oldPrice和价格被用于超级属性,oldPrice是defalt价格和价格是属性的价格,产品是有这个产品的列表属性。

选择每个属性的第一个选项,试试:

<script type="text/javascript"> 
    var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>); 
    for(var i=spConfig.settings.length-1;i>=0;i--) { 
     spConfig.settings[i].selectedIndex = 1; 
    } 
    spConfig.reloadPrice(); 
</script> 
+0

事实上,这是我想改变的文件。如果客户想要选择其他选项,我只想加载这些行(在javascript之前)。但是,我不知道我需要创建一个php文件来获取这些行并加载选项,而无需刷新整个页面。 – FelixR

+0

请检查编辑答案 – changeling

相关问题