Magento 产品页面选项 select 或 - 添加自定义 select 文本,同时删除 "Incl Tax"
Magento product page options selector - adding custom select text, while removing "Incl Tax"
所以我试图将两个解决方案合并在一起形成一个..
我一直在使用 this answer 中的代码从产品页面选项 select 或可配置产品中删除“(含税)”,并且效果很好。
如链接答案所示,在 app/design/frontend/rwd/myTheme/template/catalog/product/view/type/configurable.phtml 中我更改了行
<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>
这达到了隐藏(含税)的预期结果,让我很高兴。
后来,有人问我是否可以将 select 框中的文本从阅读 "Choose an option" 更改为选项名称或 "Select (option name):"
我发现 the following answer 完美运行 - 它用
替换了同一文件的完整内容
<?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>
现在效果很好,我们可以将选项标签设置为我们喜欢的任何内容,但在此过程中我们的“(含税)”返回毁了我的一天。
我正在找人告诉我如何合并这两段代码并使它们很好地协同工作,这样我就可以同时拥有自定义产品选项文本并防止“(含税)”字符串来自出现。
非常感谢任何帮助。
找到我自己的解决方案:
首先,废弃第一个答案中的代码,使用第二个答案中的代码,然后更改 varien/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;
所以我试图将两个解决方案合并在一起形成一个.. 我一直在使用 this answer 中的代码从产品页面选项 select 或可配置产品中删除“(含税)”,并且效果很好。 如链接答案所示,在 app/design/frontend/rwd/myTheme/template/catalog/product/view/type/configurable.phtml 中我更改了行
<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>
这达到了隐藏(含税)的预期结果,让我很高兴。
后来,有人问我是否可以将 select 框中的文本从阅读 "Choose an option" 更改为选项名称或 "Select (option name):"
我发现 the following answer 完美运行 - 它用
替换了同一文件的完整内容<?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>
现在效果很好,我们可以将选项标签设置为我们喜欢的任何内容,但在此过程中我们的“(含税)”返回毁了我的一天。
我正在找人告诉我如何合并这两段代码并使它们很好地协同工作,这样我就可以同时拥有自定义产品选项文本并防止“(含税)”字符串来自出现。
非常感谢任何帮助。
找到我自己的解决方案:
首先,废弃第一个答案中的代码,使用第二个答案中的代码,然后更改 varien/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;