Skip to content

Commit 847d23f

Browse files
author
Oleksii Korshenko
authored
MAGETWO-69023: Backport of MAGETWO-59512 for Magento 2.1: Products in wishlist show $0.00 price #6866 #9571
2 parents 8a84178 + 247ce6d commit 847d23f

File tree

5 files changed

+86
-26
lines changed

5 files changed

+86
-26
lines changed

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,12 @@ class ConfigurableProduct extends FinalPrice implements ConfiguredPriceInterface
2121
*/
2222
public function getValue()
2323
{
24-
$result = 0.;
2524
/** @var \Magento\Wishlist\Model\Item\Option $customOption */
2625
$customOption = $this->getProduct()->getCustomOption('simple_product');
27-
if ($customOption) {
28-
/** @var \Magento\Framework\Pricing\PriceInfoInterface $priceInfo */
29-
$priceInfo = $customOption->getProduct()->getPriceInfo();
30-
$result = $priceInfo->getPrice(self::PRICE_CODE)->getValue();
31-
}
32-
return max(0, $result);
26+
$product = $customOption ? $customOption->getProduct() : $this->getProduct();
27+
$price = $product->getPriceInfo()->getPrice(self::PRICE_CODE)->getValue();
28+
29+
return max(0, $price);
3330
}
3431

3532
/**

app/code/Magento/Wishlist/Test/Unit/Pricing/ConfiguredPrice/ConfigurableProductTest.php

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,30 @@
55
*/
66
namespace Magento\Wishlist\Test\Unit\Pricing\ConfiguredPrice;
77

8-
use Magento\Framework\Pricing\Adjustment\CalculatorInterface;
9-
use Magento\Framework\Pricing\PriceCurrencyInterface;
10-
use Magento\Framework\Pricing\PriceInfoInterface;
11-
use Magento\Framework\Pricing\SaleableInterface;
12-
use Magento\Wishlist\Pricing\ConfiguredPrice\ConfigurableProduct;
13-
148
class ConfigurableProductTest extends \PHPUnit_Framework_TestCase
159
{
1610
/**
17-
* @var SaleableInterface|\PHPUnit_Framework_MockObject_MockObject
11+
* @var \Magento\Framework\Pricing\SaleableInterface|\PHPUnit_Framework_MockObject_MockObject
1812
*/
1913
private $saleableItem;
2014

2115
/**
22-
* @var CalculatorInterface|\PHPUnit_Framework_MockObject_MockObject
16+
* @var \Magento\Framework\Pricing\Adjustment\CalculatorInterface|\PHPUnit_Framework_MockObject_MockObject
2317
*/
2418
private $calculator;
2519

2620
/**
27-
* @var PriceCurrencyInterface|\PHPUnit_Framework_MockObject_MockObject
21+
* @var \Magento\Framework\Pricing\PriceCurrencyInterface|\PHPUnit_Framework_MockObject_MockObject
2822
*/
2923
private $priceCurrency;
3024

3125
/**
32-
* @var ConfigurableProduct
26+
* @var \Magento\Wishlist\Pricing\ConfiguredPrice\ConfigurableProduct
3327
*/
3428
private $model;
3529

3630
/**
37-
* @var PriceInfoInterface|\PHPUnit_Framework_MockObject_MockObject
31+
* @var \Magento\Framework\Pricing\PriceInfoInterface|\PHPUnit_Framework_MockObject_MockObject
3832
*/
3933
private $priceInfoMock;
4034

@@ -49,17 +43,14 @@ protected function setUp()
4943
'getCustomOption',
5044
])
5145
->getMockForAbstractClass();
52-
$this->saleableItem->expects($this->once())
53-
->method('getPriceInfo')
54-
->willReturn($this->priceInfoMock);
5546

5647
$this->calculator = $this->getMockBuilder('Magento\Framework\Pricing\Adjustment\CalculatorInterface')
5748
->getMockForAbstractClass();
5849

5950
$this->priceCurrency = $this->getMockBuilder('Magento\Framework\Pricing\PriceCurrencyInterface')
6051
->getMockForAbstractClass();
6152

62-
$this->model = new ConfigurableProduct(
53+
$this->model = new \Magento\Wishlist\Pricing\ConfiguredPrice\ConfigurableProduct(
6354
$this->saleableItem,
6455
null,
6556
$this->calculator,
@@ -82,7 +73,7 @@ public function testGetValue()
8273
->getMock();
8374
$this->priceInfoMock->expects($this->once())
8475
->method('getPrice')
85-
->with(ConfigurableProduct::PRICE_CODE)
76+
->with(\Magento\Wishlist\Pricing\ConfiguredPrice\ConfigurableProduct::PRICE_CODE)
8677
->willReturn($priceMock);
8778

8879
$productMock = $this->getMockBuilder('Magento\Catalog\Model\Product')
@@ -109,11 +100,28 @@ public function testGetValue()
109100

110101
public function testGetValueWithNoCustomOption()
111102
{
103+
$priceValue = 100;
104+
105+
$priceMock = $this->getMockBuilder(\Magento\Framework\Pricing\Price\PriceInterface::class)
106+
->getMockForAbstractClass();
107+
$priceMock->expects($this->once())
108+
->method('getValue')
109+
->willReturn($priceValue);
110+
112111
$this->saleableItem->expects($this->once())
113112
->method('getCustomOption')
114113
->with('simple_product')
115114
->willReturn(null);
116115

117-
$this->assertEquals(0, $this->model->getValue());
116+
$this->saleableItem->expects($this->once())
117+
->method('getPriceInfo')
118+
->willReturn($this->priceInfoMock);
119+
120+
$this->priceInfoMock->expects($this->once())
121+
->method('getPrice')
122+
->with(\Magento\Wishlist\Pricing\ConfiguredPrice\ConfigurableProduct::PRICE_CODE)
123+
->willReturn($priceMock);
124+
125+
$this->assertEquals(100, $this->model->getValue());
118126
}
119127
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Wishlist\Test\Constraint;
8+
9+
class AssertProductPriceIsNotZero extends \Magento\Mtf\Constraint\AbstractConstraint
10+
{
11+
/**
12+
* Assert that product price is not zero in default wishlist.
13+
*
14+
* @param \Magento\Cms\Test\Page\CmsIndex $cmsIndex
15+
* @param \Magento\Customer\Test\Page\CustomerAccountIndex $customerAccountIndex
16+
* @param \Magento\Wishlist\Test\Page\WishlistIndex $wishlistIndex
17+
* @param \Magento\Mtf\Fixture\InjectableFixture $product
18+
*
19+
* @return void
20+
*/
21+
public function processAssert(
22+
\Magento\Cms\Test\Page\CmsIndex $cmsIndex,
23+
\Magento\Customer\Test\Page\CustomerAccountIndex $customerAccountIndex,
24+
\Magento\Wishlist\Test\Page\WishlistIndex $wishlistIndex,
25+
\Magento\Mtf\Fixture\InjectableFixture $product
26+
) {
27+
$cmsIndex->getLinksBlock()->openLink('My Account');
28+
$customerAccountIndex->getAccountMenuBlock()->openMenuItem('My Wish List');
29+
$wishlistItem = $wishlistIndex->getWishlistBlock()->getProductItemsBlock()->getItemProduct($product);
30+
31+
\PHPUnit_Framework_Assert::assertNotEquals(
32+
'0.00',
33+
$wishlistItem->getPrice(),
34+
$product->getName() . ' has zero price on Wish List page.'
35+
);
36+
}
37+
38+
/**
39+
* Returns a string representation of the object.
40+
*
41+
* @return string
42+
*/
43+
public function toString()
44+
{
45+
return 'Product price is not zero in default Wish List.';
46+
}
47+
}

dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/AddProductToWishlistEntityTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,16 @@ public function __prepare(Customer $customer)
4949
*
5050
* @param Customer $customer
5151
* @param string $product
52+
* @param bool $configure
5253
* @return array
5354
*/
54-
public function test(Customer $customer, $product)
55+
public function test(Customer $customer, $product, $configure = true)
5556
{
5657
$product = $this->createProducts($product)[0];
5758

5859
// Steps:
5960
$this->loginCustomer($customer);
60-
$this->addToWishlist([$product], true);
61+
$this->addToWishlist([$product], $configure);
6162

6263
return ['product' => $product];
6364
}

dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/AddProductToWishlistEntityTest.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,12 @@
5050
<constraint name="Magento\Wishlist\Test\Constraint\AssertProductDetailsInWishlist" />
5151
<constraint name="Magento\Wishlist\Test\Constraint\AssertProductIsPresentInCustomerBackendWishlist" />
5252
</variation>
53+
<variation name="AddProductToWishlistEntityTestVariation8">
54+
<data name="product/0" xsi:type="string">configurableProduct::default</data>
55+
<data name="configure" xsi:type="boolean">false</data>
56+
<constraint name="Magento\Wishlist\Test\Constraint\AssertAddProductToWishlistSuccessMessage" />
57+
<constraint name="Magento\Wishlist\Test\Constraint\AssertProductIsPresentInWishlist" />
58+
<constraint name="Magento\Wishlist\Test\Constraint\AssertProductPriceIsNotZero" />
59+
</variation>
5360
</testCase>
5461
</config>

0 commit comments

Comments
 (0)