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.59k stars 9.32k forks source link

Non Dynamic Priced Bundle Products - Selections percentage price calculated as percent of bundle product #39235

Open harrigo opened 2 months ago

harrigo commented 2 months ago

Preconditions and environment

Steps to reproduce

By selection product i'm referring to the child item e.g. a bundle of notepad and pen consisting of 2 simple products where I want to calculate the price based on a percentage of these products price.

Simple Products Notepad - £10 Pen - £1

Bundle Item Notepad Bundle Including Pen (Here we are going to discount the bundle by 10% because we are buying a bundle however would like this to stay up to date with future updated in prices say an increase in the Notepad price causes the bundle price to increase proportionately)

  1. Set bundle item to non dynamic pricing so we can control selection items (Notepad, Pen) with percentage based pricing.
  2. Set bundle price to 0. (This feels to be like an additional charge for the bundle however will price each part of the bundle separately)
  3. Set each selection item to 90 for the percentage giving individual prices for the items of £9 (10 x (90 / 100)) and £0.90 (1 x (90 / 100)) and a total bundle price of £9.90.
  4. Visit product page on frontend price

Expected result

Price should show £9.90 with £9 for the notepad and £0.90 for the pen (90% of the simple products)

This would allow you to create percentage based discounts when purchasing bundles of products together and allows for pricing to stay up to date even with future price increased of the child products.

Actual result

Percentage seems to apply to the bundle product's price. If f I set a price of £10 for the bundle product the selection products with percentage based prices show as £9 when I believe this should show as 90% of the selection products price. I cannot see an example of when you would ever want to set a percentage of a fixed price already set on that page, you could just set a fixed price.

Additional information

I have tested on a vanilla 2.4 and looked at the source and the class Magento/Bundle/Model/Product/Price has not been modified for years and seems to show percent calculated on the bundleProduct:

        if ($bundleProduct->getPriceType() == self::PRICE_TYPE_DYNAMIC) {
            $totalQty = $bundleQty * $selectionQty;
            if (!$takeTierPrice || $totalQty === 0) {
                $totalQty = 1;
            }
            $price = $selectionProduct->getFinalPrice($totalQty);
        } else {
            if ($selectionProduct->getSelectionPriceType()) {
                // percent
                $product = clone $bundleProduct;
                $product->setFinalPrice($this->getPrice($product));
                $this->_eventManager->dispatch(
                    'catalog_product_get_final_price',
                    ['product' => $product, 'qty' => $bundleQty]
                );
                $price = $product->getData('final_price') * ($selectionProduct->getSelectionPriceValue() / 100);
            } else {
                // fixed
                $price = $selectionProduct->getSelectionPriceValue();
            }
        }

When I feel it should be calculated on the child product:

        if ($bundleProduct->getPriceType() == self::PRICE_TYPE_DYNAMIC) {
            $totalQty = $bundleQty * $selectionQty;
            if (!$takeTierPrice || $totalQty === 0) {
                $totalQty = 1;
            }
            $price = $selectionProduct->getFinalPrice($totalQty);
        } else {
            if ($selectionProduct->getSelectionPriceType()) {
                // percent
                $this->_eventManager->dispatch(
                    'catalog_product_get_final_price',
                    ['product' => $selectionProduct, 'qty' => $bundleQty]
                );
                $price = $selectionProduct->getFinalPrice() * ($selectionProduct->getSelectionPriceValue() / 100);
            } else {
                // fixed
                $price = $selectionProduct->getSelectionPriceValue();
            }
        }

This may have always be like this as I had a patch similar to above in place it seemed that didn't get applied however unsure if this is as intended or a bug however does not seem logical to myself to ever have this work in such a way.

Triage and priority

m2-assistant[bot] commented 2 months ago

Hi @harrigo. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce.

m2-assistant[bot] commented 2 months ago

Hi @engcom-Bravo. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-Bravo commented 2 months ago

Hi @harrigo,

Thanks for your reporting and collaboration.

We have verified the issue in Latest 2.4-develop instance and the issue is not reproducible.Kindly refer the screenshots.

Bundleee-Products-Inventory-Catalog-Magento-Admin-10-04-2024_10_11_AM

Screenshot 2024-10-04 at 10 12 06

Price is showing 90% of the child product.

Kindly recheck the issue in Latest 2.4-develop instance and elaborate the steps to reproduce if the issue is still reproducible.

Thanks.

harrigo commented 2 months ago

Thanks for getting back to me so quickly, the screenshots you have provided describes the behaviour I am describing however feel this is wrong.

There is slight confusion of my interpretation of child product (the bundle selection item) and yours where you seem to be referring to the child product as the parent (bundle items) price.

In your screenshots the selection is showing a price for a percentage of the main bundle product. I do not know from your screenshots the price of the child item (with SKU Magento) however I am expecting / feel the percentage should be calculated based on the price of that item rather than the bundle itself.

engcom-Bravo commented 1 month ago

Hi @harrigo,

Thanks for your update.

We have verified the issue in Latest 2.4-develop instance and the Percentage seems to apply to the bundle product's price it seems to be an expected behaviour of magento when we set Dynamic Price to No.

Screenshot 2024-10-24 at 11 48 47 Screenshot 2024-10-24 at 11 41 30 Screenshot 2024-10-24 at 11 41 19

As per Magento devdocs https://experienceleague.adobe.com/en/docs/commerce-admin/catalog/products/types/product-create-bundle#step-5-add-the-bundle-items when we set Dynamic Price to Yes the product price is derived from the price of the individual products included in the bundle.

Thanks.

harrigo commented 1 month ago

Hello,

I understand that with dynamic pricing enabled, Magento combines the prices of individual items in a bundle. However, this approach has its limitations, particularly when it comes to using percentage-based pricing.

When dynamic pricing is turned off, Magento allows for both fixed and percentage-based pricing. While the dev docs cover fixed pricing, they offer little insight into percentage-based pricing in this context, making me question whether its current behavior is intentional, as use cases seem limited.

For example, let's consider a bundle:

Notepad - £10 Pen - £1 With fixed pricing, I can set the bundle price to 0 and charge for the individual products. This approach allows for flexibility such as applying discounts (a common practice when selling bundles) but these discounts will fall out of sync when doing general pricing updates.

When using percentage based pricing, however, setting the bundle price to 0 causes all the product prices to also become 0. To avoid this, I'm forced to add an arbitrary price to the bundle, which then complicates the percentage calculations based on this unrelated bundle price. For instance:

Bundle: £1 Notepad (900%): £9 Pen (100%): £1 Total: £11 Alternatively, I could apply all charges to the bundle itself:

Bundle: £11 Notepad: 0% Pen: 0%

In both scenarios, the percentage-based pricing creates an unnecessary link to the bundle price rather than being a straightforward percentage of the individual product prices.

In my opinion, percentage based pricing should apply to the individual product prices within the bundle, rather than to the overall bundle price. This would reduce complexity and ensure that pricing updates to simple SKU's do not require additional maintenance within bundle products.

I’ve applied a patch to modify this functionality, allowing prices to be adjusted from their original values while maintaining a relationship with the original pricing.

In its current form, percentage-based pricing introduces complexity with little benefit. I also believe that the current "Dynamic Price On/Off" terminology is misleading. Percentage based pricing should logically be part of dynamic pricing, while turning it off should lead to fixed pricing only without percentages.

Kind regards Harri

engcom-Bravo commented 1 month ago

Hi @harrigo,

Thanks for your quick response.

We are Considering this as a improvement to proceed further marking this as a Feature Request.

Thanks.