2014-05-23 163 views
1

Magento的SCP推广和单选按钮我使用的Magento版本的扩展简单配置的产品(SCP)1.8.1.0可配置产品的

我所试图实现的是具有可配置产品(使用SCP!)那将不同的选项显示为单选按钮而不是下拉(默认)。尽管这听起来很容易,但到目前为止我找不到合适的解决方案(有很多建议,其中没有一个似乎有效)。 我很想在后端解决这个问题,尽管在这一点上,我会同样喜欢工作的前端解决方案。

看起来是什么在configurable.phtml工作吐出了不同的自定义选项,为产品设置,这样的事情:

$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', '#ATTRIBUTENAME#'); 
      foreach ($attribute->getSource()->getAllOptions(true) as $option) { 
       echo /*$option['value'] . ' ' .*/ $option['label'] . "\n"; 
      } 

我能想象这是一个起点,即使我没有想到它通过。

我可以确认为未工作,插件明智的是这两个:

我知道这是一个非常具体的问题,它是一个可能的重复this,但是甚至可能有v1.7的工作解决方案,在v1.8中不再有效,我有一种感觉,这对其他许多人来说可能是非常有趣的。

编辑:只是为了详细说明SCP做了些什么: 它允许你有一个可配置的产品,可以有选择之间的依赖关系。这可以通过为每种可能的选项提供单个产品来实现。这种方式可以使价格上涨,这取决于产品的材料和尺寸。所以一个尺寸可以有不同的价格取决于材料,然后一个新的价格范围,如果尺寸增加。 GitHub网站也提供了一个更好的理解,以防万一,这是令人困惑的。

如果您想安装SCP,请确保安装了回购请求中提供的修复程序。

回答

1

原来这就是我最终使用。它不会更改configurable.phtml或SCP核心代码中的任何代码。相反,我只是调用skin/frontend/base/default/js/scp_product_extension.js来更新选项和价格。这必须发生在客户端,但大多数SCP逻辑显然也是如此。

var sizeselect = $(".catalog-product-view .input-box select").eq(0); 
    var materialselect = $(".catalog-product-view .input-box select").eq(1); 


     function optionsToRadios(element){ 
     var select = element; 

     if (element == materialselect){ 
      $(".radios").append("<div class='secondradiofield'></div>") 
      select.find('option').each(function(j, option){ 
       var option = $(option); 
       var eachval = option.val(); 

       $(".catalog-product-view .secondradiofield").append(
        "<input type='radio' id='s1"+j+"' data-value='"+eachval+"' data-position='"+j+"'/><span><label for='s1"+j+"'>"+option.text()+"</label></span>" 
       ); 

      }); // ende find each 

     } else{ 

      select.find('option').each(function(j, option){ 
       var option = $(option); 
       var eachval = option.val(); 

       $(".catalog-product-view .radios").append(
        "<input type='radio' id='s2"+j+"' data-value='"+eachval+"' data-position='"+j+"'/><span><label for='s2"+j+"'>"+option.text()+"</label></span>" 
       ); 

      }); // end find each 
     } 
    }; 

    // Make first <select> to radios 
    optionsToRadios(sizeselect); 




     /* 
     * 
     * @SCP - seems like the passed element cannot be a jQuery object! 
     * @SCP - spConfig.reloadPrice() is autmatically called by spConfig.configureElement(el). 
     * 
     */ 

     $(document).on("click", ".radios>input[type='radio']", function(){ 

      var val = $(this).attr("data-value"); 
      var index = $(this).attr("data-position"); 
      var select = $(".catalog-product-view .input-box select").eq(0); 

      // deselect other options 
      select.prop("selected", false); 
      select.find("option").removeAttr("selected"); 

      // synch options with <select> 
      var clickedOption = $(select.find("option")[index]); 
      clickedOption.attr("selected", "selected"); 
      clickedOption.prop("selected", true); // IMPORTANT: Firefox need the prop to work! 

      // Make call to SCP to update 
      var el = document.getElementsByClassName("super-attribute-select")[0]; 
      spConfig.configureElement(el); 
      spConfig.reloadPrice(); 

      // Show second <select> as radios 
      if($("input[type='radio']").length < 5){ 
       optionsToRadios(materialselect); 
      } 

      // Deselect other radio buttons 
      $(".radios>input[type='radio']").not($(this)).prop('checked', false); 
     }); 

首先功能刚刚接通缺省<select>元素注入单选按钮。 <select>元素用CSS隐藏,因为我们不希望选项出现两次。接下来是只听收音机按钮上的点击事件,并基本上将点击同步到<select>元素。当select元素发生变化时,您只需调用spConfig.configureElement(el);函数,其中el是相应的<select>元素。

如果第二个<select>元素具有对第一个元素的依赖关系,那么当单击单选按钮时,还必须更新此元素。

希望给别人一个线索,谁试图做同样的事情。

3
+0

感谢您的回复。即使该插件可以很好地用单选按钮代替下拉菜单,但它也不能保持SCP工作的功能,这在这种情况下至关重要。 – BenMann

+0

我明白了,您需要自定义一个它们。您需要自定义其中的一个模块 –