【问题标题】:add string to displayed price in magento将字符串添加到magento中显示的价格
【发布时间】:2013-08-30 22:21:59
【问题描述】:

我正在尝试在 Magento 的显示价格中添加一个简单的字符串。目前,价格默认显示为 $##.##。我希望它阅读:价格:$##.##

对显示价格的简单搜索将我带到了 template/catalog/product/price.phtml。当涉及变量时,此文件似乎控制价格显示。 IE,价格含税,不含税,特价等...

不涉及变量时,哪个文件控制显示价格,默认价格:

<span class="price">$##.##</span>

一旦我确定了它的位置,我相信我可以在显示的价格之前附加一个简单的字符串。

提前致谢。

【问题讨论】:

  • 是同一个文件,只是尽量不要迷失在if-else语句中。应该有价格没有附加文本的情况
  • "这是同一个文件,只是尽量不要迷失在 if-else 语句中。"这完全有可能正在发生。这很令人沮丧。
  • 我会以快速而肮脏的方式来做...Javascript。为您的价格找到一个通用选择器并使用它来添加文本
  • 我被警告不要在这里走捷径,因为 magento 是...敏感的。我一直在搜索 price.phtml 文件,但没有找到涵盖价格默认显示的案例,我错过了什么?该文件中的每个案例都涵盖了没有出现在前端的 html id 的特殊案例。至少可以说我很困惑。

标签: php magento


【解决方案1】:

好的。我在 cmets 中建议不要迷失在 if-else 声明中,但我也只是做了几分钟。终于找到了。
在这个 if 语句中

<?php if ($_finalPrice >= $_price): ?>

还有一个if

<?php if ($_taxHelper->displayBothPrices()): ?>

在最后一个ifelse 声明中,有您正在寻找的部分。

            <?php if ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($_product, 0)): // including ?>
                <span class="regular-price" id="product-price-<?php echo $_id ?><?php echo $this->getIdSuffix() ?>">
                    <?php echo $_coreHelper->currency($_price + $_weeeTaxAmount, true, true) ?>
                </span>
            <?php elseif ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($_product, 1)): // incl. + weee ?>
                <span class="regular-price" id="product-price-<?php echo $_id ?><?php echo $this->getIdSuffix() ?>">
                    <?php echo $_coreHelper->currency($_price + $_weeeTaxAmount, true, true) ?>
                </span>
                <span class="weee">(
                    <?php foreach ($_weeeTaxAttributes as $_weeeTaxAttribute): ?>
                        <?php echo $_weeeSeparator; ?>
                        <?php echo $_weeeTaxAttribute->getName(); ?>: <?php echo $_coreHelper->currency($_weeeTaxAttribute->getAmount(), true, true); ?>
                        <?php $_weeeSeparator = ' + '; ?>
                    <?php endforeach; ?>
                    )</span>
            <?php elseif ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($_product, 4)): // incl. + weee ?>
                <span class="regular-price" id="product-price-<?php echo $_id ?><?php echo $this->getIdSuffix() ?>">
                    <?php echo $_coreHelper->currency($_price + $_weeeTaxAmount, true, true) ?>
                </span>
                <span class="weee">(
                    <?php foreach ($_weeeTaxAttributes as $_weeeTaxAttribute): ?>
                        <?php echo $_weeeSeparator; ?>
                        <?php echo $_weeeTaxAttribute->getName(); ?>: <?php echo $_coreHelper->currency($_weeeTaxAttribute->getAmount() + $_weeeTaxAttribute->getTaxAmount(), true, true); ?>
                        <?php $_weeeSeparator = ' + '; ?>
                    <?php endforeach; ?>
                    )</span>
            <?php elseif ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($_product, 2)): // excl. + weee + final ?>
                <span class="regular-price"><?php echo $_coreHelper->currency($_price,true,true) ?></span><br />
                <?php foreach ($_weeeTaxAttributes as $_weeeTaxAttribute): ?>
                    <span class="weee">
                        <?php echo $_weeeTaxAttribute->getName(); ?>: <?php echo $_coreHelper->currency($_weeeTaxAttribute->getAmount(), true, true); ?>
                    </span>
                <?php endforeach; ?>
                <span class="regular-price" id="product-price-<?php echo $_id ?><?php echo $this->getIdSuffix() ?>">
                    <?php echo $_coreHelper->currency($_price + $_weeeTaxAmount, true, true) ?>
                </span>
            <?php else: ?>
                <span class="regular-price" id="product-price-<?php echo $_id ?><?php echo $this->getIdSuffix() ?>">
                    <?php if ($_finalPrice == $_price): ?>
                        <?php echo $_coreHelper->currency($_price, true, true) ?>
                    <?php else: ?>
                        <?php echo $_coreHelper->currency($_finalPrice, true, true) ?>
                    <?php endif; ?>
                </span>
            <?php endif; ?>

此代码中的每个部分都显示正常价格,具体取决于税收设置。很可能您只需要最后一部分。

<?php if ($_finalPrice == $_price): ?>
    <?php echo $_coreHelper->currency($_price, true, true) ?>
<?php else: ?>
    <?php echo $_coreHelper->currency($_finalPrice, true, true) ?>
<?php endif; ?>

【讨论】:

  • 试一试。我会告诉你的!
【解决方案2】:

我在 magento 1.8 上,在几乎普通的系统上开发,调试时,我在

                 <?php if ($_finalPrice == $_price): ?>
                    <?php echo $_coreHelper->currency($_price, true, true) ?>
                <?php else: ?>
                    <?php echo $_coreHelper->currency($_finalPrice, true, true) ?>
                <?php endif; ?>

绕行 201 行

【讨论】:

  • 正好在第 201 行。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多