Skip to content

Commit

Permalink
magento#16069: Configurable product price is not displayed if all chi…
Browse files Browse the repository at this point in the history
…ldren are out of stock and even if Display Out of Stock Products is set to "yes"
  • Loading branch information
vpodorozh committed Oct 23, 2018
1 parent 207e2e1 commit f4ec67e
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 16 deletions.
5 changes: 3 additions & 2 deletions app/code/Magento/Catalog/Pricing/Render/FinalPriceBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ public function __construct(
*/
protected function _toHtml()
{
if (!$this->salableResolver->isSalable($this->getSaleableItem()) &&
$this->isApplySalableCheck($this->getSaleableItem())) {
if ($this->isApplySalableCheck($this->getSaleableItem()) &&
!$this->salableResolver->isSalable($this->getSaleableItem())
) {
return '';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function build($productId): array
$selects = $this->linkedProductSelectBuilder->build($productId);

foreach ($selects as $select) {
$this->baseSelectProcessor->process($select, $productId);
$this->baseSelectProcessor->process($select, (int)$productId);
}

return $selects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
use Magento\Framework\Pricing\Render\RendererPool;
use Magento\Framework\Pricing\SaleableInterface;
use Magento\Framework\View\Element\Template\Context;
use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\StockStatus;
use Magento\CatalogInventory\Api\StockConfigurationInterface;

/**
* Class FinalPriceBox
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class FinalPriceBox extends \Magento\Catalog\Pricing\Render\FinalPriceBox
{
/**
Expand All @@ -28,9 +32,9 @@ class FinalPriceBox extends \Magento\Catalog\Pricing\Render\FinalPriceBox
private $lowestPriceOptionsProvider;

/**
* @var StockStatus
* @var StockConfigurationInterface
*/
private $stockStatus;
private $stockConfig;

/**
* @param Context $context
Expand All @@ -42,8 +46,9 @@ class FinalPriceBox extends \Magento\Catalog\Pricing\Render\FinalPriceBox
* @param LowestPriceOptionsProviderInterface $lowestPriceOptionsProvider
* @param SalableResolverInterface|null $salableResolver
* @param MinimalPriceCalculatorInterface|null $minPriceCalculator
* @param StockStatus $stockStatus
* @param StockConfigurationInterface|null $stockConfig
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Context $context,
Expand All @@ -55,7 +60,7 @@ public function __construct(
LowestPriceOptionsProviderInterface $lowestPriceOptionsProvider = null,
SalableResolverInterface $salableResolver = null,
MinimalPriceCalculatorInterface $minPriceCalculator = null,
StockStatus $stockStatus = null
StockConfigurationInterface $stockConfig = null
) {
parent::__construct(
$context,
Expand All @@ -68,7 +73,8 @@ public function __construct(
);
$this->lowestPriceOptionsProvider = $lowestPriceOptionsProvider ?:
ObjectManager::getInstance()->get(LowestPriceOptionsProviderInterface::class);
$this->stockStatus = $stockStatus ?: ObjectManager::getInstance()->get(StockStatus::class);
$this->stockConfig = $stockConfig ?:
ObjectManager::getInstance()->get(StockConfigurationInterface::class);
}

/**
Expand All @@ -94,6 +100,6 @@ public function hasSpecialPrice(): bool
*/
protected function isApplySalableCheck(SaleableInterface $salableItem): bool
{
return !$this->stockStatus->isAllChildOutOfStock($salableItem->getId());
return !$this->stockConfig->isShowOutOfStock();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\ConfigurableProduct\Test\Unit\Model\ResourceModel\Product;

use Magento\Framework\DB\Select;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Catalog\Model\ResourceModel\Product\BaseSelectProcessorInterface;
use Magento\ConfigurableProduct\Model\ResourceModel\Product\BaseSelectProcessorInterface;
use Magento\Catalog\Model\ResourceModel\Product\LinkedProductSelectBuilderInterface;
use Magento\ConfigurableProduct\Model\ResourceModel\Product\LinkedProductSelectBuilder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\ConfigurableProduct\Test\Unit\Model\ResourceModel\Product;

use Magento\Framework\DB\Select;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Catalog\Model\ResourceModel\Product\BaseSelectProcessorInterface;
use Magento\ConfigurableProduct\Model\ResourceModel\Product\BaseSelectProcessorInterface;
use Magento\CatalogInventory\Api\StockConfigurationInterface;
use Magento\CatalogInventory\Model\Stock\Status as StockStatus;
use Magento\CatalogInventory\Model\ResourceModel\Stock\Status as StockStatusResource;
Expand All @@ -30,7 +32,7 @@ class StockStatusBaseSelectProcessorTest extends \PHPUnit\Framework\TestCase
/**
* @var StockStatusConfigurableInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $stockStatusConfigurableResourceMock;
private $stockConfigurable;

/**
* @var string
Expand Down Expand Up @@ -60,7 +62,7 @@ protected function setUp()
->method('getMainTable')
->willReturn($this->stockStatusTable);

$this->stockStatusConfigurableResourceMock = $this->getMockBuilder(StockStatusConfigurableInterface::class)
$this->stockConfigurable = $this->getMockBuilder(StockStatusConfigurableInterface::class)
->disableOriginalConstructor()
->getMock();

Expand All @@ -69,7 +71,7 @@ protected function setUp()
[
'stockConfig' => $this->stockConfigMock,
'stockStatusResource' => $this->stockStatusResourceMock,
'stockStatusConfigurableResource' => $this->stockStatusConfigurableResourceMock
'stockConfigurable' => $this->stockConfigurable
]
);
}
Expand All @@ -86,7 +88,7 @@ public function testProcess($isShowOutOfStock, $isAllChildOutOfStock)
->method('isShowOutOfStock')
->willReturn($isShowOutOfStock);

$this->stockStatusConfigurableResourceMock->expects($this->any())
$this->stockConfigurable->expects($this->any())
->method('isAllChildOutOfStock')
->willReturn($isAllChildOutOfStock);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\ConfigurableProduct\Test\Unit\Model\ResourceModel\Product\Type\Configurable;

Expand Down

0 comments on commit f4ec67e

Please sign in to comment.