Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 14050fa

Browse files
author
Dmytro Voskoboinikov
committed
MAGETWO-72582: Configurable product displays the price of "out of stock" configuration
1 parent 348a897 commit 14050fa

File tree

6 files changed

+72
-76
lines changed

6 files changed

+72
-76
lines changed

app/code/Magento/ConfigurableProduct/Model/Product/Pricing/Renderer/SalableResolver.php

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\ConfigurableProduct\Plugin\Catalog\Model\Product\Pricing\Renderer;
7+
8+
use Magento\ConfigurableProduct\Pricing\Price\LowestPriceOptionsProviderInterface;
9+
10+
/**
11+
* A plugin for a salable resolver.
12+
*/
13+
class SalableResolver
14+
{
15+
/**
16+
* @var LowestPriceOptionsProviderInterface
17+
*/
18+
private $lowestPriceOptionsProvider;
19+
20+
/**
21+
* @param LowestPriceOptionsProviderInterface $lowestPriceOptionsProvider
22+
*/
23+
public function __construct(
24+
LowestPriceOptionsProviderInterface $lowestPriceOptionsProvider
25+
) {
26+
$this->lowestPriceOptionsProvider = $lowestPriceOptionsProvider;
27+
}
28+
29+
/**
30+
* Performs an additional check whether given configurable product has
31+
* at least one configuration in-stock.
32+
*
33+
* @param \Magento\Catalog\Model\Product\Pricing\Renderer\SalableResolver $subject
34+
* @param bool $result
35+
* @param \Magento\Framework\Pricing\SaleableInterface $salableItem
36+
*
37+
* @return bool
38+
*
39+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
40+
*/
41+
public function afterIsSalable(
42+
\Magento\Catalog\Model\Product\Pricing\Renderer\SalableResolver $subject,
43+
$result,
44+
\Magento\Framework\Pricing\SaleableInterface $salableItem
45+
) {
46+
if ($salableItem->getTypeId() == 'configurable' && $result) {
47+
if (!$this->lowestPriceOptionsProvider->getProducts($salableItem)) {
48+
$result = false;
49+
}
50+
}
51+
52+
return $result;
53+
}
54+
}

app/code/Magento/ConfigurableProduct/etc/di.xml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,7 @@
206206
<argument name="baseSelectProcessor" xsi:type="object">Magento\ConfigurableProduct\Model\ResourceModel\Product\StockStatusBaseSelectProcessor</argument>
207207
</arguments>
208208
</type>
209-
<type name="Magento\ConfigurableProduct\Pricing\Render\FinalPriceBox">
210-
<arguments>
211-
<argument name="salableResolver" xsi:type="object">Magento\ConfigurableProduct\Model\Product\Pricing\Renderer\SalableResolver</argument>
212-
</arguments>
209+
<type name="Magento\Catalog\Model\Product\Pricing\Renderer\SalableResolver">
210+
<plugin name="configurable" type="Magento\ConfigurableProduct\Plugin\Catalog\Model\Product\Pricing\Renderer\SalableResolver" />
213211
</type>
214212
</config>

app/code/Magento/Wishlist/etc/di.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,4 @@
7878
</argument>
7979
</arguments>
8080
</type>
81-
<virtualType name="Magento\Wishlist\Pricing\Render\Configurable\ConfiguredPriceBox" type="Magento\Wishlist\Pricing\Render\ConfiguredPriceBox">
82-
<arguments>
83-
<argument name="salableResolver" xsi:type="object">Magento\ConfigurableProduct\Model\Product\Pricing\Renderer\SalableResolver</argument>
84-
</arguments>
85-
</virtualType>
8681
</config>

app/code/Magento/Wishlist/view/base/layout/catalog_product_prices.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@
1616
</item>
1717
</item>
1818
</argument>
19-
<argument name="configurable" xsi:type="array">
20-
<item name="prices" xsi:type="array">
21-
<item name="wishlist_configured_price" xsi:type="array">
22-
<item name="render_class" xsi:type="string">Magento\Wishlist\Pricing\Render\Configurable\ConfiguredPriceBox</item>
23-
</item>
24-
</item>
25-
</argument>
2619
</arguments>
2720
</referenceBlock>
2821
</layout>

dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Constraint/AssertConfigurableProductOutOfStockPage.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,25 @@ protected function verify()
3030
protected function verifyPrice()
3131
{
3232
$priceBlock = $this->productView->getPriceBlock();
33-
if (!$priceBlock->isVisible()) {
34-
return "Price block for '{$this->product->getName()}' product' is not visible.";
35-
}
36-
$formPrice = $priceBlock->isOldPriceVisible() ? $priceBlock->getOldPrice() : $priceBlock->getPrice();
3733
$fixturePrice = $this->getLowestConfigurablePrice();
3834

39-
if ($fixturePrice != $formPrice) {
40-
return "Displayed product price on product page (front-end) not equals passed from fixture. "
41-
. "Actual: {$formPrice}, expected: {$fixturePrice}.";
35+
if ($fixturePrice === null) {
36+
if ($priceBlock->isVisible()) {
37+
return "Price block for '{$this->product->getName()}' product' is visible.";
38+
}
39+
} else {
40+
if (!$priceBlock->isVisible()) {
41+
return "Price block for '{$this->product->getName()}' product' is not visible.";
42+
}
43+
44+
$formPrice = $priceBlock->isOldPriceVisible() ? $priceBlock->getOldPrice() : $priceBlock->getPrice();
45+
46+
if ($fixturePrice != $formPrice) {
47+
return "Displayed product price on product page (front-end) not equals passed from fixture. "
48+
. "Actual: {$formPrice}, expected: {$fixturePrice}.";
49+
}
4250
}
51+
4352
return null;
4453
}
4554

0 commit comments

Comments
 (0)