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

Commit 7ab0846

Browse files
author
Dmytro Voskoboinikov
committed
MAGETWO-72582: Configurable product displays the price of "out of stock" configuration
1 parent 9b44db0 commit 7ab0846

File tree

8 files changed

+82
-17
lines changed

8 files changed

+82
-17
lines changed

app/code/Magento/Catalog/view/base/templates/product/price/configured_price.phtml

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
7-
// @codingStandardsIgnoreFile
8-
96
?>
10-
117
<?php
128
/** @var \Magento\Catalog\Pricing\Render\FinalPriceBox $block */
139
/** @var \Magento\Catalog\Pricing\Price\ConfiguredPrice $configuredPrice */
@@ -18,13 +14,11 @@ $priceLabel = ($block->getPriceLabel() !== null)
1814
: '';
1915
?>
2016
<p class="price-as-configured">
21-
<?php if($configuredPrice->getAmount()->getValue() !== null): ?>
22-
<?= /* @noEscape */ $block->renderAmount($configuredPrice->getAmount(), [
23-
'display_label' => $priceLabel,
24-
'price_id' => $block->getPriceId('product-price-'),
25-
'price_type' => 'finalPrice',
26-
'include_container' => true,
27-
'schema' => $schema
28-
]); ?>
29-
<?php endif; ?>
17+
<?= /* @escapeNotVerified */ $block->renderAmount($configuredPrice->getAmount(), [
18+
'display_label' => $priceLabel,
19+
'price_id' => $block->getPriceId('product-price-'),
20+
'price_type' => 'finalPrice',
21+
'include_container' => true,
22+
'schema' => $schema
23+
]); ?>
3024
</p>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\ConfigurableProduct\Model\Product\Pricing\Renderer;
7+
8+
use Magento\Framework\Pricing\SaleableInterface;
9+
use Magento\Catalog\Model\Product\Pricing\Renderer\SalableResolverInterface;
10+
use Magento\ConfigurableProduct\Pricing\Price\LowestPriceOptionsProviderInterface;
11+
12+
/**
13+
* A decorator for a salable resolver.
14+
*
15+
* Extends functionality of the salable resolver by performing the additional check
16+
* which is related to configurable products.
17+
*/
18+
class SalableResolver implements SalableResolverInterface
19+
{
20+
/**
21+
* @var SalableResolverInterface
22+
*/
23+
private $salableResolver;
24+
25+
/**
26+
* @var LowestPriceOptionsProviderInterface
27+
*/
28+
private $lowestPriceOptionsProvider;
29+
30+
/**
31+
* @param SalableResolverInterface $salableResolver
32+
* @param LowestPriceOptionsProviderInterface $lowestPriceOptionsProvider
33+
*/
34+
public function __construct(
35+
SalableResolverInterface $salableResolver,
36+
LowestPriceOptionsProviderInterface $lowestPriceOptionsProvider
37+
) {
38+
$this->salableResolver = $salableResolver;
39+
$this->lowestPriceOptionsProvider = $lowestPriceOptionsProvider;
40+
}
41+
42+
/**
43+
* {@inheritdoc}
44+
*/
45+
public function isSalable(SaleableInterface $salableItem)
46+
{
47+
if ($this->lowestPriceOptionsProvider->getProducts($salableItem)) {
48+
return $this->salableResolver->isSalable($salableItem);
49+
}
50+
51+
return false;
52+
}
53+
}

app/code/Magento/ConfigurableProduct/Pricing/Price/ConfigurablePriceResolver.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ public function __construct(
5555

5656
/**
5757
* @param \Magento\Framework\Pricing\SaleableInterface|\Magento\Catalog\Model\Product $product
58-
* @return float|null
58+
* @return float
59+
* @throws \Magento\Framework\Exception\LocalizedException
5960
*/
6061
public function resolvePrice(\Magento\Framework\Pricing\SaleableInterface $product)
6162
{
@@ -66,6 +67,6 @@ public function resolvePrice(\Magento\Framework\Pricing\SaleableInterface $produ
6667
$price = $price ? min($price, $productPrice) : $productPrice;
6768
}
6869

69-
return $price === null ? null : (float)$price;
70+
return (float)$price;
7071
}
7172
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,9 @@
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>
213+
</type>
209214
</config>

app/code/Magento/ConfigurableProduct/view/base/templates/product/price/final_price.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ $schema = ($block->getZone() == 'item_view') ? true : false;
3838
'skip_adjustments' => true
3939
]); ?>
4040
</span>
41-
<?php elseif($finalPriceModel->getAmount()->getValue() !== null): ?>
41+
<?php else: ?>
4242
<?php /* @escapeNotVerified */ echo $block->renderAmount($finalPriceModel->getAmount(), [
4343
'price_id' => $block->getPriceId('product-price-' . $idSuffix),
4444
'price_type' => 'finalPrice',

app/code/Magento/Wishlist/Pricing/ConfiguredPrice/ConfigurableProduct.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function getValue()
2626
$product = $customOption ? $customOption->getProduct() : $this->getProduct();
2727
$price = $product->getPriceInfo()->getPrice(self::PRICE_CODE)->getValue();
2828

29-
return $price === null ? null : max(0, $price);
29+
return max(0, $price);
3030
}
3131

3232
/**

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,9 @@
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>
8186
</config>

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
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>
1926
</arguments>
2027
</referenceBlock>
2128
</layout>

0 commit comments

Comments
 (0)