Skip to content

Commit 8f47bb7

Browse files
authored
ENGCOM-6647: Fixed Issue with tier price 0 when saving product second time #26162
2 parents 5c1e4f2 + 02c2595 commit 8f47bb7

File tree

2 files changed

+117
-21
lines changed

2 files changed

+117
-21
lines changed

app/code/Magento/Catalog/Model/Product/Attribute/Backend/TierPrice/UpdateHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private function updateValues(array $valuesToUpdate, array $oldValues): bool
129129
{
130130
$isChanged = false;
131131
foreach ($valuesToUpdate as $key => $value) {
132-
if ((!empty($value['value'])
132+
if ((($value['value'])!== null
133133
&& (float)$oldValues[$key]['price'] !== $this->localeFormat->getNumber($value['value'])
134134
) || $this->getPercentage($oldValues[$key]) !== $this->getPercentage($value)
135135
) {

app/code/Magento/Catalog/Test/Unit/Model/Attribute/Backend/TierPrice/UpdateHandlerTest.php

Lines changed: 116 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
namespace Magento\Catalog\Test\Unit\Model\Attribute\Backend\TierPrice;
99

10-
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
11-
use Magento\Catalog\Model\Product\Attribute\Backend\TierPrice\UpdateHandler;
12-
use Magento\Store\Model\StoreManagerInterface;
1310
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
11+
use Magento\Catalog\Model\Product\Attribute\Backend\TierPrice\UpdateHandler;
12+
use Magento\Catalog\Model\ResourceModel\Product\Attribute\Backend\Tierprice;
1413
use Magento\Customer\Api\GroupManagementInterface;
1514
use Magento\Framework\EntityManager\MetadataPool;
16-
use Magento\Catalog\Model\ResourceModel\Product\Attribute\Backend\Tierprice;
15+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
16+
use Magento\Store\Model\StoreManagerInterface;
1717

1818
/**
1919
* Unit tests for \Magento\Catalog\Model\Product\Attribute\Backend\TierPrice\UpdateHandler
@@ -95,20 +95,27 @@ protected function setUp()
9595
);
9696
}
9797

98-
public function testExecute(): void
99-
{
100-
$newTierPrices = [
101-
['website_id' => 0, 'price_qty' => 2, 'cust_group' => 0, 'price' => 15],
102-
['website_id' => 0, 'price_qty' => 3, 'cust_group' => 3200, 'price' => null, 'percentage_value' => 20]
103-
];
104-
$priceIdToDelete = 2;
105-
$originalTierPrices = [
106-
['price_id' => 1, 'website_id' => 0, 'price_qty' => 2, 'cust_group' => 0, 'price' => 10],
107-
['price_id' => $priceIdToDelete, 'website_id' => 0, 'price_qty' => 4, 'cust_group' => 0, 'price' => 20],
108-
];
109-
$linkField = 'entity_id';
110-
$productId = 10;
111-
$originalProductId = 11;
98+
/**
99+
* Verify update handle.
100+
*
101+
* @param array $newTierPrices
102+
* @param array $originalTierPrices
103+
* @param int $priceIdToDelete
104+
* @param string $linkField
105+
* @param int $productId
106+
* @param int $originalProductId
107+
* @throws \Magento\Framework\Exception\InputException
108+
*
109+
* @dataProvider configDataProvider
110+
*/
111+
public function testExecute(
112+
$newTierPrices,
113+
$originalTierPrices,
114+
$priceIdToDelete,
115+
$linkField,
116+
$productId,
117+
$originalProductId
118+
): void {
112119

113120
/** @var \PHPUnit_Framework_MockObject_MockObject $product */
114121
$product = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductInterface::class)
@@ -128,8 +135,12 @@ public function testExecute(): void
128135
['entity_id', $originalProductId]
129136
]
130137
);
138+
131139
$product->expects($this->atLeastOnce())->method('getStoreId')->willReturn(0);
132-
$product->expects($this->atLeastOnce())->method('setData')->with('tier_price_changed', 1);
140+
141+
$product->expects($this->atLeastOnce())
142+
->method('setData')
143+
->with('tier_price_changed', 1);
133144
$store = $this->getMockBuilder(\Magento\Store\Api\Data\StoreInterface::class)
134145
->disableOriginalConstructor()
135146
->setMethods(['getWebsiteId'])
@@ -163,11 +174,12 @@ public function testExecute(): void
163174
$this->tierPriceResource->expects($this->exactly(2))->method('savePriceData')->willReturnSelf();
164175
$this->tierPriceResource->expects($this->once())->method('deletePriceData')
165176
->with($productId, null, $priceIdToDelete);
166-
167177
$this->assertEquals($product, $this->updateHandler->execute($product));
168178
}
169179

170180
/**
181+
* Verify update handle with exception.
182+
*
171183
* @expectedException \Magento\Framework\Exception\InputException
172184
* @expectedExceptionMessage Tier prices data should be array, but actually other type is received
173185
*/
@@ -190,4 +202,88 @@ public function testExecuteWithException(): void
190202

191203
$this->updateHandler->execute($product);
192204
}
205+
206+
/**
207+
* Returns test parameters.
208+
*
209+
* @return array
210+
*/
211+
public function configDataProvider()
212+
{
213+
return [
214+
[
215+
[
216+
[
217+
'website_id' => 0,
218+
'price_qty' => 2,
219+
'cust_group' => 0,
220+
'price' => 15
221+
],
222+
[
223+
'website_id' => 0,
224+
'price_qty' => 3,
225+
'cust_group' => 3200,
226+
'price' => null,
227+
'percentage_value' => 20
228+
]
229+
],
230+
[
231+
[
232+
'price_id' => 1,
233+
'website_id' => 0,
234+
'price_qty' => 2,
235+
'cust_group' => 0,
236+
'price' => 10],
237+
[
238+
'price_id' => 2,
239+
'website_id' => 0,
240+
'price_qty' => 4,
241+
'cust_group' => 0,
242+
'price' => 20
243+
],
244+
],
245+
2,
246+
'entity_id',
247+
10,
248+
11
249+
],
250+
[
251+
[
252+
[
253+
'website_id' => 0,
254+
'price_qty' => 2,
255+
'cust_group' => 0,
256+
'price' => 0
257+
],
258+
[
259+
'website_id' => 0,
260+
'price_qty' => 3,
261+
'cust_group' => 3200,
262+
'price' => null,
263+
'percentage_value' => 20
264+
]
265+
],
266+
[
267+
[
268+
'price_id' => 1,
269+
'website_id' => 0,
270+
'price_qty' => 2,
271+
'cust_group' => 0,
272+
'price' => 10
273+
],
274+
[
275+
'price_id' => 2,
276+
'website_id' => 0,
277+
'price_qty' => 4,
278+
'cust_group' => 0,
279+
'price' => 20
280+
],
281+
],
282+
2,
283+
'entity_id',
284+
10,
285+
11
286+
]
287+
];
288+
}
193289
}

0 commit comments

Comments
 (0)