6

Magento の 1.6 以降のバージョンには未解決のバグがあり、オプションを選択すると、階層価格の割引率がデフォルトで 100% になります。他の貢献者は、product.js を 747 行目あたりから変更することを提案しています。

for (var i = 0; i < this.tierPrices.length; i++) {

することが

for (var i = 0; i > this.tierPrices.length; i++) {

これにより、% 節約の問題は解決されますが、そのコード ブロックは実行されません。私は決して Javascript の専門家ではありませんが、このブロックは、オプションが選択されたときに階層の価格と割引率を更新しているようです。「コメントアウト」するのではなく、問題の根本を見つけたかったのです。

Firebug でのデバッグから、層価格のクラスが product.js で間違っていることに気付きました。そのため、0 の層価格が取得されます。これは、% 節約が常に 100% である理由を説明しています。Firebug は価格を次のように表示します

class="tier-prices product-pricing">   
        Buy 10 for  
        <span class="price">$40.00</span>

一方、product.js は次を使用してオブジェクトを取得しようとしています。

$$('.price.tier-' + i).each(function (el) {

上記を次のように変更すると

$$('.tier-prices .price).each(function (el) {

ティア価格は取得されますが、製品に複数のティア価格がある場合、それらを個別に参照する方法はありません。上記のクラス「price」には、一意の識別子または反復数が宣言されていません。

階層価格の class="price" はどこで宣言されていますか? tierprices.phtml のコードでは、次のようになります。

<?php echo $this->__('Buy %1$s for %2$s each', $_price['price_qty'], $_price['formated_price'])?>
4

2 に答える 2

6

顧客の Magento サイトを 1.7.0.2 にアップグレードした後、本当にバグが発生し始めたので、これに少し時間を費やしました。

これには 2 つの部分があります。場所と修正を記載しますが、これらはアップグレードの証明にはなりません (そのため、ファイルのコピーを作成してテーマ固有のフォルダーに配置することをお勧めしますが、問題のJSファイルで可能かどうかはわかりません)。

1) 修正を表示

ファイル内/design/frontend/base/default/template/catalog/product/view/tierprices.phtml

行を置き換える必要があります32-34

$_product = $this->getProduct();
$_tierPrices = $this->getTierPrices();
$_finalPriceInclTax = $this->helper('tax')->getPrice($_product, $_product->getFinalPrice(), true);

次のコードを使用します。

$_product = $this->getProduct();
$_tierPrices = array();

foreach($this->getTierPrices() as $index => $info) {
    $_tierPrices[$index] = $info;
    $_tierPrices[$index]['formated_price'] = str_replace('class="price"', 'class="price tier-'.$index.'"', $info['formated_price']);
    $_tierPrices[$index]['formated_price_incl_tax'] = str_replace('class="price"', 'class="price tier-'.$index.' tier-'.$index.'-incl-tax"', $info['formated_price_incl_tax']);
}
$_finalPriceInclTax = $this->helper('tax')->getPrice($_product, $_product->getFinalPrice(), true);

これにより、すでに把握していたように、クラスが正しくレンダリングされないという問題が修正されます。ここで私はこのコードを見つけました- すべての問題を修正したわけではありませんが、JS が変更されました。

2)JS修正

ファイル内のjs/Varien/product.js行を置き換える必要があります757-769

$$('.benefit').each(function (el) {
    var parsePrice = function (html) {
        return parseFloat(/\d+\.?\d*/.exec(html));
    };
    var container = $(this.containers[3]) ? this.containers[3] : this.containers[0];
    var price = parsePrice($(container).innerHTML);
    var tierPrice = $$('.price.tier-' + i);
    tierPrice = tierPrice.length ? parseInt(tierPrice[0].innerHTML, 10) : 0;
    var $percent = Selector.findChildElements(el, ['.percent.tier-' + i]);
    $percent.each(function (el) {
        el.innerHTML = Math.ceil(100 - ((100 / price) * tierPrice));
    });
}, this);

これとともに:

//
// Code fixed to prevent the redundant inner loop and to use actual tiered pricing in calculation
// It also takes the optional price variants into consideration (eg: +£2 for a blue tshirt)
// Note: I've made this comment deliberately large, to keep the line numbers in sync
//
var parsePrice = function (html) {
    return parseFloat(/\d+\.?\d*/.exec(html));
};
var container = $(this.containers[3]) ? this.containers[3] : this.containers[0];
var price = parsePrice($(container).innerHTML);
$$('.percent.tier-' + i).each(function (el) {
    el.innerHTML = Math.ceil(100 - ((100 / price) * (this.tierPrices[i] + parseFloat(optionPrices))));
}, this);

これにより、少なくとも 1 人の命が数時間救われることを願っています。

T

于 2013-04-15T18:58:35.693 に答える
0

パーツは、価格がフォーマットされている場合、またはより深いモデル レイヤーで実行されclass="price"た結果です。Mage_Directory_Model_Currency::formatPrecision()$this->formatPrice()Mage::helper('core')->formatPrice();

を拡張 (および書き換え) することで一意の識別子を追加できますが、どこでも使用されてMage_Directory_Model_Currencyいることに注意してください。formatPrecisionそのため、階層価格をフォーマットするための独自のヘルパー/モデル ロジックを作成できます。

于 2013-02-04T20:05:27.897 に答える