【问题标题】:Show Price Range for Configurable Products Magento显示可配置产品 Magento 的价格范围
【发布时间】:2013-04-20 19:36:58
【问题描述】:

我在我的 1.7 Magento 上使用 Simple Configurable Products 扩展 (http://www.magentocommerce.com/magento-connect/simple-configurable-products.html),一切似乎都运行良好。我唯一想更改的是在类别页面上显示价格范围,而不是“价格来源”。换句话说:

这就是我现在拥有的可配置产品:

价格来自:$[最便宜的相关产品的价格]

这就是我想要展示的:

$[最便宜的相关产品的价格] - $[最贵的相关产品的价格]

如果你能推荐如何修改这个扩展而不是核心文件,那就更好了,但任何解决方案都将不胜感激。

P.S.:我在 Stack Overflow 和 Magento 论坛上阅读了大量关于此的主题,但似乎没有人为此找到可靠的解决方案。

【问题讨论】:

    标签: php magento magento-1.7


    【解决方案1】:

    这对我来说听起来很有趣,所以我决定尝试一下。

    我通过修改文件让它工作:
    app/code/community/OrganicInternet/SimpleConfigurableProducts/Catalog/Product/Price.php
    (为了理智,将其复制到 code/local/... 目录树;D)

    由于您不想要实际的“Price From:”文本,您可以注释掉这些行:

    if ($product->getMaxPossibleFinalPrice() != $product->getFinalPrice()) {
        $extraHtml .= $this->__('Price From:');
    }
    


    现在这里是有趣的地方。我基本上是通过更改这一行来复制他们自己的插入方法:

    return substr_replace($priceHtml, $extraHtml, strpos($priceHtml, $htmlToInsertAfter)+strlen($htmlToInsertAfter),0);
    

    进入这些行:

    $finalHtml = substr_replace($priceHtml, $extraHtml, strpos($priceHtml, $htmlToInsertAfter)+strlen($htmlToInsertAfter),0);
    
    if ($product->getMaxPossibleFinalPrice() != $product->getFinalPrice()) {
    
        $finalPriceHtml = ' - $' . strval(number_format($product->getMaxPossibleFinalPrice(),2,'.',','));
        $finalPriceInsertAfter = strval(number_format($product->getFinalPrice(),2,'.',','));
    
        $finalHtml = substr_replace($finalHtml, $finalPriceHtml, strpos($finalHtml, $finalPriceInsertAfter)+strlen($finalPriceInsertAfter),0);
    }
    return $finalHtml;
    

    基本上复制了他们插入配置价格标签的原始方法,但这次在默认价格之后插入了最高价格。但是,它不适用于多币种商店,您必须抓住商店货币运营商并根据使用的货币更改 number_format。您可能可以使用内置的货币格式方法,但我不熟悉它,因为我没有在多货币商店工作过。

    试一试,如果有任何问题,请告诉我。

    【讨论】:

    • 不得不将上面的代码从使用 round() 更改为 number_format()。当产品价格为整数时(5.00 美元对 5.98 美元),round() 会导致插入问题。
    猜你喜欢
    • 1970-01-01
    • 2011-06-26
    • 1970-01-01
    • 2013-05-18
    • 2012-07-20
    • 2015-11-25
    • 1970-01-01
    • 2013-11-03
    • 2013-01-15
    相关资源
    最近更新 更多