123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\SalesRule\Model;
- /**
- * SalesRule Coupon Model
- *
- * @api
- * @since 100.0.2
- */
- class Coupon extends \Magento\Framework\Model\AbstractExtensibleModel implements
- \Magento\SalesRule\Api\Data\CouponInterface
- {
- const KEY_COUPON_ID = 'coupon_id';
- const KEY_RULE_ID = 'rule_id';
- const KEY_CODE = 'code';
- const KEY_USAGE_LIMIT = 'usage_limit';
- const KEY_USAGE_PER_CUSTOMER = 'usage_per_customer';
- const KEY_TIMES_USED = 'times_used';
- const KEY_EXPIRATION_DATE = 'expiration_date';
- const KEY_IS_PRIMARY = 'is_primary';
- const KEY_CREATED_AT = 'created_at';
- const KEY_TYPE = 'type';
- /**
- * Constructor
- *
- * @return void
- */
- protected function _construct()
- {
- parent::_construct();
- $this->_init(\Magento\SalesRule\Model\ResourceModel\Coupon::class);
- }
- /**
- * Set rule instance
- *
- * @param Rule $rule
- * @return $this
- */
- public function setRule(Rule $rule)
- {
- $this->setRuleId($rule->getId());
- return $this;
- }
- /**
- * Load primary coupon for specified rule
- *
- * @param Rule|int $rule
- * @return $this
- */
- public function loadPrimaryByRule($rule)
- {
- $this->getResource()->loadPrimaryByRule($this, $rule);
- return $this;
- }
- /**
- * Load Cart Price Rule by coupon code
- *
- * @param string $couponCode
- * @return $this
- */
- public function loadByCode($couponCode)
- {
- $this->load($couponCode, 'code');
- return $this;
- }
- //@codeCoverageIgnoreStart
- /**
- * Get coupon id
- *
- * @return int|null
- */
- public function getCouponId()
- {
- return $this->getData(self::KEY_COUPON_ID);
- }
- /**
- * Set coupon id
- *
- * @param int $couponId
- * @return $this
- */
- public function setCouponId($couponId)
- {
- return $this->setData(self::KEY_COUPON_ID, $couponId);
- }
- /**
- * Get the id of the rule associated with the coupon
- *
- * @return int
- */
- public function getRuleId()
- {
- return $this->getData(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 coupon code
- *
- * @return string|null
- */
- public function getCode()
- {
- return $this->getData(self::KEY_CODE);
- }
- /**
- * Set coupon code
- *
- * @param string $code
- * @return $this
- */
- public function setCode($code)
- {
- return $this->setData(self::KEY_CODE, $code);
- }
- /**
- * Get usage limit
- *
- * @return int|null
- */
- public function getUsageLimit()
- {
- return $this->getData(self::KEY_USAGE_LIMIT);
- }
- /**
- * Set usage limit
- *
- * @param int $usageLimit
- * @return $this
- */
- public function setUsageLimit($usageLimit)
- {
- return $this->setData(self::KEY_USAGE_LIMIT, $usageLimit);
- }
- /**
- * Get usage limit per customer
- *
- * @return int|null
- */
- public function getUsagePerCustomer()
- {
- return $this->getData(self::KEY_USAGE_PER_CUSTOMER);
- }
- /**
- * Set usage limit per customer
- *
- * @param int $usagePerCustomer
- * @return $this
- */
- public function setUsagePerCustomer($usagePerCustomer)
- {
- return $this->setData(self::KEY_USAGE_PER_CUSTOMER, $usagePerCustomer);
- }
- /**
- * Get the number of times the coupon has been used
- *
- * @return int
- */
- public function getTimesUsed()
- {
- return $this->getData(self::KEY_TIMES_USED);
- }
- /**
- * Set Times Used
- *
- * @param int $timesUsed
- * @return $this
- */
- public function setTimesUsed($timesUsed)
- {
- return $this->setData(self::KEY_TIMES_USED, $timesUsed);
- }
- /**
- * Get expiration date
- *
- * @return string|null
- */
- public function getExpirationDate()
- {
- return $this->getData(self::KEY_EXPIRATION_DATE);
- }
- /**
- * Set expiration date
- *
- * @param string $expirationDate
- * @return $this
- */
- public function setExpirationDate($expirationDate)
- {
- return $this->setData(self::KEY_EXPIRATION_DATE, $expirationDate);
- }
- /**
- * Whether the coupon is primary coupon for the rule that it's associated with
- *
- * @return bool
- * @SuppressWarnings(PHPMD.BooleanGetMethodName)
- */
- public function getIsPrimary()
- {
- return $this->getData(self::KEY_IS_PRIMARY);
- }
- /**
- * Set whether the coupon is the primary coupon for the rule that it's associated with
- *
- * @param bool $isPrimary
- * @return $this
- */
- public function setIsPrimary($isPrimary)
- {
- return $this->setData(self::KEY_IS_PRIMARY, $isPrimary);
- }
- /**
- * Date when the coupon is created
- *
- * @return string|null
- */
- public function getCreatedAt()
- {
- return $this->getData(self::KEY_CREATED_AT);
- }
- /**
- * Set the date the coupon is created
- *
- * @param string $createdAt
- * @return $this
- */
- public function setCreatedAt($createdAt)
- {
- return $this->setData(self::KEY_CREATED_AT, $createdAt);
- }
- /**
- * Type of coupon
- *
- * @return int|null
- */
- public function getType()
- {
- return $this->getData(self::KEY_TYPE);
- }
- /**
- * Set type
- *
- * @param int $type
- * @return $this
- */
- public function setType($type)
- {
- return $this->setData(self::KEY_TYPE, $type);
- }
- /**
- * Retrieve existing extension attributes object or create a new one.
- *
- * @return \Magento\SalesRule\Api\Data\CouponExtensionInterface|null
- */
- public function getExtensionAttributes()
- {
- return $this->_getExtensionAttributes();
- }
- /**
- * Set an extension attributes object.
- *
- * @param \Magento\SalesRule\Api\Data\CouponExtensionInterface $extensionAttributes
- * @return $this
- */
- public function setExtensionAttributes(
- \Magento\SalesRule\Api\Data\CouponExtensionInterface $extensionAttributes
- ) {
- return $this->_setExtensionAttributes($extensionAttributes);
- }
- //@codeCoverageIgnoreEnd
- }
|