【问题标题】:Magento and decimels in the cart购物车中的 Magento 和小数
【发布时间】:2013-04-26 11:44:22
【问题描述】:

我更改了 magento 中的一些函数以去除价格中的小数。 该解决方案似乎适用于没有选项的简单产品,但有选项的产品在选择选项时仍显示 .00。具有讽刺意味的是,该选项的下拉菜单显示了该选项的额外成本,但没有小数位,但选择该选项的主要价格仍显示小数位。这可以在js文件中吗?可配置的.js 有 reloadOldPrice() 方法我试图转储它,但价格变量总是 0 有什么想法吗?

【问题讨论】:

    标签: magento


    【解决方案1】:

    新编辑

    我以前的代码确实行不通。我测试了以下,它的工作原理:

    // Wrap original reloadPrice function
    spConfig.reloadPrice = spConfig.reloadPrice.wrap(function(original){
        // Call original reloadPrice() function
        original();
    
        // Get the DOM-element that contains the price
        var priceSpan = $('product-price-'+this.config.productId).down();
    
        // Get the current value
        var oldP = priceSpan.innerHTML;
    
        // Change the value
        var newP = oldP.sub('.00','');
    
        // Update the element
        priceSpan.update(newP);
    });
    

    在 Magento 中,spConfig 对象定义为 var spConfig = new Product.Config(...);,因此请务必在 spConfig 实例化后添加我在此处提供的代码。

    还有很多工作要做:

    我建议将 var line newP = oldP.sub('.00',''); 更改为也可以捕获 ,00 的内容,因为在某些语言环境中这将是价格格式。

    此外,例如,如果您选择显示包含不含税的价格,上述代码将不起作用,因为$('product-price-'+this.config.productId).down() 将包含两个元素(我认为)。

    如果您更愿意将代码附加到 configurable.js 文件中,您应该像这样附加它:

    Product.Config.prototype.reloadPrice = Product.Config.prototype.reloadPrice.wrap(...); 
    

    (请注意我在第一个答案中忘记的 .prototype)。


    旧帖子(不起作用)

    如果人们想知道为什么它不起作用,首先它应该是 Product.Config.prototype.formatPrice 而不是 Product.Config.formatPrice,其次,formatPrice 函数显然不负责价格 html被输出。

    configurable.js还有一个函数formatPrice,大概在价格更新的时候调用。

    所以你可以试试:

    Product.Config.formatPrice = Product.Config.formatPrice.wrap(function(originalFormatPrice, price, showSign) {
        var str = originalFormatPrice(price, showSign);
        return str.slice(0, -3); // remove last three characters (.00)
    });
    

    【讨论】:

    • 我犯了一些错误,我用一个工作示例编辑了答案。
    【解决方案2】:
    **Go your price.phtml file**
    

    第 201 行

    <?php echo $_coreHelper->currency($_price, true, true) ?>
    
    replace this code
    
    <?php $_prix = $_coreHelper->currency($_price,true,true) ?>
    <?php $_prix = str_replace(".00", "", $_prix); ?>
    <?php echo $_prix ?>
    

    【讨论】:

    • in price.phtml $_prix 已经没有小数点了。选择某些产品选项时出现小数点
    • 找到您的位置添加产品选项以了解使用此功能的价格。
    【解决方案3】:

    尝试使用免费扩展ET Currency Manager。在这个扩展中实现了这个功能。

    【讨论】:

      猜你喜欢
      • 2012-12-28
      • 1970-01-01
      • 1970-01-01
      • 2013-05-22
      • 2014-10-30
      • 1970-01-01
      • 1970-01-01
      • 2015-07-06
      • 2014-11-03
      相关资源
      最近更新 更多