Skip to content

Commit 1721f95

Browse files
committed
implementation change by picking up customizable options data from catalog options
1 parent 54b43ec commit 1721f95

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ConfigurableProduct extends AbstractPrice
1717
/**
1818
* Price type final.
1919
*/
20-
public const PRICE_CODE = 'final_price';
20+
const PRICE_CODE = 'final_price';
2121

2222
/**
2323
* @var ItemInterface
@@ -57,11 +57,16 @@ public function getConfiguredRegularAmount(): \Magento\Framework\Pricing\Amount\
5757
*/
5858
public function getValue()
5959
{
60-
61-
$price = $this->getProduct()->getMinimalPrice();
62-
if (!$price) {
63-
$price = $this->getProduct()->getPriceInfo()->getPrice(self::PRICE_CODE)->getValue();
60+
$product = $this->getProduct();
61+
$price = $product->getPriceInfo()->getPrice(self::PRICE_CODE)->getValue();
62+
if ($product->getProductOptionsCollection()) {
63+
foreach ($product->getProductOptionsCollection() as $configurableOptions) {
64+
foreach ($configurableOptions->getValues() as $configurableOptionData) {
65+
$price += $configurableOptionData->getData('price');
66+
}
67+
}
6468
}
69+
6570
return max(0, $price);
6671
}
6772

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ protected function setUp(): void
5555
->setMethods([
5656
'getPriceInfo',
5757
'getCustomOption',
58-
'getMinimalPrice'
58+
'getProductOptionsCollection'
5959
])
6060
->getMockForAbstractClass();
6161

@@ -101,11 +101,11 @@ public function testGetValue()
101101
$wishlistItemOptionMock = $this->getMockBuilder(Option::class)
102102
->disableOriginalConstructor()
103103
->getMock();
104-
$wishlistItemOptionMock->expects($this->atLeastOnce())
104+
$wishlistItemOptionMock->expects($this->once())
105105
->method('getProduct')
106106
->willReturn($productMock);
107107

108-
$this->saleableItem->expects($this->atLeastOnce())
108+
$this->saleableItem->expects($this->once())
109109
->method('getCustomOption')
110110
->with('simple_product')
111111
->willReturn($wishlistItemOptionMock);
@@ -117,14 +117,29 @@ public function testGetValueWithNoCustomOption()
117117
{
118118
$priceValue = 100;
119119

120+
$priceMock = $this->getMockBuilder(PriceInterface::class)
121+
->getMockForAbstractClass();
122+
$priceMock->expects($this->once())
123+
->method('getValue')
124+
->willReturn($priceValue);
125+
120126
$this->saleableItem->expects($this->once())
121127
->method('getCustomOption')
122128
->with('simple_product')
123129
->willReturn(null);
124130

125131
$this->saleableItem->expects($this->once())
126-
->method('getMinimalPrice')
127-
->willReturn($priceValue);
132+
->method('getProductOptionsCollection')
133+
->willReturn(null);
134+
135+
$this->saleableItem->expects($this->once())
136+
->method('getPriceInfo')
137+
->willReturn($this->priceInfoMock);
138+
139+
$this->priceInfoMock->expects($this->once())
140+
->method('getPrice')
141+
->with(ConfigurableProduct::PRICE_CODE)
142+
->willReturn($priceMock);
128143

129144
$this->assertEquals(100, $this->model->getValue());
130145
}

0 commit comments

Comments
 (0)