1 | <?php |
||
2 | |||
3 | /** |
||
4 | * Copyright © 2016-present Spryker Systems GmbH. All rights reserved. |
||
5 | * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
||
6 | */ |
||
7 | |||
8 | namespace SprykerTest\Zed\PriceProductSchedule\Business\Facade; |
||
9 | |||
10 | use Codeception\Test\Unit; |
||
11 | use DateTime; |
||
12 | use Generated\Shared\Transfer\CurrencyTransfer; |
||
13 | use Generated\Shared\Transfer\MoneyValueTransfer; |
||
14 | use Generated\Shared\Transfer\PriceProductFilterTransfer; |
||
15 | use Generated\Shared\Transfer\PriceProductScheduleTransfer; |
||
16 | use Generated\Shared\Transfer\PriceProductTransfer; |
||
17 | use Generated\Shared\Transfer\PriceTypeTransfer; |
||
18 | use Generated\Shared\Transfer\StoreTransfer; |
||
19 | use Spryker\Zed\PriceProductSchedule\Business\PriceProductScheduleBusinessFactory; |
||
20 | use Spryker\Zed\PriceProductSchedule\PriceProductScheduleConfig; |
||
21 | |||
22 | /** |
||
23 | * Auto-generated group annotations |
||
24 | * |
||
25 | * @group SprykerTest |
||
26 | * @group Zed |
||
27 | * @group PriceProductSchedule |
||
28 | * @group Business |
||
29 | * @group Facade |
||
30 | * @group PriceProductScheduleRemoveAndApplyTest |
||
31 | * Add your own group annotations below this line |
||
32 | */ |
||
33 | class PriceProductScheduleRemoveAndApplyTest extends Unit |
||
34 | { |
||
35 | /** |
||
36 | * @var \SprykerTest\Zed\PriceProductSchedule\PriceProductScheduleBusinessTester |
||
37 | */ |
||
38 | protected $tester; |
||
39 | |||
40 | /** |
||
41 | * @var \Spryker\Zed\PriceProductSchedule\Business\PriceProductScheduleFacadeInterface |
||
42 | */ |
||
43 | protected $priceProductScheduleFacade; |
||
44 | |||
45 | /** |
||
46 | * @var \Spryker\Zed\Currency\Business\CurrencyFacadeInterface |
||
47 | */ |
||
48 | protected $currencyFacade; |
||
49 | |||
50 | /** |
||
51 | * @var \Generated\Shared\Transfer\StoreTransfer |
||
52 | */ |
||
53 | protected StoreTransfer $storeTransfer; |
||
54 | |||
55 | /** |
||
56 | * @var \Spryker\Zed\PriceProduct\Business\PriceProductFacadeInterface |
||
57 | */ |
||
58 | protected $priceProductFacade; |
||
59 | |||
60 | /** |
||
61 | * @return void |
||
62 | */ |
||
63 | public function setUp(): void |
||
64 | { |
||
65 | parent::setUp(); |
||
66 | |||
67 | $this->tester->ensureDatabaseTableIsEmpty(); |
||
68 | |||
69 | $this->priceProductScheduleFacade = $this->tester->getFacade(); |
||
70 | $this->currencyFacade = $this->tester->getLocator()->currency()->facade(); |
||
71 | $this->storeTransfer = $this->tester->haveStore([StoreTransfer::NAME => 'DE']); |
||
72 | $this->priceProductFacade = $this->tester->getLocator()->priceProduct()->facade(); |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * @return void |
||
77 | */ |
||
78 | public function testPriceProductScheduleAbstractDeleteAndApplyShouldSetDefaultPriceFromOriginal(): void |
||
79 | { |
||
80 | // Assign |
||
81 | $productConcreteTransfer = $this->tester->haveProduct(); |
||
82 | $defaultPriceTypeTransfer = $this->tester->havePriceType(); |
||
83 | |||
84 | $currencyId = $this->tester->haveCurrency([CurrencyTransfer::CODE => 'test1']); |
||
85 | $currencyTransfer = $this->currencyFacade->getByIdCurrency($currencyId); |
||
86 | |||
87 | $this->tester->havePriceProduct([ |
||
88 | PriceProductTransfer::SKU_PRODUCT_ABSTRACT => $productConcreteTransfer->getAbstractSku(), |
||
89 | PriceProductTransfer::PRICE_TYPE => $defaultPriceTypeTransfer, |
||
90 | PriceProductTransfer::MONEY_VALUE => [ |
||
91 | MoneyValueTransfer::NET_AMOUNT => 100, |
||
92 | MoneyValueTransfer::GROSS_AMOUNT => 100, |
||
93 | MoneyValueTransfer::CURRENCY => $currencyTransfer, |
||
94 | ], |
||
95 | ]); |
||
96 | |||
97 | $fallbackPriceTypeTransfer = $this->tester->havePriceType(); |
||
98 | |||
99 | $this->tester->havePriceProduct([ |
||
100 | PriceProductTransfer::SKU_PRODUCT_ABSTRACT => $productConcreteTransfer->getAbstractSku(), |
||
101 | PriceProductTransfer::PRICE_TYPE => $fallbackPriceTypeTransfer, |
||
102 | PriceProductTransfer::MONEY_VALUE => [ |
||
103 | MoneyValueTransfer::NET_AMOUNT => 200, |
||
104 | MoneyValueTransfer::GROSS_AMOUNT => 200, |
||
105 | MoneyValueTransfer::CURRENCY => $currencyTransfer, |
||
106 | ], |
||
107 | ]); |
||
108 | |||
109 | $priceProductScheduleTransfer = $this->tester->havePriceProductSchedule([ |
||
110 | PriceProductScheduleTransfer::ACTIVE_FROM => (new DateTime('-4 days')), |
||
111 | PriceProductScheduleTransfer::ACTIVE_TO => (new DateTime('+1 hour')), |
||
112 | PriceProductScheduleTransfer::IS_CURRENT => true, |
||
113 | PriceProductScheduleTransfer::PRICE_PRODUCT => [ |
||
114 | PriceProductTransfer::ID_PRODUCT => $productConcreteTransfer->getIdProductConcrete(), |
||
115 | PriceProductTransfer::PRICE_TYPE => [ |
||
116 | PriceTypeTransfer::NAME => $defaultPriceTypeTransfer->getName(), |
||
117 | PriceTypeTransfer::ID_PRICE_TYPE => $defaultPriceTypeTransfer->getIdPriceType(), |
||
118 | ], |
||
119 | PriceProductTransfer::MONEY_VALUE => [ |
||
120 | MoneyValueTransfer::FK_STORE => $this->storeTransfer->getIdStore(), |
||
121 | MoneyValueTransfer::FK_CURRENCY => $currencyId, |
||
122 | MoneyValueTransfer::CURRENCY => $currencyTransfer, |
||
123 | MoneyValueTransfer::NET_AMOUNT => 100, |
||
124 | MoneyValueTransfer::GROSS_AMOUNT => 100, |
||
125 | ], |
||
126 | ], |
||
127 | ]); |
||
128 | |||
129 | $priceProductScheduleFacade = $this->tester->getFacade(); |
||
130 | $priceProductScheduleFacade->setFactory( |
||
131 | (new PriceProductScheduleBusinessFactory()) |
||
132 | ->setConfig($this->getConfigMock($defaultPriceTypeTransfer->getName(), $fallbackPriceTypeTransfer->getName())), |
||
133 | ); |
||
134 | |||
135 | // Act |
||
136 | $priceProductScheduleFacade->applyScheduledPrices($this->storeTransfer->getName()); |
||
137 | $priceProductScheduleFacade->removeAndApplyPriceProductSchedule($priceProductScheduleTransfer->getIdPriceProductSchedule()); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
138 | |||
139 | // Assert |
||
140 | $priceProductFilterTransfer = (new PriceProductFilterTransfer()) |
||
141 | ->setSku($productConcreteTransfer->getSku()) |
||
142 | ->setPriceTypeName($defaultPriceTypeTransfer->getName()) |
||
143 | ->setCurrencyIsoCode($currencyTransfer->getCode()) |
||
144 | ->setStoreName($this->storeTransfer->getName()); |
||
145 | |||
146 | $actualPriceProductTransfer = $this->priceProductFacade->findPriceProductFor($priceProductFilterTransfer); |
||
147 | |||
148 | $this->assertSame(200, $actualPriceProductTransfer->getMoneyValue()->getNetAmount(), 'Default price does not match expected value.'); |
||
149 | } |
||
150 | |||
151 | /** |
||
152 | * @return void |
||
153 | */ |
||
154 | public function testPriceProductScheduleConcreteDeleteAndApplyShouldSetDefaultPriceFromOriginal(): void |
||
155 | { |
||
156 | // Assign |
||
157 | $productConcreteTransfer = $this->tester->haveProduct(); |
||
158 | $defaultPriceTypeTransfer = $this->tester->havePriceType(); |
||
159 | |||
160 | $currencyId = $this->tester->haveCurrency([CurrencyTransfer::CODE => 'test2']); |
||
161 | $currencyTransfer = $this->currencyFacade->getByIdCurrency($currencyId); |
||
162 | |||
163 | $this->tester->havePriceProduct([ |
||
164 | PriceProductTransfer::SKU_PRODUCT_ABSTRACT => $productConcreteTransfer->getAbstractSku(), |
||
165 | PriceProductTransfer::PRICE_TYPE => $defaultPriceTypeTransfer, |
||
166 | PriceProductTransfer::SKU_PRODUCT => $productConcreteTransfer->getSku(), |
||
167 | PriceProductTransfer::MONEY_VALUE => [ |
||
168 | MoneyValueTransfer::NET_AMOUNT => 100, |
||
169 | MoneyValueTransfer::GROSS_AMOUNT => 100, |
||
170 | MoneyValueTransfer::CURRENCY => $currencyTransfer, |
||
171 | ], |
||
172 | ]); |
||
173 | |||
174 | $fallbackPriceTypeTransfer = $this->tester->havePriceType(); |
||
175 | |||
176 | $this->tester->havePriceProduct([ |
||
177 | PriceProductTransfer::SKU_PRODUCT_ABSTRACT => $productConcreteTransfer->getAbstractSku(), |
||
178 | PriceProductTransfer::PRICE_TYPE => $fallbackPriceTypeTransfer, |
||
179 | PriceProductTransfer::SKU_PRODUCT => $productConcreteTransfer->getSku(), |
||
180 | PriceProductTransfer::MONEY_VALUE => [ |
||
181 | MoneyValueTransfer::NET_AMOUNT => 200, |
||
182 | MoneyValueTransfer::GROSS_AMOUNT => 200, |
||
183 | MoneyValueTransfer::CURRENCY => $currencyTransfer, |
||
184 | ], |
||
185 | ]); |
||
186 | |||
187 | $priceProductScheduleTransfer = $this->tester->havePriceProductSchedule([ |
||
188 | PriceProductScheduleTransfer::ACTIVE_FROM => (new DateTime('-4 days')), |
||
189 | PriceProductScheduleTransfer::ACTIVE_TO => (new DateTime('+1 hour')), |
||
190 | PriceProductScheduleTransfer::IS_CURRENT => true, |
||
191 | PriceProductScheduleTransfer::PRICE_PRODUCT => [ |
||
192 | PriceProductTransfer::ID_PRODUCT => $productConcreteTransfer->getIdProductConcrete(), |
||
193 | PriceProductTransfer::PRICE_TYPE => [ |
||
194 | PriceTypeTransfer::NAME => $defaultPriceTypeTransfer->getName(), |
||
195 | PriceTypeTransfer::ID_PRICE_TYPE => $defaultPriceTypeTransfer->getIdPriceType(), |
||
196 | ], |
||
197 | PriceProductTransfer::MONEY_VALUE => [ |
||
198 | MoneyValueTransfer::FK_STORE => $this->storeTransfer->getIdStore(), |
||
199 | MoneyValueTransfer::FK_CURRENCY => $currencyId, |
||
200 | MoneyValueTransfer::CURRENCY => $currencyTransfer, |
||
201 | MoneyValueTransfer::NET_AMOUNT => 100, |
||
202 | MoneyValueTransfer::GROSS_AMOUNT => 100, |
||
203 | ], |
||
204 | ], |
||
205 | ]); |
||
206 | |||
207 | $priceProductScheduleFacade = $this->tester->getFacade(); |
||
208 | $priceProductScheduleFacade->setFactory( |
||
209 | (new PriceProductScheduleBusinessFactory()) |
||
210 | ->setConfig($this->getConfigMock($defaultPriceTypeTransfer->getName(), $fallbackPriceTypeTransfer->getName())), |
||
211 | ); |
||
212 | |||
213 | // Act |
||
214 | $priceProductScheduleFacade->applyScheduledPrices($this->storeTransfer->getName()); |
||
215 | $priceProductScheduleFacade->removeAndApplyPriceProductSchedule($priceProductScheduleTransfer->getIdPriceProductSchedule()); |
||
216 | |||
217 | // Assert |
||
218 | $priceProductFilterTransfer = (new PriceProductFilterTransfer()) |
||
219 | ->setSku($productConcreteTransfer->getSku()) |
||
220 | ->setPriceTypeName($defaultPriceTypeTransfer->getName()) |
||
221 | ->setCurrencyIsoCode($currencyTransfer->getCode()) |
||
222 | ->setStoreName($this->storeTransfer->getName()); |
||
223 | |||
224 | $actualPriceProductTransfer = $this->priceProductFacade->findPriceProductFor($priceProductFilterTransfer); |
||
225 | |||
226 | $this->assertSame(200, $actualPriceProductTransfer->getMoneyValue()->getNetAmount(), 'Default price does not match expected value.'); |
||
227 | } |
||
228 | |||
229 | /** |
||
230 | * @return void |
||
231 | */ |
||
232 | public function testPriceProductScheduleAbstractDeleteAndApplyShouldSetDefaultPriceFromSecondScheduledPrice(): void |
||
233 | { |
||
234 | // Assign |
||
235 | $productConcreteTransfer = $this->tester->haveProduct(); |
||
236 | $defaultPriceTypeTransfer = $this->tester->havePriceType(); |
||
237 | |||
238 | $currencyId = $this->tester->haveCurrency([CurrencyTransfer::CODE => 'test3']); |
||
239 | $currencyTransfer = $this->currencyFacade->getByIdCurrency($currencyId); |
||
240 | |||
241 | $this->tester->havePriceProduct([ |
||
242 | PriceProductTransfer::SKU_PRODUCT_ABSTRACT => $productConcreteTransfer->getAbstractSku(), |
||
243 | PriceProductTransfer::PRICE_TYPE => $defaultPriceTypeTransfer, |
||
244 | PriceProductTransfer::MONEY_VALUE => [ |
||
245 | MoneyValueTransfer::NET_AMOUNT => 100, |
||
246 | MoneyValueTransfer::GROSS_AMOUNT => 100, |
||
247 | MoneyValueTransfer::CURRENCY => $currencyTransfer, |
||
248 | ], |
||
249 | ]); |
||
250 | |||
251 | $fallbackPriceTypeTransfer = $this->tester->havePriceType(); |
||
252 | |||
253 | $this->tester->havePriceProduct([ |
||
254 | PriceProductTransfer::SKU_PRODUCT_ABSTRACT => $productConcreteTransfer->getAbstractSku(), |
||
255 | PriceProductTransfer::PRICE_TYPE => $fallbackPriceTypeTransfer, |
||
256 | PriceProductTransfer::MONEY_VALUE => [ |
||
257 | MoneyValueTransfer::NET_AMOUNT => 200, |
||
258 | MoneyValueTransfer::GROSS_AMOUNT => 200, |
||
259 | MoneyValueTransfer::CURRENCY => $currencyTransfer, |
||
260 | ], |
||
261 | ]); |
||
262 | |||
263 | $priceProductScheduleTransfer = $this->tester->havePriceProductSchedule([ |
||
264 | PriceProductScheduleTransfer::ACTIVE_FROM => (new DateTime('-4 days')), |
||
265 | PriceProductScheduleTransfer::ACTIVE_TO => (new DateTime('+1 hour')), |
||
266 | PriceProductScheduleTransfer::IS_CURRENT => false, |
||
267 | PriceProductScheduleTransfer::PRICE_PRODUCT => [ |
||
268 | PriceProductTransfer::ID_PRODUCT_ABSTRACT => $productConcreteTransfer->getFkProductAbstract(), |
||
269 | PriceProductTransfer::PRICE_TYPE => [ |
||
270 | PriceTypeTransfer::NAME => $defaultPriceTypeTransfer->getName(), |
||
271 | PriceTypeTransfer::ID_PRICE_TYPE => $defaultPriceTypeTransfer->getIdPriceType(), |
||
272 | ], |
||
273 | PriceProductTransfer::MONEY_VALUE => [ |
||
274 | MoneyValueTransfer::FK_STORE => $this->storeTransfer->getIdStore(), |
||
275 | MoneyValueTransfer::FK_CURRENCY => $currencyId, |
||
276 | MoneyValueTransfer::CURRENCY => $currencyTransfer, |
||
277 | MoneyValueTransfer::NET_AMOUNT => 100, |
||
278 | MoneyValueTransfer::GROSS_AMOUNT => 100, |
||
279 | ], |
||
280 | ], |
||
281 | ]); |
||
282 | |||
283 | $this->tester->havePriceProductSchedule([ |
||
284 | PriceProductScheduleTransfer::ACTIVE_FROM => (new DateTime('-6 days')), |
||
285 | PriceProductScheduleTransfer::ACTIVE_TO => (new DateTime('+6 days')), |
||
286 | PriceProductScheduleTransfer::IS_CURRENT => false, |
||
287 | PriceProductScheduleTransfer::PRICE_PRODUCT => [ |
||
288 | PriceProductTransfer::ID_PRODUCT_ABSTRACT => $productConcreteTransfer->getFkProductAbstract(), |
||
289 | PriceProductTransfer::PRICE_TYPE => [ |
||
290 | PriceTypeTransfer::NAME => $defaultPriceTypeTransfer->getName(), |
||
291 | PriceTypeTransfer::ID_PRICE_TYPE => $defaultPriceTypeTransfer->getIdPriceType(), |
||
292 | ], |
||
293 | PriceProductTransfer::MONEY_VALUE => [ |
||
294 | MoneyValueTransfer::FK_STORE => $this->storeTransfer->getIdStore(), |
||
295 | MoneyValueTransfer::FK_CURRENCY => $currencyId, |
||
296 | MoneyValueTransfer::CURRENCY => $currencyTransfer, |
||
297 | MoneyValueTransfer::NET_AMOUNT => 500, |
||
298 | MoneyValueTransfer::GROSS_AMOUNT => 500, |
||
299 | ], |
||
300 | ], |
||
301 | ]); |
||
302 | |||
303 | $priceProductScheduleFacade = $this->tester->getFacade(); |
||
304 | $priceProductScheduleFacade->setFactory( |
||
305 | (new PriceProductScheduleBusinessFactory()) |
||
306 | ->setConfig($this->getConfigMock($defaultPriceTypeTransfer->getName(), $fallbackPriceTypeTransfer->getName())), |
||
307 | ); |
||
308 | |||
309 | // Act |
||
310 | $priceProductScheduleFacade->applyScheduledPrices($this->storeTransfer->getName()); |
||
311 | $priceProductScheduleFacade->removeAndApplyPriceProductSchedule($priceProductScheduleTransfer->getIdPriceProductSchedule()); |
||
312 | |||
313 | // Assert |
||
314 | $priceProductFilterTransfer = (new PriceProductFilterTransfer()) |
||
315 | ->setSku($productConcreteTransfer->getAbstractSku()) |
||
316 | ->setPriceTypeName($defaultPriceTypeTransfer->getName()) |
||
317 | ->setCurrencyIsoCode($currencyTransfer->getCode()) |
||
318 | ->setStoreName($this->storeTransfer->getName()); |
||
319 | |||
320 | $actualPriceProductTransfer = $this->priceProductFacade->findPriceProductFor($priceProductFilterTransfer); |
||
321 | |||
322 | $this->assertSame(500, $actualPriceProductTransfer->getMoneyValue()->getNetAmount(), 'Default price does not match expected value.'); |
||
323 | } |
||
324 | |||
325 | /** |
||
326 | * @return void |
||
327 | */ |
||
328 | public function testPriceProductScheduleConcreteDeleteAndApplyShouldSetDefaultPriceFromAnotherScheduledPrice(): void |
||
329 | { |
||
330 | // Assign |
||
331 | $productConcreteTransfer = $this->tester->haveProduct(); |
||
332 | $defaultPriceTypeTransfer = $this->tester->havePriceType(); |
||
333 | |||
334 | $currencyId = $this->tester->haveCurrency([CurrencyTransfer::CODE => 'test4']); |
||
335 | $currencyTransfer = $this->currencyFacade->getByIdCurrency($currencyId); |
||
336 | |||
337 | $this->tester->havePriceProduct([ |
||
338 | PriceProductTransfer::SKU_PRODUCT_ABSTRACT => $productConcreteTransfer->getAbstractSku(), |
||
339 | PriceProductTransfer::PRICE_TYPE => $defaultPriceTypeTransfer, |
||
340 | PriceProductTransfer::SKU_PRODUCT => $productConcreteTransfer->getSku(), |
||
341 | PriceProductTransfer::MONEY_VALUE => [ |
||
342 | MoneyValueTransfer::NET_AMOUNT => 100, |
||
343 | MoneyValueTransfer::GROSS_AMOUNT => 100, |
||
344 | MoneyValueTransfer::CURRENCY => $currencyTransfer, |
||
345 | ], |
||
346 | ]); |
||
347 | |||
348 | $fallbackPriceTypeTransfer = $this->tester->havePriceType(); |
||
349 | |||
350 | $this->tester->havePriceProduct([ |
||
351 | PriceProductTransfer::SKU_PRODUCT_ABSTRACT => $productConcreteTransfer->getAbstractSku(), |
||
352 | PriceProductTransfer::PRICE_TYPE => $fallbackPriceTypeTransfer, |
||
353 | PriceProductTransfer::SKU_PRODUCT => $productConcreteTransfer->getSku(), |
||
354 | PriceProductTransfer::MONEY_VALUE => [ |
||
355 | MoneyValueTransfer::NET_AMOUNT => 200, |
||
356 | MoneyValueTransfer::GROSS_AMOUNT => 200, |
||
357 | MoneyValueTransfer::CURRENCY => $currencyTransfer, |
||
358 | ], |
||
359 | ]); |
||
360 | |||
361 | $priceProductScheduleTransfer = $this->tester->havePriceProductSchedule([ |
||
362 | PriceProductScheduleTransfer::ACTIVE_FROM => (new DateTime('-4 days')), |
||
363 | PriceProductScheduleTransfer::ACTIVE_TO => (new DateTime('+1 hour')), |
||
364 | PriceProductScheduleTransfer::IS_CURRENT => false, |
||
365 | PriceProductScheduleTransfer::PRICE_PRODUCT => [ |
||
366 | PriceProductTransfer::ID_PRODUCT => $productConcreteTransfer->getIdProductConcrete(), |
||
367 | PriceProductTransfer::PRICE_TYPE => [ |
||
368 | PriceTypeTransfer::NAME => $defaultPriceTypeTransfer->getName(), |
||
369 | PriceTypeTransfer::ID_PRICE_TYPE => $defaultPriceTypeTransfer->getIdPriceType(), |
||
370 | ], |
||
371 | PriceProductTransfer::MONEY_VALUE => [ |
||
372 | MoneyValueTransfer::FK_STORE => $this->storeTransfer->getIdStore(), |
||
373 | MoneyValueTransfer::FK_CURRENCY => $currencyId, |
||
374 | MoneyValueTransfer::CURRENCY => $currencyTransfer, |
||
375 | MoneyValueTransfer::NET_AMOUNT => 100, |
||
376 | MoneyValueTransfer::GROSS_AMOUNT => 100, |
||
377 | ], |
||
378 | ], |
||
379 | ]); |
||
380 | |||
381 | $this->tester->havePriceProductSchedule([ |
||
382 | PriceProductScheduleTransfer::ACTIVE_FROM => (new DateTime('-6 days')), |
||
383 | PriceProductScheduleTransfer::ACTIVE_TO => (new DateTime('+6 days')), |
||
384 | PriceProductScheduleTransfer::IS_CURRENT => false, |
||
385 | PriceProductScheduleTransfer::PRICE_PRODUCT => [ |
||
386 | PriceProductTransfer::ID_PRODUCT => $productConcreteTransfer->getIdProductConcrete(), |
||
387 | PriceProductTransfer::PRICE_TYPE => [ |
||
388 | PriceTypeTransfer::NAME => $defaultPriceTypeTransfer->getName(), |
||
389 | PriceTypeTransfer::ID_PRICE_TYPE => $defaultPriceTypeTransfer->getIdPriceType(), |
||
390 | ], |
||
391 | PriceProductTransfer::MONEY_VALUE => [ |
||
392 | MoneyValueTransfer::FK_STORE => $this->storeTransfer->getIdStore(), |
||
393 | MoneyValueTransfer::FK_CURRENCY => $currencyId, |
||
394 | MoneyValueTransfer::CURRENCY => $currencyTransfer, |
||
395 | MoneyValueTransfer::NET_AMOUNT => 500, |
||
396 | MoneyValueTransfer::GROSS_AMOUNT => 500, |
||
397 | ], |
||
398 | ], |
||
399 | ]); |
||
400 | |||
401 | $priceProductScheduleFacade = $this->tester->getFacade(); |
||
402 | $priceProductScheduleFacade->setFactory( |
||
403 | (new PriceProductScheduleBusinessFactory()) |
||
404 | ->setConfig($this->getConfigMock($defaultPriceTypeTransfer->getName(), $fallbackPriceTypeTransfer->getName())), |
||
405 | ); |
||
406 | |||
407 | // Act |
||
408 | $priceProductScheduleFacade->applyScheduledPrices($this->storeTransfer->getName()); |
||
409 | $priceProductScheduleFacade->removeAndApplyPriceProductSchedule($priceProductScheduleTransfer->getIdPriceProductSchedule()); |
||
410 | |||
411 | // Assert |
||
412 | $priceProductFilterTransfer = (new PriceProductFilterTransfer()) |
||
413 | ->setSku($productConcreteTransfer->getSku()) |
||
414 | ->setPriceTypeName($defaultPriceTypeTransfer->getName()) |
||
415 | ->setCurrencyIsoCode($currencyTransfer->getCode()) |
||
416 | ->setStoreName($this->storeTransfer->getName()); |
||
417 | |||
418 | $actualPriceProductTransfer = $this->priceProductFacade->findPriceProductFor($priceProductFilterTransfer); |
||
419 | |||
420 | $this->assertSame(500, $actualPriceProductTransfer->getMoneyValue()->getNetAmount(), 'Default price does not match expected value.'); |
||
421 | } |
||
422 | |||
423 | /** |
||
424 | * @param string $priceTypeName |
||
425 | * @param string $fallbackPriceTypeName |
||
426 | * |
||
427 | * @return \PHPUnit\Framework\MockObject\MockObject|\Spryker\Zed\PriceProductSchedule\PriceProductScheduleConfig |
||
428 | */ |
||
429 | protected function getConfigMock(string $priceTypeName, string $fallbackPriceTypeName): PriceProductScheduleConfig |
||
430 | { |
||
431 | $configMock = $this->getMockBuilder(PriceProductScheduleConfig::class) |
||
432 | ->setMethods(['getFallbackPriceTypeList']) |
||
433 | ->getMock(); |
||
434 | |||
435 | $configMock->method('getFallbackPriceTypeList') |
||
436 | ->willReturn([$priceTypeName => $fallbackPriceTypeName]); |
||
437 | |||
438 | return $configMock; |
||
439 | } |
||
440 | } |
||
441 |