Rule.php 14 KB

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