200 \
Magento\Framework\Data\FormFactory $formFactory,
201 \
Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
202 \
Magento\SalesRule\Model\CouponFactory $couponFactory,
203 \
Magento\SalesRule\Model\
Coupon\CodegeneratorFactory $codegenFactory,
215 $this->_couponFactory = $couponFactory;
216 $this->_codegenFactory = $codegenFactory;
217 $this->_condCombineFactory = $condCombineFactory;
218 $this->_condProdCombineF = $condProdCombineF;
219 $this->_couponCollection = $couponCollection;
242 parent::_construct();
255 return parent::_afterLoad();
276 if ($this->getUsesPerCoupon() ==
null && !$this->getUseAutoGeneration()) {
291 ) && $this->getCouponType() == self::COUPON_TYPE_SPECIFIC && !$this->getUseAutoGeneration()
296 $this->getUsesPerCoupon() ? $this->getUsesPerCoupon() :
null 297 )->setUsagePerCustomer(
298 $this->getUsesPerCustomer() ? $this->getUsesPerCustomer() :
null 299 )->setExpirationDate(
318 parent::loadPost(
$data);
320 if (isset(
$data[
'store_labels'])) {
321 $this->setStoreLabels(
$data[
'store_labels']);
334 return $this->_condCombineFactory->create();
344 return $this->_condProdCombineF->create();
354 if (!$this->_couponCodeGenerator) {
355 return $this->_codegenFactory->create([
'data' => [
'length' => 16]]);
368 $this->_couponCodeGenerator = $codeGenerator;
378 if ($this->_primaryCoupon ===
null) {
379 $this->_primaryCoupon = $this->_couponFactory->create();
380 $this->_primaryCoupon->loadPrimaryByRule($this->
getId());
381 $this->_primaryCoupon->setRule($this)->setIsPrimary(
true);
393 if (!$this->hasCustomerGroupIds()) {
395 $this->
setData(
'customer_group_ids', (array)$customerGroupIds);
397 return $this->
_getData(
'customer_group_ids');
413 }
elseif (isset($labels[0]) && $labels[0]) {
427 if (!$this->hasStoreLabels()) {
429 $this->setStoreLabels($labels);
432 return $this->
_getData(
'store_labels');
442 if ($this->_coupons ===
null) {
443 $this->_couponCollection->addRuleToFilter($this);
444 $this->_coupons = $this->_couponCollection->getItems();
456 if ($this->_couponTypes ===
null) {
457 $this->_couponTypes = [
461 $transport = new \Magento\Framework\DataObject(
462 [
'coupon_types' => $this->_couponTypes,
'is_coupon_type_auto_visible' =>
false]
464 $this->_eventManager->dispatch(
'salesrule_rule_get_coupon_types', [
'transport' => $transport]);
465 $this->_couponTypes = $transport->getCouponTypes();
466 if ($transport->getIsCouponTypeAutoVisible()) {
483 public function acquireCoupon($saveNewlyCreated =
true, $saveAttemptCount = 10)
485 if ($this->getCouponType() == self::COUPON_TYPE_NO_COUPON) {
488 if ($this->getCouponType() == self::COUPON_TYPE_SPECIFIC) {
492 $coupon = $this->_couponFactory->create();
498 $this->getUsesPerCoupon() ? $this->getUsesPerCoupon() :
null 499 )->setUsagePerCustomer(
500 $this->getUsesPerCustomer() ? $this->getUsesPerCustomer() :
null 501 )->setExpirationDate(
504 \
Magento\SalesRule\Api\Data\CouponInterface::TYPE_GENERATED
511 if (!$saveNewlyCreated) {
514 if ($this->
getId()) {
515 for ($attemptNum = 0; $attemptNum < $saveAttemptCount; $attemptNum++) {
518 }
catch (\Exception $e) {
519 if ($e instanceof \
Magento\Framework\Exception\LocalizedException ||
$coupon->getId()) {
523 $couponCode . self::getCouponCodeGenerator()->getDelimiter() . sprintf(
536 throw new \Magento\Framework\Exception\LocalizedException(
__(
'Can\'t acquire coupon.'));
550 return $this->
getData(
'from_date');
561 return $this->
getData(
'to_date');
572 $addressId = $this->_getAddressId(
$address);
573 return isset($this->_validatedAddresses[$addressId]) ? true :
false;
585 $addressId = $this->_getAddressId(
$address);
586 $this->_validatedAddresses[$addressId] = $validationResult;
599 $addressId = $this->_getAddressId(
$address);
600 return isset($this->_validatedAddresses[$addressId]) ? $this->_validatedAddresses[$addressId] :
false;
609 private function _getAddressId(
$address)
setIsValidForAddress($address, $validationResult)
elseif(isset( $params[ 'redirect_parent']))
getStoreLabel($store=null)
const COUPON_TYPE_NO_COUPON
getActionsFieldSetId($formName='')
getConditionsFieldSetId($formName='')
const COUPON_TYPE_SPECIFIC
getIsValidForAddress($address)
getData($key='', $index=null)
setCouponCodeGenerator(\Magento\SalesRule\Model\Coupon\CodegeneratorInterface $codeGenerator)
setData($key, $value=null)
hasIsValidForAddress($address)
__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)