magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.56k stars 9.32k forks source link

Magento 2.3.4 swatch-render-js _getNewPrices does not return correct tierPrice data for variations #28042

Closed gaiterjones closed 4 years ago

gaiterjones commented 4 years ago

Preconditions (*)

  1. Magento 2.3.4 / 2.3.5-p1
  2. Configurable product with swatch enabled variations

Steps to reproduce (*)

  1. Open a configurable product page with swatch variation products that have tier pricing
  2. Click on the lowest priced variation swatch image

Expected result (*)

  1. Tier pricing for variation displayed

Actual result (*)

  1. No tier pricing displayed

swatch-render.js has a new _getNewPrices function called from _UpdatePrice when swatch image clicked.

        _getNewPrices: function () {
            var $widget = this,
                optionPriceDiff = 0,
                allowedProduct = this._getAllowedProductWithMinPrice(this._CalcProducts()),
                optionPrices = this.options.jsonConfig.optionPrices,
                basePrice = parseFloat(this.options.jsonConfig.prices.basePrice.amount),
                optionFinalPrice,
                newPrices;

            if (!_.isEmpty(allowedProduct)) {
                optionFinalPrice = parseFloat(optionPrices[allowedProduct].finalPrice.amount);
                optionPriceDiff = optionFinalPrice - basePrice;
            }

            if (optionPriceDiff !== 0) {
                newPrices  = this.options.jsonConfig.optionPrices[allowedProduct];
            } else {
                newPrices = $widget.options.jsonConfig.prices;
            }

            return newPrices;
        },

if optionPriceDiff is zero no option data (including tier pricing) is returned resulting in no tier pricing being displayed.

Assuming basePrice here is the lowest price of the variation product, tier prices for the lowest priced variation product will never be displayed because the optionPriceDiff calculation of optionFinalPrice (min parent product price) minus basePrice (lowest price of option) are the same and will be zero.

if basePrice is the lowest option price then tier prices of the options should also be checked to calculate the actual lowest option price. Alternatively a simple check for option tier price data should be performed instead of the optionPriceDiff.

e.g.

            if (!_.isEmpty(allowedProduct)) {

                if (optionPrices[allowedProduct].tierPrices && optionPrices[allowedProduct].tierPrices.length)
                {
                    // get baseprice from tiers
                    //
                    _.each(optionPrices[allowedProduct].tierPrices, function (tierPrice) {
                        //console.log ('TIER='+tierPrice.price);
                        tierPrices.push(parseFloat(tierPrice.price));
                    });

                    basePrice = tierPrices.slice().sort(function(a,b) {
                        return a - b;
                    }).shift();

                } else {
                    basePrice = parseFloat(this.options.jsonConfig.prices.basePrice.amount);
                }

                optionFinalPrice = parseFloat(optionPrices[allowedProduct].finalPrice.amount);
                optionPriceDiff = optionFinalPrice - basePrice;
            }
m2-assistant[bot] commented 4 years ago

Hi @gaiterjones. Thank you for your report. To help us process this issue please make sure that you provided the following information:

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, please, review the Magento Contributor Assistant documentation.

@gaiterjones do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?


gaiterjones commented 4 years ago

@magento give me 2.4-develop instance

magento-engcom-team commented 4 years ago

Hi @gaiterjones. Thank you for your request. I'm working on Magento 2.4-develop instance for you

magento-engcom-team commented 4 years ago

Hi @gaiterjones, here is your Magento instance. Admin access: https://i-28042-2-4-develop.instances.magento-community.engineering/admin_caf5 Login: 14afe72d Password: 6a766da55ee8 Instance will be terminated in up to 3 hours.

mrtuvn commented 4 years ago

@gaiterjones I have seen quite a lot open PR around this topic (tier price) for both backend and frontend. Not sure it's can solve your problem Filter with component: ConfigurableProduct

One open PR for server rendering swatch and also other fixes :)

gaiterjones commented 4 years ago

@mrtuvn thanks for your comments. I will close this due to lack of interest. I have implemented my own fix using the code I posted above.