簡體   English   中英

Magento:bundle.js中的“ Bug”層級定價,用於“捆綁產品”上的“配置價格”

[英]Magento: Tier Pricing 'Bug' in bundle.js for “Price as Configured” on Bundle products

在弄清楚如何獲取捆綁包頁面的“已配置價格”部分來更新層級定價方面有些困難。

現在,如果我在捆綁產品中有一個復選框選擇,然后單擊該復選框將其添加到捆綁中,則“配置價格”會更新為產品的全價,而不是層級定價(商品的默認數量)選擇范圍內的價格)。

現在,我正在瀏覽/skin/frontend/base/default/js/bundle.js文件,並在selectionPrice方法下看到以下內容:

selectionPrice: function(optionId, selectionId) {

.................

    if (this.config.priceType == '0') {
        price = this.config.options[optionId].selections[selectionId].price;
        tierPrice = this.config.options[optionId].selections[selectionId].tierPrice;

        for (var i=0; i < tierPrice.length; i++) {
            if (Number(tierPrice[i].price_qty) <= qty && Number(tierPrice[i].price) <= price) {
                price = tierPrice[i].price;
            }
        }
    } else {
        selection = this.config.options[optionId].selections[selectionId];
        if (selection.priceType == '0') {
            price = selection.priceValue;
        } else {
            price = (this.config.basePrice*selection.priceValue)/100;
        }
    }

到目前為止,我可以說它涉及到設置:

price = this.config.options[optionId].selections[selectionId].price

現在,通常,如果tierPrice返回一個對象,則它應該能夠遍歷該對象並找到層價格(至少這是代碼似乎應該執行的操作)。 但是,它永遠不會進入實際上會設置分級價格的for循環。 在控制台中,我可以通過執行以下操作直接訪問分層價格:

bundle.config.options['301'].selections['1066'].tierPrice['32000-5']

但是,Magento代碼取決於能否調用..... tierPrice [0]而不是.... tierPrice ['32000-5']來獲取每個單獨的定價對象。 調用.... tierPrice [0]返回未定義,而tierPrice.length返回未定義。

為什么不能使用for循環訪問嵌套數組? 我在這里有什么選擇?

謝謝!

作為基於JavaScript的解決方案的替代方案,不幸的是,該解決方案需要替換核心文件bundle.js我有一個基於PHP的解決方案

首先,問題是該對象根本不應該是對象。 我們可以干預JSON生成,並確保它實際上是一個數組。

為此,必須使用以下方法重寫來重寫類Mage_Catalog_Model_Product_Type_Price

public function getTierPrice($qty = null, $product)
{
    $tierPrice = parent::getTierPrice($qty, $product);
    if (is_array($tierPrice)) {
        return array_values($tierPrice);
    }
    return $tierPrice;
}

getTierPrice()方法未在任何地方使用,據我所知,字符串鍵是相關的,因此與將生成的JSON分開並重新創建它相比,它更優雅。

我寫了一個擴展程序,將其與另一個捆綁包層定價錯誤一起修復,您可以從https://github.com/sgh-it/bundletierprices獲得

進一步閱讀: http : //www.schmengler-se.de/zh/2014/10/magento-buendelprodukte-staffelpreise-der-einfachen-produkte-nutzen/

我主要使用Magento 1.7和:

[跳到下面的更新以獲取我的答案。 摘要: 我們學到了什么? 我認為您正在使用Magento 1.5。 但是即使是Magento 1.7也不夠好。 在Magento 1.8之前,您嘗試使用的功能尚未完全修復。 ]

我開始在這里為您提供幫助,因為我知道使用捆綁軟件可能會非常復雜。 我沒有使用分層定價,因此我在開發服務器上進行了設置,並開始逐步瀏覽上面列出的bundle.js函數。

我發現使我感到困惑的兩件事:

a)我的tierPrice[] 一個索引為0,1,2的數組(我通過Magento管理員設置了三層): tierPrice對象是一個數組對象

在這里為您提供幫助的是我的捆綁JSON對象定義的摘錄,即來自app/design/frontend/themename/default/template/bundle/catalog/product/view/type/bundle/bundle.phtml

 <script type="text/javascript">
  //<![CDATA[
      var bundle = new Product.Bundle(<?php echo $this->getJsonConfig() ?>);
  //]]>
 </script>

片段:

var bundle = new Product.Bundle({"options":{"837":{"selections":{"4205":{"qty":1,"customQty":"1","price":52,"priceInclTax":52,"priceExclTax":52,"priceValue":0,"priceType":"0","tierPrice":[{"price_id":"4","website_id":"0","all_groups":"1","cust_group":32000,"price":29.99,"price_qty":"2.0000","website_price":"29.9900"},{"price_id":"5","website_id":"0","all_groups":"1","cust_group":32000,"price":18.88,"price_qty":"3.0000","website_price":"18.8800"},{"price_id":"6","website_id":"0","all_groups":"1","cust_group":32000,"price":7.77,"price_qty":"4.0000","website_price":"7.7700"}], ...

你看起來像這樣嗎?

b)因此,在上面的for循環之后,在我的開發服務器上, bundle.js正確地識別了一個層級價格, 但是在代碼的后面,可變價格根據顯示的含稅價或不含稅價重新設置,即以下代碼:

//file: skin/frontend/theme/default/js/bundle.js
//function: selectionPrice()
//...
selection = this.config.options[optionId].selections[selectionId];
if (selection.priceInclTax !== undefined) {
    priceInclTax = selection.priceInclTax;
    price = selection.priceExclTax !== undefined ? selection.priceExclTax : selection.price;
} else {
    priceInclTax = price;
}
//...

因此,最后,我的“配置價格”也最終不正確

你怎么看? 您能找出為什么您的bundle對象使用tierPrice['32000-5']而不是tierPrice[0]嗎? bundle.js嘗試應用含稅或不含稅的顯示價格時,您的層級價格是否會被覆蓋?

(而且似乎沒有默認方法可以知道tierPrice是含稅還是不含稅。我在這里聞到一個錯誤)。

實際上,您可能會對此錯誤報告感興趣。 http://www.magentocommerce.com/bug-tracking/issue?issue=11477 (需要登錄)],並且在層級定價跟蹤了一些其他錯誤,這些錯誤將有助於解釋Magento 1.8中的代碼更新

更新:我一直在指Magento 1.7中的bundle.js

我可以看到在Magento 1.8中,bundle.js進行了改進,以考慮到tierPrice和tierPrice包括和不含稅-但這還必須附帶一個不同的bundle JSON對象(以保存tierPrice[i].priceInclTax;的字段和值tierPrice[i].priceInclTax;tierPrice[i].priceExclTax;

因此,我們現在可能會有一個答案:

a)升級到Magento 1.8

要么

b)使用來自bundle.js Magento 1.8的代碼以及 JSON對象的文件'app / core / Mage / Bundle / Block / Catalog / Product / View / Type / Bundle.php中手動更新主題的bundle.js 。 ',在1.7至1.8之間進行檢查,

Magento 1.7

//file app/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle.php
//class Mage_Bundle_Block_Catalog_Product_View_Type_Bundle
//function getJsonConfig()
//...
                $tierPrices = $_selection->getTierPrice();
                foreach ($tierPrices as &$tierPriceInfo) {
                    $tierPriceInfo['price'] = $coreHelper->currency($tierPriceInfo['price'], false, false);
                }
                unset($tierPriceInfo); // break the reference with the last element
//...

Magento的1.8

//file app/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle.php
//class Mage_Bundle_Block_Catalog_Product_View_Type_Bundle
//function getJsonConfig()
//...
                $tierPrices = $_selection->getTierPrice();
                foreach ($tierPrices as &$tierPriceInfo) {
                    $tierPriceInfo['price'] = $coreHelper->currency($tierPriceInfo['price'], false, false);
                    $tierPriceInfo['priceInclTax'] = $taxHelper->getPrice($_selection, $tierPriceInfo['price'], true);
                    $tierPriceInfo['priceExclTax'] = $taxHelper->getPrice($_selection, $tierPriceInfo['price']);
                }
                unset($tierPriceInfo); // break the reference with the last element
//...

因此,如果您手動更新舊版本的Magento,則需要擴展類Mage_Bundle_Block_Catalog_Product_View_Type_Bundle並使用此更新的getJsonConfig()創建自己的新bundle.php

我沒有在1.7和1.8的這些文件之間運行差異,這值得一看,看看是否有其他變化。

所有這些都假定您可以深入了解為什么擁有tierPrice ['32000-5']的原因,因此,如上所述,將我的bundle JSON對象聲明與您的包進行比較,或者將您的包JSON對象聲明粘貼到這里供其他人檢查。

我們學到了什么? 我認為您正在使用Magento 1.5。 但是即使是Magento 1.7也不夠好。 在Magento 1.8之前,您嘗試使用的功能尚未完全修復。

馬拉奇。

這是我回答自己的問題!

所以我弄清楚了為什么它不起作用。 Magento代碼嘗試使用以下方法遍歷對象:

var(i=0;i<object.length;i++)

這不適用於對象。 我更改了代碼以在selectionPrice:function(optionId,selectionId)方法中使用for(對象中的鍵)遍歷對象:

if (this.config.priceType == '0') {
        price = this.config.options[optionId].selections[selectionId].price;
        tierPrice = this.config.options[optionId].selections[selectionId].tierPrice;

        // Ensures that tierPrice is set 
        // If a selection has no tier pricing it would return an empty array

        if (tierPrice.length != 0){

        // Iterate through tier Pricing until you reach correct quantity break
        // then set price.    

        for (key in tierPrice){
          if (tierPrice.hasOwnProperty(key)){
            if(tierPrice[key].price_qty <= qty && tierPrice[key].price <= price) {
                price = tierPrice[key].price;

            }
        }
        }
        }

然后,在方法的底部,您需要輸入條件tierPrice.length == 0,否則您的層級定價將再次被覆蓋:

// Check that priceInclTax AND tierPrice are not set
    if (selection.priceInclTax !== undefined && tierPrice.length == 0) {

        priceInclTax = selection.priceInclTax;
        price = selection.priceExclTax !== undefined ? selection.priceExclTax : selection.price;

    }

    else {
        priceInclTax = price;
    }

這似乎對我有用,因為它現在可以成功更新“已配置價格”以說明層級定價,並且仍然可以成功更新所有其他定價。 如果您的Magento商店具有weee模塊/稅收規則,則可能會引起大驚小怪,但是對於我的商店配置而言,它的效果很好。

希望有幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM