Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport of MAGETWO-59512 for Magento 2.1: Products in wishlist show $0.00 price #6866 #9571

Merged
merged 1 commit into from
May 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,12 @@ class ConfigurableProduct extends FinalPrice implements ConfiguredPriceInterface
*/
public function getValue()
{
$result = 0.;
/** @var \Magento\Wishlist\Model\Item\Option $customOption */
$customOption = $this->getProduct()->getCustomOption('simple_product');
if ($customOption) {
/** @var \Magento\Framework\Pricing\PriceInfoInterface $priceInfo */
$priceInfo = $customOption->getProduct()->getPriceInfo();
$result = $priceInfo->getPrice(self::PRICE_CODE)->getValue();
}
return max(0, $result);
$product = $customOption ? $customOption->getProduct() : $this->getProduct();
$price = $product->getPriceInfo()->getPrice(self::PRICE_CODE)->getValue();

return max(0, $price);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,30 @@
*/
namespace Magento\Wishlist\Test\Unit\Pricing\ConfiguredPrice;

use Magento\Framework\Pricing\Adjustment\CalculatorInterface;
use Magento\Framework\Pricing\PriceCurrencyInterface;
use Magento\Framework\Pricing\PriceInfoInterface;
use Magento\Framework\Pricing\SaleableInterface;
use Magento\Wishlist\Pricing\ConfiguredPrice\ConfigurableProduct;

class ConfigurableProductTest extends \PHPUnit_Framework_TestCase
{
/**
* @var SaleableInterface|\PHPUnit_Framework_MockObject_MockObject
* @var \Magento\Framework\Pricing\SaleableInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $saleableItem;

/**
* @var CalculatorInterface|\PHPUnit_Framework_MockObject_MockObject
* @var \Magento\Framework\Pricing\Adjustment\CalculatorInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $calculator;

/**
* @var PriceCurrencyInterface|\PHPUnit_Framework_MockObject_MockObject
* @var \Magento\Framework\Pricing\PriceCurrencyInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $priceCurrency;

/**
* @var ConfigurableProduct
* @var \Magento\Wishlist\Pricing\ConfiguredPrice\ConfigurableProduct
*/
private $model;

/**
* @var PriceInfoInterface|\PHPUnit_Framework_MockObject_MockObject
* @var \Magento\Framework\Pricing\PriceInfoInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $priceInfoMock;

Expand All @@ -49,17 +43,14 @@ protected function setUp()
'getCustomOption',
])
->getMockForAbstractClass();
$this->saleableItem->expects($this->once())
->method('getPriceInfo')
->willReturn($this->priceInfoMock);

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

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

$this->model = new ConfigurableProduct(
$this->model = new \Magento\Wishlist\Pricing\ConfiguredPrice\ConfigurableProduct(
$this->saleableItem,
null,
$this->calculator,
Expand All @@ -82,7 +73,7 @@ public function testGetValue()
->getMock();
$this->priceInfoMock->expects($this->once())
->method('getPrice')
->with(ConfigurableProduct::PRICE_CODE)
->with(\Magento\Wishlist\Pricing\ConfiguredPrice\ConfigurableProduct::PRICE_CODE)
->willReturn($priceMock);

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

public function testGetValueWithNoCustomOption()
{
$priceValue = 100;

$priceMock = $this->getMockBuilder(\Magento\Framework\Pricing\Price\PriceInterface::class)
->getMockForAbstractClass();
$priceMock->expects($this->once())
->method('getValue')
->willReturn($priceValue);

$this->saleableItem->expects($this->once())
->method('getCustomOption')
->with('simple_product')
->willReturn(null);

$this->assertEquals(0, $this->model->getValue());
$this->saleableItem->expects($this->once())
->method('getPriceInfo')
->willReturn($this->priceInfoMock);

$this->priceInfoMock->expects($this->once())
->method('getPrice')
->with(\Magento\Wishlist\Pricing\ConfiguredPrice\ConfigurableProduct::PRICE_CODE)
->willReturn($priceMock);

$this->assertEquals(100, $this->model->getValue());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Wishlist\Test\Constraint;

class AssertProductPriceIsNotZero extends \Magento\Mtf\Constraint\AbstractConstraint
{
/**
* Assert that product price is not zero in default wishlist.
*
* @param \Magento\Cms\Test\Page\CmsIndex $cmsIndex
* @param \Magento\Customer\Test\Page\CustomerAccountIndex $customerAccountIndex
* @param \Magento\Wishlist\Test\Page\WishlistIndex $wishlistIndex
* @param \Magento\Mtf\Fixture\InjectableFixture $product
*
* @return void
*/
public function processAssert(
\Magento\Cms\Test\Page\CmsIndex $cmsIndex,
\Magento\Customer\Test\Page\CustomerAccountIndex $customerAccountIndex,
\Magento\Wishlist\Test\Page\WishlistIndex $wishlistIndex,
\Magento\Mtf\Fixture\InjectableFixture $product
) {
$cmsIndex->getLinksBlock()->openLink('My Account');
$customerAccountIndex->getAccountMenuBlock()->openMenuItem('My Wish List');
$wishlistItem = $wishlistIndex->getWishlistBlock()->getProductItemsBlock()->getItemProduct($product);

\PHPUnit_Framework_Assert::assertNotEquals(
'0.00',
$wishlistItem->getPrice(),
$product->getName() . ' has zero price on Wish List page.'
);
}

/**
* Returns a string representation of the object.
*
* @return string
*/
public function toString()
{
return 'Product price is not zero in default Wish List.';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,16 @@ public function __prepare(Customer $customer)
*
* @param Customer $customer
* @param string $product
* @param bool $configure
* @return array
*/
public function test(Customer $customer, $product)
public function test(Customer $customer, $product, $configure = true)
{
$product = $this->createProducts($product)[0];

// Steps:
$this->loginCustomer($customer);
$this->addToWishlist([$product], true);
$this->addToWishlist([$product], $configure);

return ['product' => $product];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,12 @@
<constraint name="Magento\Wishlist\Test\Constraint\AssertProductDetailsInWishlist" />
<constraint name="Magento\Wishlist\Test\Constraint\AssertProductIsPresentInCustomerBackendWishlist" />
</variation>
<variation name="AddProductToWishlistEntityTestVariation8">
<data name="product/0" xsi:type="string">configurableProduct::default</data>
<data name="configure" xsi:type="boolean">false</data>
<constraint name="Magento\Wishlist\Test\Constraint\AssertAddProductToWishlistSuccessMessage" />
<constraint name="Magento\Wishlist\Test\Constraint\AssertProductIsPresentInWishlist" />
<constraint name="Magento\Wishlist\Test\Constraint\AssertProductPriceIsNotZero" />
</variation>
</testCase>
</config>