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

Public Member Functions

 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Data\FormFactory $formFactory, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\SalesRule\Model\CouponFactory $couponFactory, \Magento\SalesRule\Model\Coupon\CodegeneratorFactory $codegenFactory, \Magento\SalesRule\Model\Rule\Condition\CombineFactory $condCombineFactory, \Magento\SalesRule\Model\Rule\Condition\Product\CombineFactory $condProdCombineF, \Magento\SalesRule\Model\ResourceModel\Coupon\Collection $couponCollection, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[], ExtensionAttributesFactory $extensionFactory=null, AttributeValueFactory $customAttributeFactory=null, \Magento\Framework\Serialize\Serializer\Json $serializer=null)
 
 loadRelations ()
 
 loadCouponCode ()
 
 afterSave ()
 
 loadPost (array $data)
 
 getConditionsInstance ()
 
 getActionsInstance ()
 
 getCouponCodeGenerator ()
 
 setCouponCodeGenerator (\Magento\SalesRule\Model\Coupon\CodegeneratorInterface $codeGenerator)
 
 getPrimaryCoupon ()
 
 getCustomerGroupIds ()
 
 getStoreLabel ($store=null)
 
 getStoreLabels ()
 
 getCoupons ()
 
 getCouponTypes ()
 
 getFromDate ()
 
 getToDate ()
 
 hasIsValidForAddress ($address)
 
 setIsValidForAddress ($address, $validationResult)
 
 getIsValidForAddress ($address)
 
 getConditionsFieldSetId ($formName='')
 
 getActionsFieldSetId ($formName='')
 
- Public Member Functions inherited from AbstractModel
 getConditionsInstance ()
 
 getActionsInstance ()
 
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Data\FormFactory $formFactory, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[], ExtensionAttributesFactory $extensionFactory=null, AttributeValueFactory $customAttributeFactory=null, \Magento\Framework\Serialize\Serializer\Json $serializer=null)
 
 beforeSave ()
 
 setConditions ($conditions)
 
 getConditions ()
 
 setActions ($actions)
 
 getActions ()
 
 getForm ()
 
 loadPost (array $data)
 
 validate (\Magento\Framework\DataObject $object)
 
 validateData (\Magento\Framework\DataObject $dataObject)
 
 isDeleteable ()
 
 setIsDeleteable ($value)
 
 isReadonly ()
 
 setIsReadonly ($value)
 
 getWebsiteIds ()
 
- 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 COUPON_TYPE_NO_COUPON = 1
 
const COUPON_TYPE_SPECIFIC = 2
 
const COUPON_TYPE_AUTO = 3
 
const TO_PERCENT_ACTION = 'to_percent'
 
const BY_PERCENT_ACTION = 'by_percent'
 
const TO_FIXED_ACTION = 'to_fixed'
 
const BY_FIXED_ACTION = 'by_fixed'
 
const CART_FIXED_ACTION = 'cart_fixed'
 
const BUY_X_GET_Y_ACTION = 'buy_x_get_y'
 
- Data Fields inherited from CustomAttributesDataInterface
const CUSTOM_ATTRIBUTES = 'custom_attributes'
 
- Data Fields inherited from ExtensibleDataInterface
const EXTENSION_ATTRIBUTES_KEY = 'extension_attributes'
 

Protected Member Functions

 _construct ()
 
 _afterLoad ()
 
- Protected Member Functions inherited from AbstractModel
 _resetConditions ($conditions=null)
 
 _resetActions ($actions=null)
 
 _convertFlatToRecursive (array $data)
 
- 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)
 

Protected Attributes

 $_couponCodeGenerator
 
 $_eventPrefix = 'salesrule_rule'
 
 $_eventObject = 'rule'
 
 $_primaryCoupon
 
 $_coupons
 
 $_couponTypes
 
 $_validatedAddresses = []
 
 $_couponFactory
 
 $_codegenFactory
 
 $_condCombineFactory
 
 $_condProdCombineF
 
 $_couponCollection
 
 $_storeManager
 
- Protected Attributes inherited from AbstractModel
 $_conditions
 
 $_actions
 
 $_form
 
 $_isDeleteable = true
 
 $_isReadonly = false
 
 $serializer
 
 $_formFactory
 
 $_localeDate
 
- 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 = []
 

Additional Inherited Members

- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Shopping Cart Rule data model

@api @method string getName() @method \Magento\SalesRule\Model\Rule setName(string $value) @method string getDescription() @method \Magento\SalesRule\Model\Rule setDescription(string $value) @method \Magento\SalesRule\Model\Rule setFromDate(string $value) @method \Magento\SalesRule\Model\Rule setToDate(string $value) @method int getUsesPerCustomer() @method \Magento\SalesRule\Model\Rule setUsesPerCustomer(int $value) @method int getUsesPerCoupon() @method \Magento\SalesRule\Model\Rule setUsesPerCoupon(int $value) @method \Magento\SalesRule\Model\Rule setCustomerGroupIds(string $value) @method int getIsActive() @method \Magento\SalesRule\Model\Rule setIsActive(int $value) @method string getConditionsSerialized() @method \Magento\SalesRule\Model\Rule setConditionsSerialized(string $value) @method string getActionsSerialized() @method \Magento\SalesRule\Model\Rule setActionsSerialized(string $value) @method int getStopRulesProcessing() @method \Magento\SalesRule\Model\Rule setStopRulesProcessing(int $value) @method int getIsAdvanced() @method \Magento\SalesRule\Model\Rule setIsAdvanced(int $value) @method string getProductIds() @method \Magento\SalesRule\Model\Rule setProductIds(string $value) @method int getSortOrder() @method \Magento\SalesRule\Model\Rule setSortOrder(int $value) @method string getSimpleAction() @method \Magento\SalesRule\Model\Rule setSimpleAction(string $value) @method float getDiscountAmount() @method \Magento\SalesRule\Model\Rule setDiscountAmount(float $value) @method float getDiscountQty() @method \Magento\SalesRule\Model\Rule setDiscountQty(float $value) @method int getDiscountStep() @method \Magento\SalesRule\Model\Rule setDiscountStep(int $value) @method int getApplyToShipping() @method \Magento\SalesRule\Model\Rule setApplyToShipping(int $value) @method int getTimesUsed() @method \Magento\SalesRule\Model\Rule setTimesUsed(int $value) @method int getIsRss() @method \Magento\SalesRule\Model\Rule setIsRss(int $value) @method string getWebsiteIds() @method \Magento\SalesRule\Model\Rule setWebsiteIds(string $value) @method int getCouponType() @method \Magento\SalesRule\Model\Rule setCouponType(int $value) @method int getUseAutoGeneration() @method \Magento\SalesRule\Model\Rule setUseAutoGeneration(int $value) @method string getCouponCode() @method \Magento\SalesRule\Model\Rule setCouponCode(string $value) @method int getRuleId() @method \Magento\SalesRule\Model\Rule setRuleId(int $ruleId) @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Since
100.0.2

Definition at line 68 of file Rule.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\Model\Context  $context,
\Magento\Framework\Registry  $registry,
\Magento\Framework\Data\FormFactory  $formFactory,
\Magento\Framework\Stdlib\DateTime\TimezoneInterface  $localeDate,
\Magento\SalesRule\Model\CouponFactory  $couponFactory,
\Magento\SalesRule\Model\Coupon\CodegeneratorFactory  $codegenFactory,
\Magento\SalesRule\Model\Rule\Condition\CombineFactory  $condCombineFactory,
\Magento\SalesRule\Model\Rule\Condition\Product\CombineFactory  $condProdCombineF,
\Magento\SalesRule\Model\ResourceModel\Coupon\Collection  $couponCollection,
\Magento\Store\Model\StoreManagerInterface  $storeManager,
\Magento\Framework\Model\ResourceModel\AbstractResource  $resource = null,
\Magento\Framework\Data\Collection\AbstractDb  $resourceCollection = null,
array  $data = [],
ExtensionAttributesFactory  $extensionFactory = null,
AttributeValueFactory  $customAttributeFactory = null,
\Magento\Framework\Serialize\Serializer\Json  $serializer = null 
)

Rule constructor

Parameters
\Magento\Framework\Model\Context$context
\Magento\Framework\Registry$registry
\Magento\Framework\Data\FormFactory$formFactory
\Magento\Framework\Stdlib\DateTime\TimezoneInterface$localeDate
CouponFactory$couponFactory
Coupon\CodegeneratorFactory$codegenFactory
Rule\Condition\CombineFactory$condCombineFactory
Rule\Condition\Product\CombineFactory$condProdCombineF
ResourceModel\Coupon\Collection$couponCollection
\Magento\Store\Model\StoreManagerInterface$storeManager
\Magento\Framework\Model\ResourceModel\AbstractResource | null$resource
\Magento\Framework\Data\Collection\AbstractDb | null$resourceCollection
array$data
ExtensionAttributesFactory | null$extensionFactory
AttributeValueFactory | null$customAttributeFactory
\Magento\Framework\Serialize\Serializer\Json$serializer@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 197 of file Rule.php.

214  {
215  $this->_couponFactory = $couponFactory;
216  $this->_codegenFactory = $codegenFactory;
217  $this->_condCombineFactory = $condCombineFactory;
218  $this->_condProdCombineF = $condProdCombineF;
219  $this->_couponCollection = $couponCollection;
220  $this->_storeManager = $storeManager;
221  parent::__construct(
222  $context,
223  $registry,
224  $formFactory,
225  $localeDate,
226  $resource,
227  $resourceCollection,
228  $data,
229  $extensionFactory,
232  );
233  }
$storeManager
$resource
Definition: bulk.php:12

Member Function Documentation

◆ _afterLoad()

_afterLoad ( )
protected

Set coupon code and uses per coupon

Returns
$this

Definition at line 252 of file Rule.php.

253  {
254  $this->loadRelations();
255  return parent::_afterLoad();
256  }

◆ _construct()

_construct ( )
protected

Set resource model and Id field name

Returns
void

Definition at line 240 of file Rule.php.

241  {
242  parent::_construct();
243  $this->_init(\Magento\SalesRule\Model\ResourceModel\Rule::class);
244  $this->setIdFieldName('rule_id');
245  }

◆ afterSave()

afterSave ( )

Save/delete coupon

Returns
$this

Definition at line 286 of file Rule.php.

287  {
288  $couponCode = trim($this->getCouponCode());
289  if (strlen(
291  ) && $this->getCouponType() == self::COUPON_TYPE_SPECIFIC && !$this->getUseAutoGeneration()
292  ) {
293  $this->getPrimaryCoupon()->setCode(
295  )->setUsageLimit(
296  $this->getUsesPerCoupon() ? $this->getUsesPerCoupon() : null
297  )->setUsagePerCustomer(
298  $this->getUsesPerCustomer() ? $this->getUsesPerCustomer() : null
299  )->setExpirationDate(
300  $this->getToDate()
301  )->save();
302  } else {
303  $this->getPrimaryCoupon()->delete();
304  }
305 
306  parent::afterSave();
307  return $this;
308  }

◆ getActionsFieldSetId()

getActionsFieldSetId (   $formName = '')

Get actions field set id.

Parameters
string$formName
Returns
string
Since
100.1.0

Definition at line 636 of file Rule.php.

637  {
638  return $formName . 'rule_actions_fieldset_' . $this->getId();
639  }
$formName
Definition: gallery.phtml:11

◆ getActionsInstance()

getActionsInstance ( )

Get rule condition product combine model instance

Returns
\Magento\SalesRule\Model\Rule\Condition\Product\Combine

Definition at line 342 of file Rule.php.

343  {
344  return $this->_condProdCombineF->create();
345  }

◆ getConditionsFieldSetId()

getConditionsFieldSetId (   $formName = '')

Get conditions field set id.

Parameters
string$formName
Returns
string
Since
100.1.0

Definition at line 624 of file Rule.php.

625  {
626  return $formName . 'rule_conditions_fieldset_' . $this->getId();
627  }
$formName
Definition: gallery.phtml:11

◆ getConditionsInstance()

getConditionsInstance ( )

Get rule condition combine model instance

Returns
\Magento\SalesRule\Model\Rule\Condition\Combine

Definition at line 332 of file Rule.php.

333  {
334  return $this->_condCombineFactory->create();
335  }

◆ getCouponCodeGenerator()

getCouponCodeGenerator ( )

Returns code generator instance for auto generated coupons

Returns
\Magento\SalesRule\Model\Coupon\CodegeneratorInterface

Definition at line 352 of file Rule.php.

353  {
354  if (!$this->_couponCodeGenerator) {
355  return $this->_codegenFactory->create(['data' => ['length' => 16]]);
356  }
358  }

◆ getCoupons()

getCoupons ( )

Retrieve subordinate coupons

Returns
\Magento\SalesRule\Model\Coupon[]

Definition at line 440 of file Rule.php.

441  {
442  if ($this->_coupons === null) {
443  $this->_couponCollection->addRuleToFilter($this);
444  $this->_coupons = $this->_couponCollection->getItems();
445  }
446  return $this->_coupons;
447  }

◆ getCouponTypes()

getCouponTypes ( )

Retrieve coupon types

Returns
array

Definition at line 454 of file Rule.php.

455  {
456  if ($this->_couponTypes === null) {
457  $this->_couponTypes = [
460  ];
461  $transport = new \Magento\Framework\DataObject(
462  ['coupon_types' => $this->_couponTypes, 'is_coupon_type_auto_visible' => false]
463  );
464  $this->_eventManager->dispatch('salesrule_rule_get_coupon_types', ['transport' => $transport]);
465  $this->_couponTypes = $transport->getCouponTypes();
466  if ($transport->getIsCouponTypeAutoVisible()) {
467  $this->_couponTypes[\Magento\SalesRule\Model\Rule::COUPON_TYPE_AUTO] = __('Auto');
468  }
469  }
470  return $this->_couponTypes;
471  }
__()
Definition: __.php:13

◆ getCustomerGroupIds()

getCustomerGroupIds ( )

Get sales rule customer group Ids

Returns
array

Definition at line 391 of file Rule.php.

392  {
393  if (!$this->hasCustomerGroupIds()) {
394  $customerGroupIds = $this->_getResource()->getCustomerGroupIds($this->getId());
395  $this->setData('customer_group_ids', (array)$customerGroupIds);
396  }
397  return $this->_getData('customer_group_ids');
398  }

◆ getFromDate()

getFromDate ( )

Get from date.

Returns
string
Since
100.1.0

Definition at line 548 of file Rule.php.

549  {
550  return $this->getData('from_date');
551  }

◆ getIsValidForAddress()

getIsValidForAddress (   $address)

Get cached validation result for specific address

Parameters
Address$address
Returns
bool @SuppressWarnings(PHPMD.BooleanGetMethodName)

Definition at line 597 of file Rule.php.

598  {
599  $addressId = $this->_getAddressId($address);
600  return isset($this->_validatedAddresses[$addressId]) ? $this->_validatedAddresses[$addressId] : false;
601  }
$address
Definition: customer.php:38

◆ getPrimaryCoupon()

getPrimaryCoupon ( )

Retrieve rule's primary coupon

Returns
\Magento\SalesRule\Model\Coupon

Definition at line 376 of file Rule.php.

377  {
378  if ($this->_primaryCoupon === null) {
379  $this->_primaryCoupon = $this->_couponFactory->create();
380  $this->_primaryCoupon->loadPrimaryByRule($this->getId());
381  $this->_primaryCoupon->setRule($this)->setIsPrimary(true);
382  }
383  return $this->_primaryCoupon;
384  }

◆ getStoreLabel()

getStoreLabel (   $store = null)

Get Rule label by specified store

Parameters
\Magento\Store\Model\Store | int | bool | null$store
Returns
string|bool

Definition at line 406 of file Rule.php.

407  {
408  $storeId = $this->_storeManager->getStore($store)->getId();
409  $labels = (array)$this->getStoreLabels();
410 
411  if (isset($labels[$storeId])) {
412  return $labels[$storeId];
413  } elseif (isset($labels[0]) && $labels[0]) {
414  return $labels[0];
415  }
416 
417  return false;
418  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17

◆ getStoreLabels()

getStoreLabels ( )

Set if not yet and retrieve rule store labels

Returns
array

Definition at line 425 of file Rule.php.

426  {
427  if (!$this->hasStoreLabels()) {
428  $labels = $this->_getResource()->getStoreLabels($this->getId());
429  $this->setStoreLabels($labels);
430  }
431 
432  return $this->_getData('store_labels');
433  }

◆ getToDate()

getToDate ( )

Get to date.

Returns
string
Since
100.1.0

Definition at line 559 of file Rule.php.

560  {
561  return $this->getData('to_date');
562  }

◆ hasIsValidForAddress()

hasIsValidForAddress (   $address)

Check cached validation result for specific address

Parameters
Address$address
Returns
bool

Definition at line 570 of file Rule.php.

571  {
572  $addressId = $this->_getAddressId($address);
573  return isset($this->_validatedAddresses[$addressId]) ? true : false;
574  }
$address
Definition: customer.php:38

◆ loadCouponCode()

loadCouponCode ( )

Load coupon code

Returns
void

Definition at line 273 of file Rule.php.

274  {
275  $this->setCouponCode($this->getPrimaryCoupon()->getCode());
276  if ($this->getUsesPerCoupon() == null && !$this->getUseAutoGeneration()) {
277  $this->setUsesPerCoupon($this->getPrimaryCoupon()->getUsageLimit());
278  }
279  }

◆ loadPost()

loadPost ( array  $data)

Initialize rule model data from array. Set store labels if applicable.

Parameters
array$data
Returns
$this

Definition at line 316 of file Rule.php.

317  {
318  parent::loadPost($data);
319 
320  if (isset($data['store_labels'])) {
321  $this->setStoreLabels($data['store_labels']);
322  }
323 
324  return $this;
325  }

◆ loadRelations()

loadRelations ( )

Load all relative data

Returns
void

Definition at line 263 of file Rule.php.

264  {
265  $this->loadCouponCode();
266  }

◆ setCouponCodeGenerator()

setCouponCodeGenerator ( \Magento\SalesRule\Model\Coupon\CodegeneratorInterface  $codeGenerator)

Set code generator instance for auto generated coupons

Parameters
\Magento\SalesRule\Model\Coupon\CodegeneratorInterface$codeGenerator
Returns
void

Definition at line 366 of file Rule.php.

367  {
368  $this->_couponCodeGenerator = $codeGenerator;
369  }

◆ setIsValidForAddress()

setIsValidForAddress (   $address,
  $validationResult 
)

Set validation result for specific address to results cache

Parameters
Address$address
bool$validationResult
Returns
$this

Definition at line 583 of file Rule.php.

584  {
585  $addressId = $this->_getAddressId($address);
586  $this->_validatedAddresses[$addressId] = $validationResult;
587  return $this;
588  }
$address
Definition: customer.php:38

Field Documentation

◆ $_codegenFactory

$_codegenFactory
protected

Definition at line 153 of file Rule.php.

◆ $_condCombineFactory

$_condCombineFactory
protected

Definition at line 158 of file Rule.php.

◆ $_condProdCombineF

$_condProdCombineF
protected

Definition at line 163 of file Rule.php.

◆ $_couponCodeGenerator

$_couponCodeGenerator
protected

Definition at line 99 of file Rule.php.

◆ $_couponCollection

$_couponCollection
protected

Definition at line 168 of file Rule.php.

◆ $_couponFactory

$_couponFactory
protected

Definition at line 148 of file Rule.php.

◆ $_coupons

$_coupons
protected

Definition at line 129 of file Rule.php.

◆ $_couponTypes

$_couponTypes
protected

Definition at line 136 of file Rule.php.

◆ $_eventObject

$_eventObject = 'rule'
protected

Definition at line 115 of file Rule.php.

◆ $_eventPrefix

$_eventPrefix = 'salesrule_rule'
protected

Definition at line 106 of file Rule.php.

◆ $_primaryCoupon

$_primaryCoupon
protected

Definition at line 122 of file Rule.php.

◆ $_storeManager

$_storeManager
protected

Definition at line 173 of file Rule.php.

◆ $_validatedAddresses

$_validatedAddresses = []
protected

Definition at line 143 of file Rule.php.

◆ BUY_X_GET_Y_ACTION

const BUY_X_GET_Y_ACTION = 'buy_x_get_y'

Definition at line 92 of file Rule.php.

◆ BY_FIXED_ACTION

const BY_FIXED_ACTION = 'by_fixed'

Definition at line 88 of file Rule.php.

◆ BY_PERCENT_ACTION

const BY_PERCENT_ACTION = 'by_percent'

Definition at line 84 of file Rule.php.

◆ CART_FIXED_ACTION

const CART_FIXED_ACTION = 'cart_fixed'

Definition at line 90 of file Rule.php.

◆ COUPON_TYPE_AUTO

const COUPON_TYPE_AUTO = 3

Definition at line 77 of file Rule.php.

◆ COUPON_TYPE_NO_COUPON

const COUPON_TYPE_NO_COUPON = 1

Coupon types

Definition at line 73 of file Rule.php.

◆ COUPON_TYPE_SPECIFIC

const COUPON_TYPE_SPECIFIC = 2

Definition at line 75 of file Rule.php.

◆ TO_FIXED_ACTION

const TO_FIXED_ACTION = 'to_fixed'

Definition at line 86 of file Rule.php.

◆ TO_PERCENT_ACTION

const TO_PERCENT_ACTION = 'to_percent'

Rule type actions

Definition at line 82 of file Rule.php.


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