【问题标题】:Magento move currency symbol out of span for microformatsMagento 将货币符号移出微格式的范围
【发布时间】:2013-10-30 16:28:53
【问题描述】:

我正在开发 Magento 1.7.0.2 和

app\design\frontend\default\default\template\catalog\product\price.phtml 

第 201 行(ish)是

 <?php echo $_coreHelper->currency($_price, true, true) ?>

生成代码:

<span class="price">£100.00</span>

由于货币符号在跨度中,因此在微格式中出现错误。因此,我希望价格看起来相同,但将货币符号从跨度中取出,使其看起来像:

£<span class="price">100.00</span>

我该怎么做? $_coreHelper->currency($_price, true, true) 在做什么?

【问题讨论】:

    标签: magento microformats


    【解决方案1】:

    $_coreHelper->currency($_price, true, true) 在做什么?

    /**
     * Convert and format price value for current application store
     *
     * @param   float $value
     * @param   bool $format
     * @param   bool $includeContainer
     * @return  mixed
     */
    public static function currency($value, $format = true, $includeContainer = true)
    

    即添加货币符号并将其包含在 &lt;span class="price"&gt;&lt;span&gt; 中,因此如果您使用 $_coreHelper->currency($_price, true, false) 您将获得相同的价格而不使用 &lt;span class="price"&gt;

    如果需要使用£&lt;span class="price"&gt;100.00&lt;/span&gt;

     <?php echo Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol(); ?>
    <span class="price"><?php echo $price ?></span>
    

    &lt;?php echo $_price ?&gt; - 不是你的代码的最终版本,你需要格式化它但没有货币符号,你可以阅读它on Magento SE topic - how to get price without currency symbol

    喜欢

    Mage::getModel('directory/currency')->format(
        $product->getFinalPrice(), 
        array('display'=>Zend_Currency::NO_SYMBOL), 
        false
    );
    

    【讨论】:

    • 在阅读了您的解释后,我这样做了,这似乎更简单?然后你的货币 php 代码 - currency($_price, false, false) ?>
    • 您还可以使用 .price::before{} 通过 css 动态内容插入货币价值。
    • @albert - 这很好。它将保存重新格式化现在超出 css 样式类价格的所有 £。我去看看
    • 我明白了。即使您不想接受,我也会作为答案回复
    • getPrice(), 2); ?> 下面插入 alberts css 货币
    【解决方案2】:

    您可以使用 :before,:after 将货币字符添加为动态内容,并通过 content="" 插入它的字符;像这样:

    
    .price{position:relative; text-align:center; outline:1px solid #000; width:200px; height:60px}
    .price:before,.price::before{content:'£'; position:absolute; z-index:12; font-size:50px; left:0; top:0; width:200px; height:60px; text-align:left}
    .price:after,.price::after{}  
    

    我做了一个快速的小提琴来展示它http://jsfiddle.net/jalbertbowdenii/7MDH5/2/

    【讨论】:

    • 相当极端的例子!我刚刚使用了 - .price:before,.price::before{content:'\00A3';} jsfiddle.net/7MDH5/3 不确定 :before 和 ::before 之间的区别,我可能必须使课程更具体到我的页面,所以它不会出现在我不想要的网站上,但是谢谢!
    • 是的,css 解决方案对我来说是最好的解决方案,因为磅符号的 css 与其匹配的价格相同,因此副作用更少。谢谢。 [developer.mozilla.org/en-US/docs/Web/CSS/::before] CSS 3 中引入了 ::before 符号,以区分伪类和伪元素。浏览器也接受符号 :before 在 CSS 2 中引入。
    • 使用 css 会丢失货币标签,因此需要类似 的东西。然后关闭它什么的。
    猜你喜欢
    • 1970-01-01
    • 2012-01-29
    • 1970-01-01
    • 2014-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-29
    相关资源
    最近更新 更多