Skip to content

Commit 59f9546

Browse files
author
Mike Weis
committed
MAGETWO-51181: [GITHUB] Configurable product's last attribute with price zero results in error #3912
- commit
1 parent ce68a6d commit 59f9546

File tree

6 files changed

+118
-9
lines changed

6 files changed

+118
-9
lines changed

app/code/Magento/Catalog/view/base/web/js/price-box.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ define([
184184
var type = $(element).data('priceType'),
185185
amount = parseFloat($(element).data('priceAmount'));
186186

187-
if (type && amount) {
187+
if (type && !isNaN(amount)) {
188188
prices[type] = {
189189
amount: amount
190190
};

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ public function resolvePrice(\Magento\Framework\Pricing\SaleableInterface $produ
4848
$productPrice = $this->priceResolver->resolvePrice($subProduct);
4949
$price = $price ? min($price, $productPrice) : $productPrice;
5050
}
51-
if (!$price) {
51+
if ($price === null) {
5252
throw new \Magento\Framework\Exception\LocalizedException(
53-
__('Configurable product "%1" do not have sub-products', $product->getName())
53+
__('Configurable product "%1" does not have sub-products', $product->getName())
5454
);
5555
}
5656
return (float)$price;

app/code/Magento/ConfigurableProduct/Test/Unit/Model/Quote/Item/CartItemProcessorTest.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,15 @@ protected function setUp()
6565
false
6666
);
6767

68-
$this->productOptionExtensionAttributes = $this->getMockBuilder(ProductOptionExtensionAttributes::class)
69-
->disableOriginalConstructor()
70-
->setMethods(['setConfigurableItemOptions'])
71-
->getMock();
68+
$this->productOptionExtensionAttributes = $this->getMockForAbstractClass(
69+
ProductOptionExtensionAttributes::class,
70+
[],
71+
'',
72+
false,
73+
true,
74+
true,
75+
['setConfigurableItemOptions']
76+
);
7277

7378
$this->model = new \Magento\ConfigurableProduct\Model\Quote\Item\CartItemProcessor(
7479
$this->objectFactoryMock,
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\ConfigurableProduct\Test\Unit\Pricing\Price;
7+
8+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
9+
10+
class ConfigurablePriceResolverTest extends \PHPUnit_Framework_TestCase
11+
{
12+
/**
13+
* @var \Magento\ConfigurableProduct\Pricing\Price\ConfigurablePriceResolver
14+
*/
15+
protected $resolver;
16+
17+
/**
18+
* @var PHPUnit_Framework_MockObject_MockObject | \Magento\ConfigurableProduct\Model\Product\Type\Configurable
19+
*/
20+
protected $configurable;
21+
22+
/**
23+
* @var PHPUnit_Framework_MockObject_MockObject | \Magento\ConfigurableProduct\Pricing\Price\PriceResolverInterface
24+
*/
25+
protected $priceResolver;
26+
27+
protected function setUp()
28+
{
29+
$className = 'Magento\ConfigurableProduct\Model\Product\Type\Configurable';
30+
$this->configurable = $this->getMock($className, ['getUsedProducts'], [], '', false);
31+
32+
$className = 'Magento\ConfigurableProduct\Pricing\Price\PriceResolverInterface';
33+
$this->priceResolver = $this->getMockForAbstractClass($className, [], '', false, true, true, ['resolvePrice']);
34+
35+
$objectManager = new ObjectManager($this);
36+
$this->resolver = $objectManager->getObject(
37+
'Magento\ConfigurableProduct\Pricing\Price\ConfigurablePriceResolver',
38+
[
39+
'priceResolver' => $this->priceResolver,
40+
'configurable' => $this->configurable,
41+
]
42+
);
43+
}
44+
45+
/**
46+
* situation: There are no used products, thus there are no prices
47+
*
48+
* @expectedException \Magento\Framework\Exception\LocalizedException
49+
*/
50+
public function testResolvePriceWithNoPrices()
51+
{
52+
$product = $this->getMockForAbstractClass(
53+
'Magento\Framework\Pricing\SaleableInterface',
54+
[],
55+
'',
56+
false,
57+
true,
58+
true,
59+
['getName']
60+
);
61+
$product->expects($this->once())->method('getName')->willReturn('Kiwi');
62+
63+
$this->configurable->expects($this->once())->method('getUsedProducts')->willReturn([]);
64+
65+
$this->resolver->resolvePrice($product);
66+
}
67+
68+
/**
69+
* situation: one product is supplying the price, which could be a price of zero (0)
70+
*
71+
* @dataProvider testResolvePriceDataProvider
72+
*/
73+
public function testResolvePrice($expectedValue)
74+
{
75+
$price = $expectedValue;
76+
77+
$product = $this->getMockForAbstractClass(
78+
'Magento\Framework\Pricing\SaleableInterface',
79+
[],
80+
'',
81+
false,
82+
true,
83+
true,
84+
['getName']
85+
);
86+
$product->expects($this->never())->method('getName');
87+
88+
$this->configurable->expects($this->once())->method('getUsedProducts')->willReturn([$product]);
89+
$this->priceResolver->expects($this->atLeastOnce())->method('resolvePrice')->willReturn($price);
90+
91+
$this->assertEquals($expectedValue, $this->resolver->resolvePrice($product));
92+
}
93+
94+
/**
95+
* @return array
96+
*/
97+
public function testResolvePriceDataProvider()
98+
{
99+
return [
100+
'price of zero' => [0.00],
101+
'price of five' => [5],
102+
];
103+
}
104+
}

app/code/Magento/ConfigurableProduct/i18n/en_US.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Summary,Summary
3030
"You need to choose options for your item.","You need to choose options for your item."
3131
"Some product variations fields are not valid.","Some product variations fields are not valid."
3232
"Configuration must have specified attributes","Configuration must have specified attributes"
33-
"Configurable product ""%1"" do not have sub-products","Configurable product ""%1"" do not have sub-products"
33+
"Configurable product ""%1"" does not have sub-products","Configurable product ""%1"" does not have sub-products"
3434
"This group contains attributes used in configurable products. Please move these attributes to another group and try again.","This group contains attributes used in configurable products. Please move these attributes to another group and try again."
3535
"This attribute is used in configurable products. You cannot remove it from the attribute set.","This attribute is used in configurable products. You cannot remove it from the attribute set."
3636
"Associated Products","Associated Products"

app/code/Magento/ConfigurableProduct/view/frontend/web/js/configurable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ define([
2323
state: {},
2424
priceFormat: {},
2525
optionTemplate: '<%- data.label %>' +
26-
'<% if (data.finalPrice.value) { %>' +
26+
"<% if (typeof data.finalPrice.value !== 'undefined') { %>" +
2727
' <%- data.finalPrice.formatted %>' +
2828
'<% } %>',
2929
mediaGallerySelector: '[data-gallery-role=gallery-placeholder]',

0 commit comments

Comments
 (0)