Magento产品页面选项选择器 - 添加自定义选择文本,同时删除"Incl Tax"



所以我试图将两个解决方案合并在一起形成一个…我一直在使用这个答案中的代码从可配置产品的产品页面选项选择器中删除"(包括税)",它工作得很好。如链接答案所示,在app/design/frontend/rwd/myTheme/template/catalog/product/view/type/configurable中。我修改了

<script type="text/javascript">
var spConfig = new Product.Config(<?php echo $this->getJsonConfig(); ?>);
</script>

到下面:

<?php // get current drop down string
$currentstring = $this->getJsonConfig();
// create new string with true set to false using str_replace function (string replace)
$newstring = str_replace( '"showBothPrices":true,"','"showBothPrices":false,"', $currentstring );?>
 <!-- render dropdown but with new var ($newstring) -->
 <script type="text/javascript">
 var spConfig = new Product.Config(<?php echo $newstring ?>);
</script>

这是隐藏(包括税)的预期结果,让我很高兴。

后来,有人问我是否可以将选择框中的文本从"选择一个选项"改为"选项名称"或"选择(选项名称):"

我找到了下面这个完美的答案——它用

替换了相同文件的全部内容
<?php
$_product    = $this->getProduct();
$_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes());?>
<?php if ($_product->isSaleable() && count($_attributes)):?>
<dl>
<?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">
            <?php $chooseText = $this->__('Select %s', $_attribute->getLabel()); ?>
            <select data-choose-text="<?php echo $chooseText; ?>" name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select">
                <option><?php echo $chooseText; ?></option>
            </select>
          </div>
    </dd>
<?php endforeach; ?>
</dl>
<script type="text/javascript">
    Product.ConfigDefaultText = new Class.create(Product.Config, {
        fillSelect: function($super, element) {
            $super(element);
            var chooseDefaultText = element.getAttribute('data-choose-text');
            $(element).options[0] = new Option(chooseDefaultText, '');
        }
    });
    var spConfig = new Product.ConfigDefaultText(<?php echo $this->getJsonConfig() ?>);
</script>

现在效果很好,我们可以把选项标签设置成任何我们喜欢的东西,但在这个过程中,我们的"(包括税)"回来了,毁了我的一天。

我正在寻找有人告诉我如何我可以合并这两个代码位,并使他们很好地发挥在一起,所以我可以有两个自定义产品选项文本,并防止"(包括税)"字符串出现。

任何帮助都非常感谢。

找到我自己的解决方案:

首先,废弃第一个答案中的代码,使用第二个答案中的代码,然后更改您的变量/configurable.js(或者为了更好的形式,创建一个覆盖的版本),如下所示:

   var str = option.label;
    if(price){
        if (this.taxConfig.showBothPrices) {
             //CHANGE THIS
            //str+= ' ' + this.formatPrice(excl, true) + ' (' + this.formatPrice(price, true) + ' ' + this.taxConfig.inclTaxTitle + ')';
           // TO THIS:
           str+= ' ' + this.formatPrice(price, true);
        } else {
            str+= ' ' + this.formatPrice(price, true);
        }
    }
    return str;

最新更新