Magento 2

Magento 2's Hidden Pricing Glitch: Why Your Bundle Product Discounts Are Showing Too Early (and How to Fix It)

As e-commerce migration experts at Shopping Mover, we constantly monitor the pulse of the Magento community, identifying critical insights that can impact your store's performance and customer experience. Today, we're shedding light on a significant bug concerning Magento 2 bundle products and their special prices – an issue that could be silently undermining your pricing strategy and customer trust.

The Mystery of the Premature Discounts

Imagine setting up a compelling special price for a bundle product, carefully scheduling it to begin next week. You expect your customers to see the regular price until then. However, a widespread Magento 2 bug, identified in GitHub issue #41862, reveals a different reality: your category pages might already be displaying the discounted price, while the product page correctly shows the full price. This inconsistency, a classic example of a "what you see is not what you get" scenario, can lead to customer confusion, abandoned carts, and a damaged brand reputation.

This issue isn't new or isolated; it has been reproduced on Magento 2.4-develop, 2.4.6-p15, and even Mage-OS 4.0.0 (which is based on 2.4.9). Whether your price indexer is set to "Update on Save" or "Update by Schedule," the problem persists, indicating a fundamental flaw in how bundle product special prices are indexed.

Steps to Reproduce the Issue:

  1. Create a bundle product with price type "Fixed," a regular price (e.g., 100), and assign it to a category.
  2. In Advanced Pricing, set a Special Price (e.g., 50% for bundles) and schedule it with a "Special Price From" date in the future (e.g., tomorrow) and a "Special Price To" date further in the future (e.g., in 10 days).
  3. Save the product, then run bin/magento indexer:reindex catalog_product_price, and flush the cache.
  4. Open the category page where the bundle product is listed, then navigate to the product page itself.

Expected Result: Both the category page and the product page should display the regular price (100) with no strike-through, as the special price hasn't started yet.

Actual Result: The category page incorrectly shows the product at 50 with 100 struck through, implying a discount. The product page, however, correctly displays 100 with no discount. This discrepancy is due to the catalog_product_index_price table already containing the discounted final_price / min_price for the bundle on category listings.

The same inconsistency occurs in reverse: if a special price has expired (empty "Special Price From" and "Special Price To" in the past), the expired discount might still appear in the index, misleading customers.

A screenshot showing a Magento 2 category page with a bundle product incorrectly displaying a future special price, while the product page shows the correct regular price.

Unpacking the Technical Glitch: A SQL Operator Misunderstanding

The core of this problem lies deep within Magento's price indexing logic for bundle products. Specifically, the culprit is a misinterpretation of SQL operator precedence in the Magento\Bundle\Model\ResourceModel\Indexer\Price::prepareBundlePriceByType() method. The condition responsible for checking special price date ranges is constructed as follows:

$specialFromExpr = "{$specialFrom} IS NULL OR {$specialFromDate} <= {$currentDate}";
$specialToExpr = "{$specialTo} IS NULL OR {$specialToDate} >= {$currentDate}";
$specialExpr = "{$specialPrice} IS NOT NULL AND {$specialPrice} > 0 AND {$specialPrice} < 100"
  . " AND {$specialFromExpr} AND {$specialToExpr}";

As highlighted in the GitHub issue, both $specialFromExpr and $specialToExpr contain an OR operator. When these expressions are concatenated into $specialExpr without proper parentheses, and considering that SQL's AND operator has higher precedence than OR, the database evaluates the condition incorrectly. It essentially interprets the logic as:

(price checks AND from IS NULL)
OR (from_date <= today AND to IS NULL)
OR (to_date >= today)

This means that any bundle product whose special_to_date is in the future will incorrectly get the special price applied in the index, regardless of whether its special_from_date has arrived. This is a classic logical error that can have significant business implications.

Why Simple Products Aren't Affected

Interestingly, the simple product indexer doesn't suffer from this flaw. Its `BaseFinalPrice` logic correctly wraps both parts of the date range check in parentheses, ensuring proper SQL evaluation:

"{$specialPrice} IS NOT NULL AND ({$specialFromExpr}) AND ({$specialToExpr})"

This comparison clearly illustrates the missing piece in the bundle product indexing logic.

The Business Impact: More Than Just a Display Error

While this might seem like a minor display bug, its implications for your e-commerce business are far-reaching:

  • Customer Confusion & Frustration: Customers seeing a discounted price on a category page, only to find a higher price on the product page, will feel misled. This erodes trust and can lead to abandoned carts.
  • Damaged Brand Reputation: Inconsistent pricing signals a lack of attention to detail and professionalism, negatively impacting your brand image.
  • Misaligned Marketing Efforts: If you're running marketing campaigns based on scheduled discounts, this bug can cause your promotions to appear prematurely, confusing customers and potentially wasting ad spend.
  • Operational Inefficiencies: Merchants might spend unnecessary time investigating why their pricing isn't working as expected, diverting resources from more critical tasks.
A flowchart illustrating the incorrect SQL operator precedence in Magento 2 bundle product pricing indexer and its corrected version.

The Solution: A Simple Yet Crucial Fix

The good news is that the fix for this issue is straightforward, involving the addition of parentheses to enforce the correct SQL operator precedence. The proposed change is:

--- a/app/code/Magento/Bundle/Model/ResourceModel/Indexer/Price.php
+++ b/app/code/Magento/Bundle/Model/ResourceModel/Indexer/Price.php
@@ -248,5 +248,5 @@
         $specialFromExpr = "{$specialFrom} IS NULL OR {$specialFromDate} <= {$currentDate}";
         $specialToExpr = "{$specialTo} IS NULL OR {$specialToDate} >= {$currentDate}";
         $specialExpr = "{$specialPrice} IS NOT NULL AND {$specialPrice} > 0 AND {$specialPrice} < 100"
-            . " AND {$specialFromExpr} AND {$specialToExpr}";
+            . " AND ({$specialFromExpr}) AND ({$specialToExpr})";
 
         return $specialExpr;

By simply adding parentheses around {$specialFromExpr} and {$specialToExpr}, the SQL query will correctly evaluate the date range conditions, ensuring that special prices are only applied within their designated start and end dates.

Real-World Verification

This fix has been successfully applied to a live Magento 2.4.6 store with approximately 500 bundle products. Before the patch, a handful of bundles with scheduled special prices exhibited the incorrect discount on category pages. After applying the fix and reindexing, both category and product pages displayed consistent pricing for all bundles, with only the index rows of the affected bundles changing. This confirms the efficacy and targeted nature of the solution.

What Merchants Should Do

If your Magento 2 store utilizes bundle products with scheduled special prices, we strongly recommend taking the following steps:

  • Check Your Store: Verify if your category pages are prematurely displaying discounts for bundle products with future special price start dates or expired special prices.
  • Prioritize Updates: Ensure your Magento 2 installation is up-to-date. This bug has been reported across several 2.4.x versions, and keeping your platform current is crucial for security and stability.
  • Consult Experts: For complex Magento 2 environments or if you're unsure about applying patches, engage with experienced Magento developers or migration experts like Shopping Mover. We can safely implement such fixes, perform thorough testing, and ensure your store's integrity.
  • Thorough Testing: After any patch or update, always perform comprehensive testing, especially for pricing, checkout flows, and product displays.

Shopping Mover: Your Partner in Magento 2 Excellence

At Shopping Mover, we specialize in Magento migrations, development, and ongoing support. Our deep understanding of Magento's architecture, including its indexing mechanisms and pricing logic, allows us to identify and resolve critical issues like this. Whether you're planning a migration to Adobe Commerce, need assistance with complex integrations, or require expert development to optimize your store's performance, our team is equipped to ensure your e-commerce platform runs flawlessly and delivers an exceptional customer experience.

Conclusion

Accurate pricing is fundamental to building customer trust and maintaining a healthy e-commerce business. The Magento 2 bundle product pricing bug, while subtle, can significantly impact your store's credibility and profitability. By understanding its technical roots and applying the necessary fix, you can ensure that your special prices are displayed precisely when and where they should be, providing a consistent and trustworthy shopping experience for your customers. Stay vigilant, stay updated, and partner with experts to keep your Magento store performing at its best.

Share:

Start with the tools

Explore migration tools

See options, compare methods, and pick the path that fits your store.

Explore migration tools