Skip to content

Commit ecdff44

Browse files
committed
MC-40054: Tier Prices get removed when the schedule update is created for a specific website
1 parent 5f7f950 commit ecdff44

File tree

1 file changed

+139
-0
lines changed

1 file changed

+139
-0
lines changed

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

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,143 @@ public function testExecuteWithException(): void
180180

181181
$this->saveHandler->execute($product);
182182
}
183+
184+
/**
185+
* @param $tierPrices
186+
* @param $tierPricesStored
187+
* @param $tierPricesExpected
188+
* @dataProvider executeWithWebsitePriceDataProvider
189+
*/
190+
public function testExecuteWithWebsitePrice($tierPrices, $tierPricesStored, $tierPricesExpected): void
191+
{
192+
$productId = 10;
193+
$linkField = 'entity_id';
194+
195+
/** @var MockObject $product */
196+
$product = $this->getMockBuilder(ProductInterface::class)
197+
->disableOriginalConstructor()
198+
->setMethods(['getData','setData', 'getStoreId'])
199+
->getMockForAbstractClass();
200+
$product->expects($this->atLeastOnce())->method('getData')->willReturnMap(
201+
[
202+
['tier_price', $tierPrices],
203+
['entity_id', $productId]
204+
]
205+
);
206+
$product->expects($this->atLeastOnce())->method('getStoreId')->willReturn(0);
207+
$product->expects($this->atLeastOnce())->method('setData')->with('tier_price_changed', 1);
208+
$store = $this->getMockBuilder(StoreInterface::class)
209+
->disableOriginalConstructor()
210+
->setMethods(['getWebsiteId'])
211+
->getMockForAbstractClass();
212+
$store->expects($this->atLeastOnce())->method('getWebsiteId')->willReturn(1);
213+
$this->storeManager->expects($this->atLeastOnce())->method('getStore')->willReturn($store);
214+
/** @var MockObject $attribute */
215+
$attribute = $this->getMockBuilder(ProductAttributeInterface::class)
216+
->disableOriginalConstructor()
217+
->setMethods(['getName', 'isScopeGlobal'])
218+
->getMockForAbstractClass();
219+
$attribute->expects($this->atLeastOnce())->method('getName')->willReturn('tier_price');
220+
$attribute->expects($this->atLeastOnce())->method('isScopeGlobal')->willReturn(false);
221+
$this->attributeRepository->expects($this->atLeastOnce())->method('get')->with('tier_price')
222+
->willReturn($attribute);
223+
$productMetadata = $this->getMockBuilder(EntityMetadataInterface::class)
224+
->disableOriginalConstructor()
225+
->setMethods(['getLinkField'])
226+
->getMockForAbstractClass();
227+
$productMetadata->expects($this->atLeastOnce())->method('getLinkField')->willReturn($linkField);
228+
$this->metadataPoll->expects($this->atLeastOnce())->method('getMetadata')
229+
->with(ProductInterface::class)
230+
->willReturn($productMetadata);
231+
$customerGroup = $this->getMockBuilder(GroupInterface::class)
232+
->disableOriginalConstructor()
233+
->setMethods(['getId'])
234+
->getMockForAbstractClass();
235+
$customerGroup->expects($this->atLeastOnce())->method('getId')->willReturn(3200);
236+
$this->groupManagement->expects($this->atLeastOnce())->method('getAllCustomersGroup')
237+
->willReturn($customerGroup);
238+
$this->tierPriceResource
239+
->expects($this->at(1))
240+
->method('savePriceData')
241+
->with(new \Magento\Framework\DataObject($tierPricesExpected[0]))
242+
->willReturnSelf();
243+
$this->tierPriceResource
244+
->expects($this->at(2))
245+
->method('savePriceData')
246+
->with(new \Magento\Framework\DataObject($tierPricesExpected[1]))
247+
->willReturnSelf();
248+
$this->tierPriceResource
249+
->expects($this->at(3))
250+
->method('savePriceData')
251+
->with(new \Magento\Framework\DataObject($tierPricesExpected[2]))
252+
->willReturnSelf();
253+
$this->tierPriceResource
254+
->expects($this->atLeastOnce())
255+
->method('loadPriceData')
256+
->willReturn($tierPricesStored);
257+
258+
$this->assertEquals($product, $this->saveHandler->execute($product));
259+
}
260+
261+
public function executeWithWebsitePriceDataProvider(): array
262+
{
263+
$productId = 10;
264+
return [[
265+
'tierPrices' => [
266+
[
267+
'price_id' => 1,
268+
'website_id' => 0,
269+
'price_qty' => 1,
270+
'cust_group' => 0,
271+
'price' => 10,
272+
'product_id' => $productId
273+
],[
274+
'price_id' => 2,
275+
'website_id' => 1,
276+
'price_qty' => 2,
277+
'cust_group' => 3200,
278+
'price' => null,
279+
'percentage_value' => 20,
280+
'product_id' => $productId
281+
]
282+
],
283+
'tierPricesStored' => [
284+
[
285+
'price_id' => 3,
286+
'website_id' => 1,
287+
'price_qty' => 3,
288+
'cust_group' => 0,
289+
'price' => 30,
290+
'product_id' => $productId
291+
]
292+
],
293+
'tierPricesExpected' => [
294+
[
295+
'website_id' => 0,
296+
'qty' => 1,
297+
'customer_group_id' => 0,
298+
'all_groups' => 0,
299+
'value' => 10,
300+
'percentage_value' => null,
301+
'entity_id' => $productId
302+
],[
303+
'website_id' => 1,
304+
'qty' => 2,
305+
'customer_group_id' => 0,
306+
'all_groups' => 1,
307+
'value' => null,
308+
'percentage_value' => 20,
309+
'entity_id' => $productId
310+
],[
311+
'website_id' => 1,
312+
'qty' => 3,
313+
'customer_group_id' => 0,
314+
'all_groups' => 0,
315+
'value' => 30,
316+
'percentage_value' => null,
317+
'entity_id' => $productId
318+
]
319+
]
320+
]];
321+
}
183322
}

0 commit comments

Comments
 (0)