Magento2: Catalog price rule applied configurable products not show oldPrice in product list

Created on 30 Nov 2016  路  21Comments  路  Source: magento/magento2


Preconditions


  1. Magento 2.1.2
  2. PHP 7.0.11

Steps to reproduce

  1. Create a price rule and apply it (for ex. 15% discount)

Expected result

  1. Listing working fine with simple products
    screenshot at nov 30 15-26-47
  2. Same as simples, show both final and old price for configurable products

Actual result

  1. Old price not shown for configurable products
    screenshot at nov 30 15-29-44

Tax needs update bug report

Most helpful comment

Hi, Line 22 in the the file: vendormagentomodule-configurable-productviewbasetemplatesproductpricefinal_price.phtml

I replaced This: <?php if (!$block->isProductList() && $block->hasSpecialPrice()): ?>
With this: <?php if ($block->hasSpecialPrice()): ?>

From onepack, if you want the old price to show in product page (when the swatches are not selected)
Remove the css styling of the "old-price" line 32 (remove everything and leave the old-price class and now it will show on the product page.

hope it helps. someone

All 21 comments

Hi, I cannot reproduce this issue. Please add more details to your description of the steps you followed when identifying this issue.

@olysenko It just classical usage of catalog price rules.

  • Create a rule based on attribute set
  • Apply it.

rule_attribute_set

Actually rule is working on all type of products.
For simples, discounted prices shown on all areas (listing, search, view etc..)
But configurables, just shown on product view page.

It may be about with price renderer in $block->getProductPrice(). Because in listing, for configurables, magento gets lowest child's price.

I'm investigating this.

In addition it may be related with #6080
Our configurables prices are 0. Catalog price calculating by totals of selected attributes (child prices).

Additional Info:

After some investigation, i think find a clue
Clean install 2.1.2 with sample-data via composer.

  • Create a catalog rule which looks like our original one and apply it. (Attribute set based)
    scr1
  • It is working well with same price children 馃憤
    scr2
    scr3

  • But if change price of any child
    scr4

  • It shows lowest price as expected but regular price gone same as our situation
    scr5

  • But in product view discount shown. So catalog rule applied all children, not only parent (as expected).
    scr6

I hope it will help to solve this.

Hi, after your las comment update I was able to reproduce issue on clear Magento installation with sample data. Your price index is invalid after price was changed. In case your have setting for indexers UPDATE BY SCHEDULE in menu System->Tools->Index Management. You have to setup cron with indexers reindex job. Or use UPDATE ON SAVE mode for indexers. In this case it will reindex price on product save. Please tell me if my comment was helpful for you.

Hi @olysenko,
All indexes are update by schedule and crond working fine. Also check database while running reindex. I have verified the calculation is correct and products got discounted price.

This issue just about showing oldPrice in frontend. Not about rule applying or other.
Product special price did not set for minimal price (lowest price of child products) so final_price.html don't know how about showing price ($block->hasSpecialPrice() in final_price.phtml returns false).

I did some trick to override it (Magento_Catalog/templates/product/price/final_price.phtml) :
line around 20

if($block->getSaleableItem()->getTypeId()==MagentoConfigurableProductModelProductTypeConfigurable::TYPE_CODE)
{
/* ex: MagentoCatalogPricingPriceConfiguredPrice */
/
* @var MagentoFrameworkPricingPricePriceInterface $priceModel */
$priceModel = $block->getPriceType('configured_price');
}

and line around 32
if($finalPriceModel->getAmount()->getValue()<$priceModel->getAmount()->getValue())
$block->getSaleableItem()->setSpecialPrice($finalPriceModel->getAmount()->getValue());
if ($block->hasSpecialPrice()): ?>

Hi @rbostan, so we need to synchronize our steps. My steps with no bug you can find below:

  1. Clean install 2.1.2 with sample-data
  2. Set all Indexes mode to UPDATE BY SCHEDULE in menu System->Tools->Index Management
  3. Add task to crontab to execute every 1 minute
  4. * * * * /usr/bin/php {magento2ce}/bin/magento indexer:reindex
  5. Create a catalog rule which looks like our original one and apply it. (Attribute set Top). Discount 20% from original price
  6. Go to front-end. Open category Women->Tops->Bras & Tanks
    All configurable products have two prices actual minimal price and regular price.
    For example, product "Breathe-Easy Tank" two prices available: $27.20 and Regular Price $34.00
  7. Change for any simple product "Breathe-Easy Tank" price to 20$
  8. Refresh category Women->Tops->Bras & Tanks
    One price is shown $20.00 for product "Breathe-Easy Tank"
  9. Wait 1 minute until indexes will be updated by cron
  10. Refresh category Women->Tops->Bras & Tanks
    Two prices are shown $16.00 and Regular Price $20.00 for product "Breathe-Easy Tank"
    What is your result after these steps? Do you have another sequence of steps?

According to contributor guide, tickets without response for two weeks should be closed.
If this issue still reproducible please feel free to create the new one: format new issue according to the Issue reporting guidelines: with steps to reproduce, actual result and expected result and specify Magento version.

I have the exact same issue on a project that has migrated data from a magento 1 store.
The products are assigned later to the configurable product not on the go while creating the configurable product.
When I apply a special price on a simple product or apply a catalog price rule the old price just never shows just the new discounted price and so it is not clear for a customer that this is a special/ discounted price.
This happens in the grids and on a product detail page.
Only when I click a color option in the detail page the display of the price box gets updated with the text "regular: xx,xx" under the new "special price".

This is on a magento 2.1.6 install on a development environment and a production environment with PHP 7.

@veloraven this is weird.
I noticed it in more clear reproducible bug-cases. Some moderators seem eager to close them when the 2-week-deadline is reached.
It is understandable that tickets cannot be open all the time but when there is a clear bug it seems to me that solving this to make magento better has more importance than this guideline.
I'm now having the exact same issue and have to create a whole new case while this case could already be solved or at least updated by me and maybe others.

@rbostan can you provide the final price file content? I don't know what to replace or override. thanks in advance!

Hi, Line 22 in the the file: vendormagentomodule-configurable-productviewbasetemplatesproductpricefinal_price.phtml

I replaced This: <?php if (!$block->isProductList() && $block->hasSpecialPrice()): ?>
With this: <?php if ($block->hasSpecialPrice()): ?>

From onepack, if you want the old price to show in product page (when the swatches are not selected)
Remove the css styling of the "old-price" line 32 (remove everything and leave the old-price class and now it will show on the product page.

hope it helps. someone

@joebordo overwrite provided by @rbostan doesn't work on 2.1.7.

I overwrote like this:

<?php
/** @var \Magento\Catalog\Pricing\Render\FinalPriceBox $block */

$productId = $block->getSaleableItem()->getId();

if ($block->getSaleableItem()->getTypeId()==\Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE) {

/** ex: \Magento\Catalog\Pricing\Price\ConfiguredPrice /

/* @var \Magento\Framework\Pricing\Price\PriceInterface $priceModel */

$priceModel = $block->getPriceType('configured_price');

} else {

/** ex: \Magento\Catalog\Pricing\Price\RegularPrice */
/** @var \Magento\Framework\Pricing\Price\PriceInterface $priceModel */
$priceModel = $block->getPriceType('regular_price');
}


/** ex: \Magento\Catalog\Pricing\Price\FinalPrice */
/** @var \Magento\Framework\Pricing\Price\PriceInterface $finalPriceModel */
$finalPriceModel = $block->getPriceType('final_price');
$idSuffix = $block->getIdSuffix() ? $block->getIdSuffix() : '';
$schema = ($block->getZone() == 'item_view') ? true : false;
?>
<?php 
if ($finalPriceModel->getAmount()->getValue() < $priceModel->getAmount()->getValue())

$block->getSaleableItem()->setSpecialPrice($finalPriceModel->getAmount()->getValue());

if ($block->hasSpecialPrice()): ?>
..............
..............
.............

@gediminaskv It worked form me on 2.1.7
@joebordo I want to copy this file and put it in my custom theme. What path should I use?

@joebordo Thanks it works for me!

Someone know how can I change "was" for "old price" ?

Sorry to reopen and drag this but im having the same issue on a magento 2.2 with migration data. ive tried the method mentioned by @joebordo but doesnt seem to work as no old price is showing.

Any advice would be much appreciated.

I have also tried the method mentioned by @joebordo with Magento 2.2.4 but doesnt seem to work as no old price is showing.

Any advice would be much appreciated.

Hi, Line 22 in the the file: vendormagentomodule-configurable-productviewbasetemplatesproductpricefinal_price.phtml

I replaced This: <?php if (!$block->isProductList() && $block->hasSpecialPrice()): ?>
With this: <?php if ($block->hasSpecialPrice()): ?>

From onepack, if you want the old price to show in product page (when the swatches are not selected)
Remove the css styling of the "old-price" line 32 (remove everything and leave the old-price class and now it will show on the product page.

hope it helps. someone

I found that this solution works for me on 2.2.6, now old prices are showing for configurable products in the catalog, hower this causes a new bug, on product pages the old price is initially shown for a second or 2 and then disappears in a flash :(. When selecting an option it goes back to displaying but that was always like that. Seems like there is some Ajax rewriting the price after the fact on the product page.

======edit:
found a fix for the bug created by the joebordo fix: https://github.com/magento/magento2/issues/8670

Hi, Line 22 in the the file: vendormagentomodule-configurable-productviewbasetemplatesproductpricefinal_price.phtml
I replaced This: <?php if (!$block->isProductList() && $block->hasSpecialPrice()): ?>
With this: <?php if ($block->hasSpecialPrice()): ?>
From onepack, if you want the old price to show in product page (when the swatches are not selected)
Remove the css styling of the "old-price" line 32 (remove everything and leave the old-price class and now it will show on the product page.
hope it helps. someone

I found that this solution works for me on 2.2.6, now old prices are showing for configurable products in the catalog, hower this causes a new bug, on product pages the old price is initially shown for a second or 2 and then disappears in a flash :(. When selecting an option it goes back to displaying but that was always like that. Seems like there is some Ajax rewriting the price after the fact on the product page.

======edit:
found a fix for the bug created by the joebordo fix: #8670

@brampta What fix did you find for the bug created by the joebordo fix? I'm on 2.2.3 and I get the old price to flash for a second and then it is replaced with the sale price. So the sale price is displayed and the Original Price, also displays the sale price.

I am on 2.3.4 and both prices show up after the fix described above. However, I only have special price on some variants of the configurable product, and the old prices show up for all variations. As a result, I have Old price 99EUR new price 99EUR which looks like I am trying to fool my customer. Is there a fix for that?

Was this page helpful?
0 / 5 - 0 ratings