1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
<?php
/**
* Data Model implementing the Address interface
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\SalesRule\Model\Data;
use Magento\SalesRule\Api\Data\ConditionInterface;
use Magento\SalesRule\Api\Data\RuleInterface;
/**
* Class Rule
*
* @SuppressWarnings(PHPMD.ExcessivePublicCount)
* @codeCoverageIgnore
*/
class Rule extends \Magento\Framework\Api\AbstractExtensibleObject implements RuleInterface
{
const KEY_RULE_ID = 'rule_id';
const KEY_NAME = 'name';
const KEY_STORE_LABELS = 'store_labels';
const KEY_DESCRIPTION = 'description';
const KEY_FROM_DATE = 'from_date';
const KEY_TO_DATE = 'to_date';
const KEY_USES_PER_CUSTOMER = 'uses_per_customer';
const KEY_IS_ACTIVE = 'is_active';
const KEY_CONDITION = 'condition';
const KEY_ACTION_CONDITION = 'action_condition';
const KEY_STOP_RULES_PROCESSING = 'stop_rules_processing';
const KEY_IS_ADVANCED = 'is_advanced';
const KEY_WEBSITES = 'website_ids';
const KEY_PRODUCT_IDS = 'product_ids';
const KEY_CUSTOMER_GROUPS = 'customer_group_ids';
const KEY_SORT_ORDER = 'sort_order';
const KEY_SIMPLE_ACTION = 'simple_action';
const KEY_DISCOUNT_AMOUNT = 'discount_amount';
const KEY_DISCOUNT_QTY = 'discount_qty';
const KEY_DISCOUNT_STEP = 'discount_step';
const KEY_APPLY_TO_SHIPPING = 'apply_to_shipping';
const KEY_TIMES_USED = 'times_used';
const KEY_IS_RSS = 'is_rss';
const KEY_COUPON_TYPE = 'coupon_type';
const KEY_USE_AUTO_GENERATION = 'use_auto_generation';
const KEY_USES_PER_COUPON = 'uses_per_coupon';
const KEY_SIMPLE_FREE_SHIPPING = 'simple_free_shipping';
/**
* Return rule id
*
* @return int|null
*/
public function getRuleId()
{
return $this->_get(self::KEY_RULE_ID);
}
/**
* Set rule id
*
* @param int $ruleId
* @return $this
*/
public function setRuleId($ruleId)
{
return $this->setData(self::KEY_RULE_ID, $ruleId);
}
/**
* Get rule name
*
* @return string|null
*/
public function getName()
{
return $this->_get(self::KEY_NAME);
}
/**
* Set rule name
*
* @param string $name
* @return $this
*/
public function setName($name)
{
return $this->setData(self::KEY_NAME, $name);
}
/**
* Get description
*
* @return string|null
*/
public function getDescription()
{
return $this->_get(self::KEY_DESCRIPTION);
}
/**
* Set description
*
* @param string $description
* @return $this
*/
public function setDescription($description)
{
return $this->setData(self::KEY_DESCRIPTION, $description);
}
/**
* Get the start date when the coupon is active
*
* @return string|null
*/
public function getFromDate()
{
return $this->_get(self::KEY_FROM_DATE);
}
/**
* Set the star date when the coupon is active
*
* @param string $fromDate
* @return $this
*/
public function setFromDate($fromDate)
{
return $this->setData(self::KEY_FROM_DATE, $fromDate);
}
/**
* Get the end date when the coupon is active
*
* @return string|null
*/
public function getToDate()
{
return $this->_get(self::KEY_TO_DATE);
}
/**
* Set the end date when the coupon is active
*
* @param string $toDate
* @return $this
*/
public function setToDate($toDate)
{
return $this->setData(self::KEY_TO_DATE, $toDate);
}
/**
* Get number of uses per customer
*
* @return int
*/
public function getUsesPerCustomer()
{
return $this->_get(self::KEY_USES_PER_CUSTOMER);
}
/**
* Set number of uses per customer
*
* @param int $usesPerCustomer
* @return $this
*/
public function setUsesPerCustomer($usesPerCustomer)
{
return $this->setData(self::KEY_USES_PER_CUSTOMER, $usesPerCustomer);
}
/**
* Whether the rule is active
*
* @return bool
* @SuppressWarnings(PHPMD.BooleanGetMethodName)
*/
public function getIsActive()
{
return $this->_get(self::KEY_IS_ACTIVE);
}
/**
* Set whether the coupon is active
*
* @param bool $isActive
* @return bool
*/
public function setIsActive($isActive)
{
return $this->setData(self::KEY_IS_ACTIVE, $isActive);
}
/**
* Get condition for the rule
*
* @return \Magento\SalesRule\Api\Data\ConditionInterface|null
*/
public function getCondition()
{
return $this->_get(self::KEY_CONDITION);
}
/**
* Set condition for the rule
*
* @param \Magento\SalesRule\Api\Data\ConditionInterface|null $condition
* @return $this
*/
public function setCondition(ConditionInterface $condition = null)
{
return $this->setData(self::KEY_CONDITION, $condition);
}
/**
* Get action condition
*
* @return \Magento\SalesRule\Api\Data\ConditionInterface|null
*/
public function getActionCondition()
{
return $this->_get(self::KEY_ACTION_CONDITION);
}
/**
* Set action condition
*
* @param \Magento\SalesRule\Api\Data\ConditionInterface|null $actionCondition
* @return $this
*/
public function setActionCondition(ConditionInterface $actionCondition = null)
{
return $this->setData(self::KEY_ACTION_CONDITION, $actionCondition);
}
/**
* Whether to stop rule processing
*
* @return bool
* @SuppressWarnings(PHPMD.BooleanGetMethodName)
*/
public function getStopRulesProcessing()
{
return $this->_get(self::KEY_STOP_RULES_PROCESSING);
}
/**
* Set whether to stop rule processing
*
* @param bool $stopRulesProcessing
* @return $this
*/
public function setStopRulesProcessing($stopRulesProcessing)
{
return $this->setData(self::KEY_STOP_RULES_PROCESSING, $stopRulesProcessing);
}
/**
* TODO: is this field needed
*
* @return bool
* @SuppressWarnings(PHPMD.BooleanGetMethodName)
*/
public function getIsAdvanced()
{
return $this->_get(self::KEY_IS_ADVANCED);
}
/**
* Set Is Advanced
*
* @param bool $isAdvanced
* @return $this
*/
public function setIsAdvanced($isAdvanced)
{
return $this->setData(self::KEY_IS_ADVANCED, $isAdvanced);
}
/**
* Get display label
*
* @return \Magento\SalesRule\Api\Data\RuleLabelInterface[]|null
*/
public function getStoreLabels()
{
return $this->_get(self::KEY_STORE_LABELS);
}
/**
* Set display label
*
* @param \Magento\SalesRule\Api\Data\RuleLabelInterface[]|null $storeLabels
* @return $this
*/
public function setStoreLabels(array $storeLabels = null)
{
return $this->setData(self::KEY_STORE_LABELS, $storeLabels);
}
/**
* Get a list of websites the rule applies to
*
* @return int[]
*/
public function getWebsiteIds()
{
return $this->_get(self::KEY_WEBSITES);
}
/**
* Set the websites the rule applies to
*
* @param int[] $websites
* @return $this
*/
public function setWebsiteIds(array $websites)
{
return $this->setData(self::KEY_WEBSITES, $websites);
}
/**
* Get ids of customer groups that the rule applies to
*
* @return int[]
*/
public function getCustomerGroupIds()
{
return $this->_get(self::KEY_CUSTOMER_GROUPS);
}
/**
* Set the customer groups that the rule applies to
*
* @param int[] $customerGroups
* @return $this
*/
public function setCustomerGroupIds(array $customerGroups)
{
return $this->setData(self::KEY_CUSTOMER_GROUPS, $customerGroups);
}
/**
* Return product ids
*
* @return int[]|null
*/
public function getProductIds()
{
return $this->_get(self::KEY_PRODUCT_IDS);
}
/**
* Set product ids
*
* @param int[]|null $productIds
* @return $this
*/
public function setProductIds(array $productIds = null)
{
return $this->setData(self::KEY_PRODUCT_IDS, $productIds);
}
/**
* Get sort order
*
* @return int
*/
public function getSortOrder()
{
return $this->_get(self::KEY_SORT_ORDER);
}
/**
* Set Sort Order
*
* @param int $sortOrder
* @return $this
*/
public function setSortOrder($sortOrder)
{
return $this->setData(self::KEY_SORT_ORDER, $sortOrder);
}
/**
* Get simple action of the rule
*
* @return string|null
*/
public function getSimpleAction()
{
return $this->_get(self::KEY_SIMPLE_ACTION);
}
/**
* Set simple action
*
* @param string $simpleAction
* @return $this
*/
public function setSimpleAction($simpleAction)
{
return $this->setData(self::KEY_SIMPLE_ACTION, $simpleAction);
}
/**
* Get discount amount
*
* @return float
*/
public function getDiscountAmount()
{
return $this->_get(self::KEY_DISCOUNT_AMOUNT);
}
/**
* Set discount amount
*
* @param float $discountAmount
* @return $this
*/
public function setDiscountAmount($discountAmount)
{
return $this->setData(self::KEY_DISCOUNT_AMOUNT, $discountAmount);
}
/**
* Return maximum qty discount is applied
*
* @return float
*/
public function getDiscountQty()
{
return $this->_get(self::KEY_DISCOUNT_QTY);
}
/**
* Set maximum qty discount is applied
*
* @param float $discountQty
* @return $this
*/
public function setDiscountQty($discountQty)
{
return $this->setData(self::KEY_DISCOUNT_QTY, $discountQty);
}
/**
* Get discount step
*
* @return int
*/
public function getDiscountStep()
{
return $this->_get(self::KEY_DISCOUNT_STEP);
}
/**
* Set discount step
*
* @param int $discountStep
* @return $this
*/
public function setDiscountStep($discountStep)
{
return $this->setData(self::KEY_DISCOUNT_STEP, $discountStep);
}
/**
* Whether the rule applies to shipping
*
* @return bool
* @SuppressWarnings(PHPMD.BooleanGetMethodName)
*/
public function getApplyToShipping()
{
return $this->_get(self::KEY_APPLY_TO_SHIPPING);
}
/**
* Set whether the rule applies to shipping
*
* @param bool $applyToShipping
* @return $this
*/
public function setApplyToShipping($applyToShipping)
{
return $this->setData(self::KEY_APPLY_TO_SHIPPING, $applyToShipping);
}
/**
* Return how many times the rule has been used
*
* @return int
*/
public function getTimesUsed()
{
return $this->_get(self::KEY_TIMES_USED);
}
/**
* Set how many times the rule has been used
*
* @param int $timesUsed
* @return $this
*/
public function setTimesUsed($timesUsed)
{
return $this->setData(self::KEY_TIMES_USED, $timesUsed);
}
/**
* Return whether the rule is in RSS
*
* @return bool
* @SuppressWarnings(PHPMD.BooleanGetMethodName)
*/
public function getIsRss()
{
return $this->_get(self::KEY_IS_RSS);
}
/**
* Set whether the rule is shown in RSS
*
* @param bool $isRss
* @return $this
*/
public function setIsRss($isRss)
{
return $this->setData(self::KEY_IS_RSS, $isRss);
}
/**
* Get coupon type
*
* @return string
*/
public function getCouponType()
{
return $this->_get(self::KEY_COUPON_TYPE);
}
/**
* Set coupon type
*
* @param string $couponType
* @return $this
*/
public function setCouponType($couponType)
{
return $this->setData(self::KEY_COUPON_TYPE, $couponType);
}
/**
* Whether to auto generate coupon
*
* @return bool
* @SuppressWarnings(PHPMD.BooleanGetMethodName)
*/
public function getUseAutoGeneration()
{
return $this->_get(self::KEY_USE_AUTO_GENERATION);
}
/**
* Set whether the rule uses auto coupon generation
*
* @param bool $useAutoGeneration
* @return $this
*/
public function setUseAutoGeneration($useAutoGeneration)
{
return $this->setData(self::KEY_USE_AUTO_GENERATION, $useAutoGeneration);
}
/**
* Return limit of uses per coupon
*
* @return int
*/
public function getUsesPerCoupon()
{
return $this->_get(self::KEY_USES_PER_COUPON);
}
/**
* Set the limit of uses per coupon
*
* @param int $usesPerCoupon
* @return $this
*/
public function setUsesPerCoupon($usesPerCoupon)
{
return $this->setData(self::KEY_USES_PER_COUPON, $usesPerCoupon);
}
/**
* When to grant free shipping
*
* @return string
*/
public function getSimpleFreeShipping()
{
return $this->_get(self::KEY_SIMPLE_FREE_SHIPPING);
}
/**
* Set when to grant free shipping
*
* @param string $simpleFreeShipping
* @return $this
*/
public function setSimpleFreeShipping($simpleFreeShipping)
{
return $this->setData(self::KEY_SIMPLE_FREE_SHIPPING, $simpleFreeShipping);
}
/**
* @inheritdoc
*
* @return \Magento\SalesRule\Api\Data\RuleExtensionInterface|null
*/
public function getExtensionAttributes()
{
return $this->_getExtensionAttributes();
}
/**
* @inheritdoc
*
* @param \Magento\SalesRule\Api\Data\RuleExtensionInterface $extensionAttributes
* @return $this
*/
public function setExtensionAttributes(
\Magento\SalesRule\Api\Data\RuleExtensionInterface $extensionAttributes
) {
return $this->_setExtensionAttributes($extensionAttributes);
}
}