Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Coupon.php
Go to the documentation of this file.
1 <?php
8 
16 {
20  const COUPON_FORMAT_ALPHANUMERIC = 'alphanum';
21 
22  const COUPON_FORMAT_ALPHABETICAL = 'alpha';
23 
24  const COUPON_FORMAT_NUMERIC = 'num';
25 
30 
34  const XML_PATH_SALES_RULE_COUPON_LENGTH = 'promo/auto_generated_coupon_codes/length';
35 
36  const XML_PATH_SALES_RULE_COUPON_FORMAT = 'promo/auto_generated_coupon_codes/format';
37 
38  const XML_PATH_SALES_RULE_COUPON_PREFIX = 'promo/auto_generated_coupon_codes/prefix';
39 
40  const XML_PATH_SALES_RULE_COUPON_SUFFIX = 'promo/auto_generated_coupon_codes/suffix';
41 
42  const XML_PATH_SALES_RULE_COUPON_DASH_INTERVAL = 'promo/auto_generated_coupon_codes/dash';
43 
47  protected $_couponParameters;
48 
53  public function __construct(
54  \Magento\Framework\App\Helper\Context $context,
55  array $couponParameters
56  ) {
57  $this->_couponParameters = $couponParameters;
58  parent::__construct($context);
59  }
60 
66  public function getFormatsList()
67  {
68  return [
69  self::COUPON_FORMAT_ALPHANUMERIC => __('Alphanumeric'),
70  self::COUPON_FORMAT_ALPHABETICAL => __('Alphabetical'),
71  self::COUPON_FORMAT_NUMERIC => __('Numeric')
72  ];
73  }
74 
80  public function getDefaultLength()
81  {
82  return (int)$this->scopeConfig->getValue(
83  self::XML_PATH_SALES_RULE_COUPON_LENGTH,
84  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
85  );
86  }
87 
93  public function getDefaultFormat()
94  {
95  return $this->scopeConfig->getValue(
96  self::XML_PATH_SALES_RULE_COUPON_FORMAT,
97  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
98  );
99  }
100 
106  public function getDefaultPrefix()
107  {
108  return $this->scopeConfig->getValue(
109  self::XML_PATH_SALES_RULE_COUPON_PREFIX,
110  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
111  );
112  }
113 
119  public function getDefaultSuffix()
120  {
121  return $this->scopeConfig->getValue(
122  self::XML_PATH_SALES_RULE_COUPON_SUFFIX,
123  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
124  );
125  }
126 
132  public function getDefaultDashInterval()
133  {
134  return (int)$this->scopeConfig->getValue(
135  self::XML_PATH_SALES_RULE_COUPON_DASH_INTERVAL,
136  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
137  );
138  }
139 
146  public function getCharset($format)
147  {
148  return str_split($this->_couponParameters['charset'][$format]);
149  }
150 
156  public function getCodeSeparator()
157  {
158  return $this->_couponParameters['separator'];
159  }
160 }
__()
Definition: __.php:13
$format
Definition: list.phtml:12
const XML_PATH_SALES_RULE_COUPON_DASH_INTERVAL
Definition: Coupon.php:42
__construct(\Magento\Framework\App\Helper\Context $context, array $couponParameters)
Definition: Coupon.php:53