Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions
Coupon Class Reference
Inheritance diagram for Coupon:
AbstractExtensibleModel CouponInterface AbstractModel CustomAttributesDataInterface ExtensibleDataInterface DataObject ExtensibleDataInterface

Public Member Functions

 setRule (\Magento\SalesRule\Model\Rule $rule)
 
 loadPrimaryByRule ($rule)
 
 loadByCode ($couponCode)
 
 getCouponId ()
 
 setCouponId ($couponId)
 
 getRuleId ()
 
 setRuleId ($ruleId)
 
 getCode ()
 
 setCode ($code)
 
 getUsageLimit ()
 
 setUsageLimit ($usageLimit)
 
 getUsagePerCustomer ()
 
 setUsagePerCustomer ($usagePerCustomer)
 
 getTimesUsed ()
 
 setTimesUsed ($timesUsed)
 
 getExpirationDate ()
 
 setExpirationDate ($expirationDate)
 
 getIsPrimary ()
 
 setIsPrimary ($isPrimary)
 
 getCreatedAt ()
 
 setCreatedAt ($createdAt)
 
 getType ()
 
 setType ($type)
 
 getExtensionAttributes ()
 
 setExtensionAttributes (\Magento\SalesRule\Api\Data\CouponExtensionInterface $extensionAttributes)
 
- Public Member Functions inherited from AbstractExtensibleModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 getCustomAttributes ()
 
 getCustomAttribute ($attributeCode)
 
 setCustomAttributes (array $attributes)
 
 setCustomAttribute ($attributeCode, $attributeValue)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 setId ($value)
 
 __sleep ()
 
 __wakeup ()
 
- Public Member Functions inherited from AbstractModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 __sleep ()
 
 __wakeup ()
 
 setIdFieldName ($name)
 
 getIdFieldName ()
 
 getId ()
 
 setId ($value)
 
 isDeleted ($isDeleted=null)
 
 hasDataChanges ()
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 setDataChanges ($value)
 
 getOrigData ($key=null)
 
 setOrigData ($key=null, $data=null)
 
 dataHasChangedFor ($field)
 
 getResourceName ()
 
 getResourceCollection ()
 
 getCollection ()
 
 load ($modelId, $field=null)
 
 beforeLoad ($identifier, $field=null)
 
 afterLoad ()
 
 isSaveAllowed ()
 
 setHasDataChanges ($flag)
 
 save ()
 
 afterCommitCallback ()
 
 isObjectNew ($flag=null)
 
 beforeSave ()
 
 validateBeforeSave ()
 
 getCacheTags ()
 
 cleanModelCache ()
 
 afterSave ()
 
 delete ()
 
 beforeDelete ()
 
 afterDelete ()
 
 afterDeleteCommit ()
 
 getResource ()
 
 getEntityId ()
 
 setEntityId ($entityId)
 
 clearInstance ()
 
 getStoredData ()
 
 getEventPrefix ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 

Data Fields

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'
 
- Data Fields inherited from CustomAttributesDataInterface
const CUSTOM_ATTRIBUTES = 'custom_attributes'
 
- Data Fields inherited from ExtensibleDataInterface
const EXTENSION_ATTRIBUTES_KEY = 'extension_attributes'
 
- Data Fields inherited from CouponInterface
const TYPE_MANUAL = 0
 
const TYPE_GENERATED = 1
 

Protected Member Functions

 _construct ()
 
- Protected Member Functions inherited from AbstractExtensibleModel
 filterCustomAttributes ($data)
 
 initializeCustomAttributes ()
 
 convertCustomAttributeValues (array &$customAttributes)
 
 getCustomAttributesCodes ()
 
 _setExtensionAttributes (\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)
 
 _getExtensionAttributes ()
 
- Protected Member Functions inherited from AbstractModel
 _construct ()
 
 _init ($resourceModel)
 
 _setResourceModel ($resourceName, $collectionName=null)
 
 _getResource ()
 
 _getEventData ()
 
 _beforeLoad ($modelId, $field=null)
 
 _afterLoad ()
 
 _hasModelChanged ()
 
 _getValidatorBeforeSave ()
 
 _createValidatorBeforeSave ()
 
 _getValidationRulesBeforeSave ()
 
 _clearReferences ()
 
 _clearData ()
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Additional Inherited Members

- Protected Attributes inherited from AbstractExtensibleModel
 $extensionAttributesFactory
 
 $extensionAttributes
 
 $customAttributeFactory
 
 $customAttributesCodes = null
 
 $customAttributesChanged = false
 
- Protected Attributes inherited from AbstractModel
 $_eventPrefix = 'core_abstract'
 
 $_eventObject = 'object'
 
 $_idFieldName = 'id'
 
 $_hasDataChanges = false
 
 $_origData
 
 $_isDeleted = false
 
 $_resource
 
 $_resourceCollection
 
 $_resourceName
 
 $_collectionName
 
 $_cacheTag = false
 
 $_dataSaveAllowed = true
 
 $_isObjectNew = null
 
 $_validatorBeforeSave = null
 
 $_eventManager
 
 $_cacheManager
 
 $_registry
 
 $_logger
 
 $_appState
 
 $_actionValidator
 
 $storedData = []
 
- Protected Attributes inherited from DataObject
 $_data = []
 
- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

SalesRule Coupon Model

@api

Since
100.0.2

Definition at line 14 of file Coupon.php.

Member Function Documentation

◆ _construct()

_construct ( )
protected

Constructor

Returns
void

Definition at line 33 of file Coupon.php.

34  {
35  parent::_construct();
36  $this->_init(\Magento\SalesRule\Model\ResourceModel\Coupon::class);
37  }

◆ getCode()

getCode ( )

Get coupon code

Returns
string|null

Implements CouponInterface.

Definition at line 124 of file Coupon.php.

125  {
126  return $this->getData(self::KEY_CODE);
127  }

◆ getCouponId()

getCouponId ( )

Get coupon id

Returns
int|null

Implements CouponInterface.

Definition at line 82 of file Coupon.php.

83  {
84  return $this->getData(self::KEY_COUPON_ID);
85  }

◆ getCreatedAt()

getCreatedAt ( )

Date when the coupon is created

Returns
string|null

Implements CouponInterface.

Definition at line 249 of file Coupon.php.

250  {
251  return $this->getData(self::KEY_CREATED_AT);
252  }

◆ getExpirationDate()

getExpirationDate ( )

Get expiration date

Returns
string|null

Implements CouponInterface.

Definition at line 206 of file Coupon.php.

207  {
208  return $this->getData(self::KEY_EXPIRATION_DATE);
209  }

◆ getExtensionAttributes()

getExtensionAttributes ( )

Retrieve existing extension attributes object or create a new one.

Returns
\Magento\SalesRule\Api\Data\CouponExtensionInterface|null

Implements CouponInterface.

Definition at line 289 of file Coupon.php.

◆ getIsPrimary()

getIsPrimary ( )

Whether the coupon is primary coupon for the rule that it's associated with

Returns
bool @SuppressWarnings(PHPMD.BooleanGetMethodName)

Implements CouponInterface.

Definition at line 228 of file Coupon.php.

229  {
230  return $this->getData(self::KEY_IS_PRIMARY);
231  }

◆ getRuleId()

getRuleId ( )

Get the id of the rule associated with the coupon

Returns
int

Implements CouponInterface.

Definition at line 103 of file Coupon.php.

104  {
105  return $this->getData(self::KEY_RULE_ID);
106  }

◆ getTimesUsed()

getTimesUsed ( )

Get the number of times the coupon has been used

Returns
int

Implements CouponInterface.

Definition at line 187 of file Coupon.php.

188  {
189  return $this->getData(self::KEY_TIMES_USED);
190  }

◆ getType()

getType ( )

Type of coupon

Returns
int|null

Implements CouponInterface.

Definition at line 270 of file Coupon.php.

271  {
272  return $this->getData(self::KEY_TYPE);
273  }

◆ getUsageLimit()

getUsageLimit ( )

Get usage limit

Returns
int|null

Implements CouponInterface.

Definition at line 145 of file Coupon.php.

146  {
147  return $this->getData(self::KEY_USAGE_LIMIT);
148  }

◆ getUsagePerCustomer()

getUsagePerCustomer ( )

Get usage limit per customer

Returns
int|null

Implements CouponInterface.

Definition at line 166 of file Coupon.php.

167  {
168  return $this->getData(self::KEY_USAGE_PER_CUSTOMER);
169  }

◆ loadByCode()

loadByCode (   $couponCode)

Load Cart Price Rule by coupon code

Parameters
string$couponCode
Returns
$this

Definition at line 69 of file Coupon.php.

70  {
71  $this->load($couponCode, 'code');
72  return $this;
73  }

◆ loadPrimaryByRule()

loadPrimaryByRule (   $rule)

Load primary coupon for specified rule

Parameters
\Magento\SalesRule\Model\Rule | int$rule
Returns
$this

Definition at line 57 of file Coupon.php.

58  {
59  $this->getResource()->loadPrimaryByRule($this, $rule);
60  return $this;
61  }

◆ setCode()

setCode (   $code)

Set coupon code

Parameters
string$code
Returns
$this

Implements CouponInterface.

Definition at line 135 of file Coupon.php.

136  {
137  return $this->setData(self::KEY_CODE, $code);
138  }
$code
Definition: info.phtml:12

◆ setCouponId()

setCouponId (   $couponId)

Set coupon id

Parameters
int$couponId
Returns
$this

Implements CouponInterface.

Definition at line 93 of file Coupon.php.

94  {
95  return $this->setData(self::KEY_COUPON_ID, $couponId);
96  }

◆ setCreatedAt()

setCreatedAt (   $createdAt)

Set the date the coupon is created

Parameters
string$createdAt
Returns
$this

Implements CouponInterface.

Definition at line 260 of file Coupon.php.

261  {
262  return $this->setData(self::KEY_CREATED_AT, $createdAt);
263  }

◆ setExpirationDate()

setExpirationDate (   $expirationDate)

Set expiration date

Parameters
string$expirationDate
Returns
$this

Implements CouponInterface.

Definition at line 217 of file Coupon.php.

218  {
219  return $this->setData(self::KEY_EXPIRATION_DATE, $expirationDate);
220  }

◆ setExtensionAttributes()

setExtensionAttributes ( \Magento\SalesRule\Api\Data\CouponExtensionInterface  $extensionAttributes)

Set an extension attributes object.

Parameters
\Magento\SalesRule\Api\Data\CouponExtensionInterface$extensionAttributes
Returns
$this

Implements CouponInterface.

Definition at line 300 of file Coupon.php.

302  {
304  }
_setExtensionAttributes(\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)

◆ setIsPrimary()

setIsPrimary (   $isPrimary)

Set whether the coupon is the primary coupon for the rule that it's associated with

Parameters
bool$isPrimary
Returns
$this

Implements CouponInterface.

Definition at line 239 of file Coupon.php.

240  {
241  return $this->setData(self::KEY_IS_PRIMARY, $isPrimary);
242  }

◆ setRule()

setRule ( \Magento\SalesRule\Model\Rule  $rule)

Set rule instance

Parameters
\Magento\SalesRule\Model\Rule$rule
Returns
$this

Definition at line 45 of file Coupon.php.

46  {
47  $this->setRuleId($rule->getId());
48  return $this;
49  }

◆ setRuleId()

setRuleId (   $ruleId)

Set rule id

Parameters
int$ruleId
Returns
$this

Implements CouponInterface.

Definition at line 114 of file Coupon.php.

115  {
116  return $this->setData(self::KEY_RULE_ID, $ruleId);
117  }

◆ setTimesUsed()

setTimesUsed (   $timesUsed)
Parameters
int$timesUsed
Returns
$this

Implements CouponInterface.

Definition at line 196 of file Coupon.php.

197  {
198  return $this->setData(self::KEY_TIMES_USED, $timesUsed);
199  }

◆ setType()

setType (   $type)
Parameters
int$type
Returns
$this

Implements CouponInterface.

Definition at line 279 of file Coupon.php.

280  {
281  return $this->setData(self::KEY_TYPE, $type);
282  }
$type
Definition: item.phtml:13

◆ setUsageLimit()

setUsageLimit (   $usageLimit)

Set usage limit

Parameters
int$usageLimit
Returns
$this

Implements CouponInterface.

Definition at line 156 of file Coupon.php.

157  {
158  return $this->setData(self::KEY_USAGE_LIMIT, $usageLimit);
159  }

◆ setUsagePerCustomer()

setUsagePerCustomer (   $usagePerCustomer)

Set usage limit per customer

Parameters
int$usagePerCustomer
Returns
$this

Implements CouponInterface.

Definition at line 177 of file Coupon.php.

178  {
179  return $this->setData(self::KEY_USAGE_PER_CUSTOMER, $usagePerCustomer);
180  }

Field Documentation

◆ KEY_CODE

const KEY_CODE = 'code'

Definition at line 19 of file Coupon.php.

◆ KEY_COUPON_ID

const KEY_COUPON_ID = 'coupon_id'

Definition at line 17 of file Coupon.php.

◆ KEY_CREATED_AT

const KEY_CREATED_AT = 'created_at'

Definition at line 25 of file Coupon.php.

◆ KEY_EXPIRATION_DATE

const KEY_EXPIRATION_DATE = 'expiration_date'

Definition at line 23 of file Coupon.php.

◆ KEY_IS_PRIMARY

const KEY_IS_PRIMARY = 'is_primary'

Definition at line 24 of file Coupon.php.

◆ KEY_RULE_ID

const KEY_RULE_ID = 'rule_id'

Definition at line 18 of file Coupon.php.

◆ KEY_TIMES_USED

const KEY_TIMES_USED = 'times_used'

Definition at line 22 of file Coupon.php.

◆ KEY_TYPE

const KEY_TYPE = 'type'

Definition at line 26 of file Coupon.php.

◆ KEY_USAGE_LIMIT

const KEY_USAGE_LIMIT = 'usage_limit'

Definition at line 20 of file Coupon.php.

◆ KEY_USAGE_PER_CUSTOMER

const KEY_USAGE_PER_CUSTOMER = 'usage_per_customer'

Definition at line 21 of file Coupon.php.


The documentation for this class was generated from the following file: