1 | <?php |
||
31 | final class PromotionContext implements Context |
||
32 | { |
||
33 | /** |
||
34 | * @var SharedStorageInterface |
||
35 | */ |
||
36 | private $sharedStorage; |
||
37 | |||
38 | /** |
||
39 | * @var ActionFactoryInterface |
||
40 | */ |
||
41 | private $actionFactory; |
||
42 | |||
43 | /** |
||
44 | * @var CouponFactoryInterface |
||
45 | */ |
||
46 | private $couponFactory; |
||
47 | |||
48 | /** |
||
49 | * @var RuleFactoryInterface |
||
50 | */ |
||
51 | private $ruleFactory; |
||
52 | |||
53 | /** |
||
54 | * @var TestPromotionFactoryInterface |
||
55 | */ |
||
56 | private $testPromotionFactory; |
||
57 | |||
58 | /** |
||
59 | * @var PromotionRepositoryInterface |
||
60 | */ |
||
61 | private $promotionRepository; |
||
62 | |||
63 | /** |
||
64 | * @var ObjectManager |
||
65 | */ |
||
66 | private $objectManager; |
||
67 | |||
68 | /** |
||
69 | * @param SharedStorageInterface $sharedStorage |
||
70 | * @param ActionFactoryInterface $actionFactory |
||
71 | * @param CouponFactoryInterface $couponFactory |
||
72 | * @param RuleFactoryInterface $ruleFactory |
||
73 | * @param TestPromotionFactoryInterface $testPromotionFactory |
||
74 | * @param PromotionRepositoryInterface $promotionRepository |
||
75 | * @param ObjectManager $objectManager |
||
76 | */ |
||
77 | public function __construct( |
||
94 | |||
95 | /** |
||
96 | * @Given there is a promotion :promotionName |
||
97 | * @Given there is a promotion :promotionName identified by :promotionCode code |
||
98 | */ |
||
99 | public function thereIsPromotion($promotionName, $promotionCode = null) |
||
112 | |||
113 | /** |
||
114 | * @Given the store has promotion :promotionName with coupon :couponCode |
||
115 | * @Given the store has also promotion :promotionName with coupon :couponCode |
||
116 | */ |
||
117 | public function thereIsPromotionWithCoupon($promotionName, $couponCode) |
||
133 | |||
134 | /** |
||
135 | * @Given /^([^"]+) gives ("(?:€|£|\$)[^"]+") discount to every order$/ |
||
136 | */ |
||
137 | public function itGivesFixedDiscountToEveryOrder(PromotionInterface $promotion, $discount) |
||
141 | |||
142 | /** |
||
143 | * @Given /^([^"]+) gives ("[^"]+%") discount to every order$/ |
||
144 | */ |
||
145 | public function itGivesPercentageDiscountToEveryOrder(PromotionInterface $promotion, $discount) |
||
149 | |||
150 | /** |
||
151 | * @Given /^([^"]+) gives ("(?:€|£|\$)[^"]+") discount to every order with quantity at least ([^"]+)$/ |
||
152 | */ |
||
153 | public function itGivesFixedDiscountToEveryOrderWithQuantityAtLeast( |
||
162 | |||
163 | /** |
||
164 | * @Given /^([^"]+) gives ("(?:€|£|\$)[^"]+") discount to every order with items total at least ("[^"]+")$/ |
||
165 | */ |
||
166 | public function itGivesFixedDiscountToEveryOrderWithItemsTotalAtLeast( |
||
175 | |||
176 | /** |
||
177 | * @Given /^([^"]+) gives ("[^"]+%") discount on shipping to every order$/ |
||
178 | */ |
||
179 | public function itGivesPercentageDiscountOnShippingToEveryOrder(PromotionInterface $promotion, $discount) |
||
186 | |||
187 | /** |
||
188 | * @Given /^([^"]+) gives free shipping to every order$/ |
||
189 | */ |
||
190 | public function thePromotionGivesFreeShippingToEveryOrder(PromotionInterface $promotion) |
||
194 | |||
195 | /** |
||
196 | * @Given /^([^"]+) gives ("[^"]+%") off every product (classified as "[^"]+")$/ |
||
197 | */ |
||
198 | public function itGivesPercentageOffEveryProductClassifiedAs( |
||
205 | |||
206 | /** |
||
207 | * @Given /^([^"]+) gives ("(?:€|£|\$)[^"]+") off on every product (classified as "[^"]+")$/ |
||
208 | */ |
||
209 | public function itGivesFixedOffEveryProductClassifiedAs( |
||
216 | |||
217 | /** |
||
218 | * @Given /^([^"]+) gives ("(?:€|£|\$)[^"]+") off on every product with minimum price at ("(?:€|£|\$)[^"]+")$/ |
||
219 | */ |
||
220 | public function thisPromotionGivesOffOnEveryProductWithMinimumPriceAt( |
||
227 | |||
228 | /** |
||
229 | * @Given /^([^"]+) gives ("(?:€|£|\$)[^"]+") off on every product priced between ("(?:€|£|\$)[^"]+") and ("(?:€|£|\$)[^"]+")$/ |
||
230 | */ |
||
231 | public function thisPromotionGivesOffOnEveryProductPricedBetween( |
||
243 | |||
244 | /** |
||
245 | * @Given /^([^"]+) gives ("[^"]+%") off on every product with minimum price at ("(?:€|£|\$)[^"]+")$/ |
||
246 | */ |
||
247 | public function thisPromotionPercentageGivesOffOnEveryProductWithMinimumPriceAt( |
||
254 | |||
255 | /** |
||
256 | * @Given /^([^"]+) gives ("[^"]+%") off on every product priced between ("(?:€|£|\$)[^"]+") and ("(?:€|£|\$)[^"]+")$/ |
||
257 | */ |
||
258 | public function thisPromotionPercentageGivesOffOnEveryProductPricedBetween( |
||
270 | |||
271 | /** |
||
272 | * @Given /^([^"]+) gives ("(?:€|£|\$)[^"]+") off if order contains products (classified as "[^"]+")$/ |
||
273 | */ |
||
274 | public function thePromotionGivesOffIfOrderContainsProductsClassifiedAs( |
||
283 | |||
284 | /** |
||
285 | * @Given /^([^"]+) gives ("(?:€|£|\$)[^"]+") off if order contains products (classified as "[^"]+" or "[^"]+")$/ |
||
286 | */ |
||
287 | public function thePromotionGivesOffIfOrderContainsProductsClassifiedAsOr( |
||
296 | |||
297 | /** |
||
298 | * @Given /^([^"]+) gives ("(?:€|£|\$)[^"]+") off if order contains products (classified as "[^"]+") with a minimum value of ("(?:€|£|\$)[^"]+")$/ |
||
299 | */ |
||
300 | public function thePromotionGivesOffIfOrderContainsProductsClassifiedAsAndPricedAt( |
||
310 | |||
311 | /** |
||
312 | * @Given /^([^"]+) gives ("(?:€|£|\$)[^"]+") off if order contains (\d+) products (classified as "[^"]+")$/ |
||
313 | */ |
||
314 | public function thePromotionGivesOffIfOrderContainsNumberOfProductsClassifiedAs( |
||
324 | |||
325 | /** |
||
326 | * @Given /^([^"]+) gives ("(?:€|£|\$)[^"]+") off customer's (\d)(?:st|nd|rd|th) order$/ |
||
327 | */ |
||
328 | public function itGivesFixedOffCustomersNthOrder(PromotionInterface $promotion, $discount, $nth) |
||
334 | |||
335 | /** |
||
336 | * @Given /^([^"]+) gives ("[^"]+%") off on the customer's (\d)(?:st|nd|rd|th) order$/ |
||
337 | */ |
||
338 | public function itGivesPercentageOffCustomersNthOrder(PromotionInterface $promotion, $discount, $nth) |
||
344 | |||
345 | /** |
||
346 | * @Given /^([^"]+) gives ("[^"]+%") off on every product (classified as "[^"]+") if an order contains any product (classified as "[^"]+")$/ |
||
347 | */ |
||
348 | public function itGivesPercentageOffOnEveryProductClassifiedAsIfAnOrderContainsAnyProductClassifiedAs( |
||
358 | |||
359 | /** |
||
360 | * @Given /^([^"]+) gives ("(?:€|£|\$)[^"]+") off on every product (classified as "[^"]+") and a free shipping to every order with items total equal at least ("[^"]+")$/ |
||
361 | */ |
||
362 | public function itGivesOffOnEveryProductClassifiedAsAndAFreeShippingToEveryOrderWithItemsTotalEqualAtLeast( |
||
375 | |||
376 | /** |
||
377 | * @Given /^([^"]+) gives ("[^"]+%") off on every product (classified as "[^"]+") and a ("(?:€|£|\$)[^"]+") discount to every order with items total equal at least ("(?:€|£|\$)[^"]+")$/ |
||
378 | */ |
||
379 | public function itGivesOffOnEveryProductClassifiedAsAndAFixedDiscountToEveryOrderWithItemsTotalEqualAtLeast( |
||
398 | |||
399 | /** |
||
400 | * @Given /^([^"]+) gives ("[^"]+%") off on every product (classified as "[^"]+" or "[^"]+") if order contains any product (classified as "[^"]+" or "[^"]+")$/ |
||
401 | */ |
||
402 | public function itGivesOffOnEveryProductClassifiedAsOrIfOrderContainsAnyProductClassifiedAsOr( |
||
420 | |||
421 | /** |
||
422 | * @Given /^(it) is coupon based promotion$/ |
||
423 | */ |
||
424 | public function itIsCouponBasedPromotion(PromotionInterface $promotion) |
||
430 | |||
431 | /** |
||
432 | * @param array $taxonCodes |
||
433 | * |
||
434 | * @return array |
||
435 | */ |
||
436 | private function getTaxonFilterConfiguration(array $taxonCodes) |
||
440 | |||
441 | /** |
||
442 | * @param int $minAmount |
||
443 | * @param int $maxAmount |
||
444 | * |
||
445 | * @return array |
||
446 | */ |
||
447 | private function getPriceRangeFilterConfiguration($minAmount, $maxAmount = null) |
||
456 | |||
457 | /** |
||
458 | * @param PromotionInterface $promotion |
||
459 | * @param int $discount |
||
460 | * @param array $configuration |
||
461 | */ |
||
462 | private function createItemFixedPromotion(PromotionInterface $promotion, $discount, array $configuration = [], $rule = null) |
||
466 | |||
467 | /** |
||
468 | * @param PromotionInterface $promotion |
||
469 | * @param int $discount |
||
470 | * @param array $configuration |
||
471 | */ |
||
472 | private function createItemPercentagePromotion(PromotionInterface $promotion, $discount, array $configuration = [], $rule = null) |
||
476 | |||
477 | /** |
||
478 | * @param PromotionInterface $promotion |
||
479 | * @param int $discount |
||
480 | * @param array $configuration |
||
481 | * @param RuleInterface $rule |
||
482 | */ |
||
483 | private function createFixedPromotion(PromotionInterface $promotion, $discount, array $configuration = [], RuleInterface $rule = null) |
||
487 | |||
488 | /** |
||
489 | * @param PromotionInterface $promotion |
||
490 | * @param float $discount |
||
491 | * @param array $configuration |
||
492 | * @param RuleInterface $rule |
||
493 | */ |
||
494 | private function createPercentagePromotion(PromotionInterface $promotion, $discount, array $configuration = [], RuleInterface $rule = null) |
||
498 | |||
499 | /** |
||
500 | * @param PromotionInterface $promotion |
||
501 | * @param ActionInterface $action |
||
502 | * @param array $configuration |
||
503 | * @param RuleInterface|null $rule |
||
504 | */ |
||
505 | private function persistPromotion(PromotionInterface $promotion, ActionInterface $action, array $configuration, RuleInterface $rule = null) |
||
517 | } |
||
518 |