【发布时间】:2016-09-08 08:45:15
【问题描述】:
所以我试图将两种解决方案合并在一起形成一个.. 我一直在使用this answer 中的代码从可配置产品的产品页面选项选择器中删除“(含税)”,并且效果很好。 如链接答案所示,在 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>
这有隐藏(含税)的预期结果,让我很开心。
后来,有人问我是否可以将选择框中的文本从“选择一个选项”更改为选项名称或“选择(选项名称):”
我发现 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>
现在这很好用,我们可以将选项标签设置为我们喜欢的任何内容,但在此过程中,我们的“(含税)”返回毁了我的一天。
我正在找人来告诉我如何合并这两个代码并让它们很好地协同工作,这样我就可以同时拥有自定义产品选项文本并防止“(含税)”字符串出现。
非常感谢任何帮助。
【问题讨论】:
标签: magento magento-1.9