Skip to content

Commit

Permalink
MAGETWO-51181: [GITHUB] Configurable product's last attribute with pr…
Browse files Browse the repository at this point in the history
…ice zero results in error #3912

 - commit
  • Loading branch information
Mike Weis committed Mar 31, 2016
1 parent ce68a6d commit 59f9546
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/view/base/web/js/price-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ define([
var type = $(element).data('priceType'),
amount = parseFloat($(element).data('priceAmount'));

if (type && amount) {
if (type && !isNaN(amount)) {
prices[type] = {
amount: amount
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public function resolvePrice(\Magento\Framework\Pricing\SaleableInterface $produ
$productPrice = $this->priceResolver->resolvePrice($subProduct);
$price = $price ? min($price, $productPrice) : $productPrice;
}
if (!$price) {
if ($price === null) {
throw new \Magento\Framework\Exception\LocalizedException(
__('Configurable product "%1" do not have sub-products', $product->getName())
__('Configurable product "%1" does not have sub-products', $product->getName())
);
}
return (float)$price;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,15 @@ protected function setUp()
false
);

$this->productOptionExtensionAttributes = $this->getMockBuilder(ProductOptionExtensionAttributes::class)
->disableOriginalConstructor()
->setMethods(['setConfigurableItemOptions'])
->getMock();
$this->productOptionExtensionAttributes = $this->getMockForAbstractClass(
ProductOptionExtensionAttributes::class,
[],
'',
false,
true,
true,
['setConfigurableItemOptions']
);

$this->model = new \Magento\ConfigurableProduct\Model\Quote\Item\CartItemProcessor(
$this->objectFactoryMock,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\ConfigurableProduct\Test\Unit\Pricing\Price;

use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;

class ConfigurablePriceResolverTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Magento\ConfigurableProduct\Pricing\Price\ConfigurablePriceResolver
*/
protected $resolver;

/**
* @var PHPUnit_Framework_MockObject_MockObject | \Magento\ConfigurableProduct\Model\Product\Type\Configurable
*/
protected $configurable;

/**
* @var PHPUnit_Framework_MockObject_MockObject | \Magento\ConfigurableProduct\Pricing\Price\PriceResolverInterface
*/
protected $priceResolver;

protected function setUp()
{
$className = 'Magento\ConfigurableProduct\Model\Product\Type\Configurable';
$this->configurable = $this->getMock($className, ['getUsedProducts'], [], '', false);

$className = 'Magento\ConfigurableProduct\Pricing\Price\PriceResolverInterface';
$this->priceResolver = $this->getMockForAbstractClass($className, [], '', false, true, true, ['resolvePrice']);

$objectManager = new ObjectManager($this);
$this->resolver = $objectManager->getObject(
'Magento\ConfigurableProduct\Pricing\Price\ConfigurablePriceResolver',
[
'priceResolver' => $this->priceResolver,
'configurable' => $this->configurable,
]
);
}

/**
* situation: There are no used products, thus there are no prices
*
* @expectedException \Magento\Framework\Exception\LocalizedException
*/
public function testResolvePriceWithNoPrices()
{
$product = $this->getMockForAbstractClass(
'Magento\Framework\Pricing\SaleableInterface',
[],
'',
false,
true,
true,
['getName']
);
$product->expects($this->once())->method('getName')->willReturn('Kiwi');

$this->configurable->expects($this->once())->method('getUsedProducts')->willReturn([]);

$this->resolver->resolvePrice($product);
}

/**
* situation: one product is supplying the price, which could be a price of zero (0)
*
* @dataProvider testResolvePriceDataProvider
*/
public function testResolvePrice($expectedValue)
{
$price = $expectedValue;

$product = $this->getMockForAbstractClass(
'Magento\Framework\Pricing\SaleableInterface',
[],
'',
false,
true,
true,
['getName']
);
$product->expects($this->never())->method('getName');

$this->configurable->expects($this->once())->method('getUsedProducts')->willReturn([$product]);
$this->priceResolver->expects($this->atLeastOnce())->method('resolvePrice')->willReturn($price);

$this->assertEquals($expectedValue, $this->resolver->resolvePrice($product));
}

/**
* @return array
*/
public function testResolvePriceDataProvider()
{
return [
'price of zero' => [0.00],
'price of five' => [5],
];
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/ConfigurableProduct/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Summary,Summary
"You need to choose options for your item.","You need to choose options for your item."
"Some product variations fields are not valid.","Some product variations fields are not valid."
"Configuration must have specified attributes","Configuration must have specified attributes"
"Configurable product ""%1"" do not have sub-products","Configurable product ""%1"" do not have sub-products"
"Configurable product ""%1"" does not have sub-products","Configurable product ""%1"" does not have sub-products"
"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."
"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."
"Associated Products","Associated Products"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ define([
state: {},
priceFormat: {},
optionTemplate: '<%- data.label %>' +
'<% if (data.finalPrice.value) { %>' +
"<% if (typeof data.finalPrice.value !== 'undefined') { %>" +
' <%- data.finalPrice.formatted %>' +
'<% } %>',
mediaGallerySelector: '[data-gallery-role=gallery-placeholder]',
Expand Down

0 comments on commit 59f9546

Please sign in to comment.