Magento2: Issue : Upgrade Magento 2.1.0 to 2.1.4 "out of stock" product main price changed to $0.00

Created on 21 Feb 2017  Â·  25Comments  Â·  Source: magento/magento2

I have referred https://github.com/magento/magento2/issues/7908 this issue also.

Getting issue on product view page,
All products (upsell, related, recently viewed) prices are changed to $0.00 on out of stock product.

Cannot Reproduce Clear Description Format is not valid

Most helpful comment

This is not new problem, it was in old version too, just some classes were renamed.
To fix need add 1 line in file vendor/magento/module-configurable-product/Pricing/Price/ConfigurablePriceResolver.php

    /**
     * @param \Magento\Framework\Pricing\SaleableInterface|\Magento\Catalog\Model\Product $product
     * @return float|null
     */
    public function resolvePrice(\Magento\Framework\Pricing\SaleableInterface $product)
    {
        $price = null;

        foreach ($this->lowestPriceOptionsProvider->getProducts($product) as $subProduct) {
            $productPrice = $this->priceResolver->resolvePrice($subProduct);
            $price = $price ? min($price, $productPrice) : $productPrice;
        }

        /* fix >>> */
        $price = $price ?: $product->getData('price');
        /* <<< fix */

        return $price === null ? null : (float)$price;
    }
  • OR override virtual type, where Vendor\Module\Fix\ConfigurablePriceResolver path to copy of class with fix (overriding)
    <virtualType name="ConfigurableFinalPriceResolver" type="Vendor\Module\Fix\ConfigurablePriceResolver">
        <arguments>
            <argument name="priceResolver" xsi:type="object">Magento\ConfigurableProduct\Pricing\Price\FinalPriceResolver</argument>
        </arguments>
    </virtualType>
<?php
namespace Vendor\Module\Fix;

class ConfigurablePriceResolver implements \Magento\ConfigurableProduct\Pricing\Price\PriceResolverInterface
{
  ....
    /**
     * @param \Magento\Framework\Pricing\SaleableInterface|\Magento\Catalog\Model\Product $product
     * @return float|null
     */
    public function resolvePrice(\Magento\Framework\Pricing\SaleableInterface $product)
    {
        $price = null;

        foreach ($this->lowestPriceOptionsProvider->getProducts($product) as $subProduct) {
            $productPrice = $this->priceResolver->resolvePrice($subProduct);
            $price = $price ? min($price, $productPrice) : $productPrice;
        }

        /* fix >>> */
        $price = $price ?: $product->getData('price');
        /* <<< fix */

        return $price === null ? null : (float)$price;
    }
}

All 25 comments

I have also the same problem.

If "display out of stock products" is enabled and a configurable product has all its simple products out of stock, then the price of the configurable product is 0.

Same here. Did you find any workaround?

Anyone know if there is any fix on this?

We have the same problem here. Updated to 2.1.4 from 2.1.2 and all Out Of Stock Products show as 0.00.

This is not new problem, it was in old version too, just some classes were renamed.
To fix need add 1 line in file vendor/magento/module-configurable-product/Pricing/Price/ConfigurablePriceResolver.php

    /**
     * @param \Magento\Framework\Pricing\SaleableInterface|\Magento\Catalog\Model\Product $product
     * @return float|null
     */
    public function resolvePrice(\Magento\Framework\Pricing\SaleableInterface $product)
    {
        $price = null;

        foreach ($this->lowestPriceOptionsProvider->getProducts($product) as $subProduct) {
            $productPrice = $this->priceResolver->resolvePrice($subProduct);
            $price = $price ? min($price, $productPrice) : $productPrice;
        }

        /* fix >>> */
        $price = $price ?: $product->getData('price');
        /* <<< fix */

        return $price === null ? null : (float)$price;
    }
  • OR override virtual type, where Vendor\Module\Fix\ConfigurablePriceResolver path to copy of class with fix (overriding)
    <virtualType name="ConfigurableFinalPriceResolver" type="Vendor\Module\Fix\ConfigurablePriceResolver">
        <arguments>
            <argument name="priceResolver" xsi:type="object">Magento\ConfigurableProduct\Pricing\Price\FinalPriceResolver</argument>
        </arguments>
    </virtualType>
<?php
namespace Vendor\Module\Fix;

class ConfigurablePriceResolver implements \Magento\ConfigurableProduct\Pricing\Price\PriceResolverInterface
{
  ....
    /**
     * @param \Magento\Framework\Pricing\SaleableInterface|\Magento\Catalog\Model\Product $product
     * @return float|null
     */
    public function resolvePrice(\Magento\Framework\Pricing\SaleableInterface $product)
    {
        $price = null;

        foreach ($this->lowestPriceOptionsProvider->getProducts($product) as $subProduct) {
            $productPrice = $this->priceResolver->resolvePrice($subProduct);
            $price = $price ? min($price, $productPrice) : $productPrice;
        }

        /* fix >>> */
        $price = $price ?: $product->getData('price');
        /* <<< fix */

        return $price === null ? null : (float)$price;
    }
}

Lifesaver @SKovbel

I've found the root cause of this issue. In 2.1.3/4 a new file has been added Magento\Catalog\Model\ResourceModel\Product\CompositeBaseSelectProcessor This adds stock data to the select, specifically the where clause which now only returns products if the item is in stock. This is the reason why the product's price shows as 0. If you remove the stock_status from $this->baseSelectProcessors you will find the query will return correctly.

This has been done to fix an issue where the base price for a configurable could be incorrect if, for example you had an option for $5 and an option for $10, but the lowest value was out of stock. The price would always show as $5 even though the option was out of stock so you could only select the $10 option. However the downside to this is that if all items are out of stock you won't get any id's returned to be able to get pricing.

@SKovbel Fix does work but doesn't include any tax.

I fixed it via the following module https://github.com/WeareJH/m2-core-bug-oos-price-fix as most stores we work with don't have different pricing for their configurable options.

Thanks @SKovbel!

Thanks @SKovbel
works perfect!
But can't get it working with more that one currency. Switching from SEK to US results in
"As low as €110.00 " which is correct. But 1000€ is not converted from 1000SEK.
Any ideas?

Thanks so much!
screen shot 2017-06-02 at 11 43 43

screen shot 2017-06-02 at 11 36 34

Thx, also got this issue...

I am using magento 2.1.9 and the solution of @SKovbel did not work ! Can anyone help me to implement it? Thx

Also have the same issue as @JackNorm. Fix of @SKovbel works for single-currency stores.

Actually, I fixed it:

Instead of

$price = $price ?: $product->getData('price');

try

$price = $price ?: $this->priceCurrency->convert($product->getData('price'));

CC @sebfie @JackNorm

On magento 2.1.9, fix from @SKovbel works (only 1 currency store, including tax, so it's ok).

A bit out of scope, but i'm confused and surprised of all those small regressions from Magento 1.9 to Magento 2.x, on front and backoffice.
I know it's a complete framework change but so many improvements for 1.x seems vanished. and so many time to be fixed. :(

@aasim110 why did you close this? I just upgraded to 2.1.9 and the bug is still there. Even with the fix, this issue should remain open so the @magento-engcom-team can resolve this without the use of a third party module. Seems like something that should be addressed by core functionality. Unless, there is a core fix and I can't find it because most of the fixes posted by Magento don't include links to the code that was changed :-/

@aasim110, thank you for your report.
We were not able to reproduce this issue by following the steps you provided. If you'd like to update it, please reopen the issue.
We tested the issue on 2.1.10, 2.2.1

This isn't working for me on 2.2.2. Is there an updated workaround, @SKovbel?

@skilar It looks like this has been fixed I am on 2.2.2 if product is "out of stock" and the setting is set to show if out of stock then the price remains. However this isn't the case 2.1.7 and it need the fix.

@magento-engcom-team This is reproducible on 2.2.5, the price of simple products changed to zero if it's out of stock and the setting is set to show out of stock.

cc @lano-vargas

@magento-engcom-team @nntoan @lano-vargas any updates ?

We were not able to reproduce this issue. If you'd like to reopen it, please provide obvious steps to reproduce.
1

This is not new problem, it was in old version too, just some classes were renamed.
To fix need add 1 line in file vendor/magento/module-configurable-product/Pricing/Price/ConfigurablePriceResolver.php

    /**
     * @param \Magento\Framework\Pricing\SaleableInterface|\Magento\Catalog\Model\Product $product
     * @return float|null
     */
    public function resolvePrice(\Magento\Framework\Pricing\SaleableInterface $product)
    {
        $price = null;

        foreach ($this->lowestPriceOptionsProvider->getProducts($product) as $subProduct) {
            $productPrice = $this->priceResolver->resolvePrice($subProduct);
            $price = $price ? min($price, $productPrice) : $productPrice;
        }

        /* fix >>> */
        $price = $price ?: $product->getData('price');
        /* <<< fix */

        return $price === null ? null : (float)$price;
    }
  • OR override virtual type, where Vendor\Module\Fix\ConfigurablePriceResolver path to copy of class with fix (overriding)
    <virtualType name="ConfigurableFinalPriceResolver" type="Vendor\Module\Fix\ConfigurablePriceResolver">
        <arguments>
            <argument name="priceResolver" xsi:type="object">Magento\ConfigurableProduct\Pricing\Price\FinalPriceResolver</argument>
        </arguments>
    </virtualType>
<?php
namespace Vendor\Module\Fix;

class ConfigurablePriceResolver implements \Magento\ConfigurableProduct\Pricing\Price\PriceResolverInterface
{
  ....
    /**
     * @param \Magento\Framework\Pricing\SaleableInterface|\Magento\Catalog\Model\Product $product
     * @return float|null
     */
    public function resolvePrice(\Magento\Framework\Pricing\SaleableInterface $product)
    {
        $price = null;

        foreach ($this->lowestPriceOptionsProvider->getProducts($product) as $subProduct) {
            $productPrice = $this->priceResolver->resolvePrice($subProduct);
            $price = $price ? min($price, $productPrice) : $productPrice;
        }

        /* fix >>> */
        $price = $price ?: $product->getData('price');
        /* <<< fix */

        return $price === null ? null : (float)$price;
    }
}

I tried to do the overide but I keep getting

atal error: Uncaught Error: Cannot instantiate interface Magento\ConfigurableProduct\Pricing\Price\PriceResolverInterface in /example.com/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:50 Stack trace: #0 /example.com/vendor/magento/framework/ObjectManager/ObjectManager.php(70): Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create('Magento\\Configu...') #1 /example.com/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(144): Magento\Framework\ObjectManager\ObjectManager->get('Magento\\Configu...') #2 /example.com/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(230): Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgument(Array, 'Magento\\Configu...', NULL, 'priceResolver', 'Magento\\Configu...') #3 /example.com/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(34): Magento\Framework\ObjectManager\Factory\AbstractFa in /example.com/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php on line 50

I am running 2.2.5 of Magento, any advice?

Facing same issue with Magento CE2.3.2. Is this fixed with newer version or is still there?

I'm having the same issue in the "Recently Viewed Products" widget.

This is not new problem, it was in old version too, just some classes were renamed.
To fix need add 1 line in file vendor/magento/module-configurable-product/Pricing/Price/ConfigurablePriceResolver.php

    /**
     * @param \Magento\Framework\Pricing\SaleableInterface|\Magento\Catalog\Model\Product $product
     * @return float|null
     */
    public function resolvePrice(\Magento\Framework\Pricing\SaleableInterface $product)
    {
        $price = null;

        foreach ($this->lowestPriceOptionsProvider->getProducts($product) as $subProduct) {
            $productPrice = $this->priceResolver->resolvePrice($subProduct);
            $price = $price ? min($price, $productPrice) : $productPrice;
        }

        /* fix >>> */
        $price = $price ?: $product->getData('price');
        /* <<< fix */

        return $price === null ? null : (float)$price;
    }
  • OR override virtual type, where Vendor\Module\Fix\ConfigurablePriceResolver path to copy of class with fix (overriding)
    <virtualType name="ConfigurableFinalPriceResolver" type="Vendor\Module\Fix\ConfigurablePriceResolver">
        <arguments>
            <argument name="priceResolver" xsi:type="object">Magento\ConfigurableProduct\Pricing\Price\FinalPriceResolver</argument>
        </arguments>
    </virtualType>
<?php
namespace Vendor\Module\Fix;

class ConfigurablePriceResolver implements \Magento\ConfigurableProduct\Pricing\Price\PriceResolverInterface
{
  ....
    /**
     * @param \Magento\Framework\Pricing\SaleableInterface|\Magento\Catalog\Model\Product $product
     * @return float|null
     */
    public function resolvePrice(\Magento\Framework\Pricing\SaleableInterface $product)
    {
        $price = null;

        foreach ($this->lowestPriceOptionsProvider->getProducts($product) as $subProduct) {
            $productPrice = $this->priceResolver->resolvePrice($subProduct);
            $price = $price ? min($price, $productPrice) : $productPrice;
        }

        /* fix >>> */
        $price = $price ?: $product->getData('price');
        /* <<< fix */

        return $price === null ? null : (float)$price;
    }
}

Any chance you woulf know how to do the same for Bundled Prodcuts that have a sub product out of stock. It shows Price as 0,00 Magento 2.3.4 Any help appreciated!

Was this page helpful?
0 / 5 - 0 ratings