Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
CouponGenerator Class Reference

Public Member Functions

 __construct (\Magento\SalesRule\Model\Service\CouponManagementService $couponManagementService, \Magento\SalesRule\Api\Data\CouponGenerationSpecInterfaceFactory $generationSpecFactory)
 
 generateCodes (array $parameters)
 

Detailed Description

Allows to generate a pool of coupon codes.

Generated coupon code - auto generated string, which is used on checkout in order to get discount (fixed or in percents) on whole customer shopping cart or on items in this shopping cart. Class was added due to Backward Compatibility and is used as proxy to:

See also
\Magento\SalesRule\Model\Service\CouponManagementService

Definition at line 16 of file CouponGenerator.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\SalesRule\Model\Service\CouponManagementService  $couponManagementService,
\Magento\SalesRule\Api\Data\CouponGenerationSpecInterfaceFactory  $generationSpecFactory 
)

All objects should be injected through constructor, because we need to have working service already after it initializing

Parameters
Service\CouponManagementService$couponManagementService
\Magento\SalesRule\Api\Data\CouponGenerationSpecInterfaceFactory$generationSpecFactory

Definition at line 49 of file CouponGenerator.php.

52  {
53  $this->couponManagementService = $couponManagementService;
54  $this->generationSpecFactory = $generationSpecFactory;
55  }

Member Function Documentation

◆ generateCodes()

generateCodes ( array  $parameters)

Generate a pool of generated coupon codes

This method is used as proxy, due to high coupling in constructor

See also
\Magento\SalesRule\Controller\Adminhtml\Promo\Quote\Generate In order to generate valid coupon codes, we need to initialize DTO object and run service.
\Magento\SalesRule\Api\Data\CouponGenerationSpecInterface -> DTO object
Parameters
array$parameters
Returns
string[]

Definition at line 68 of file CouponGenerator.php.

69  {
70  $couponSpecData = $this->convertCouponSpecData($parameters);
71  $couponSpec = $this->generationSpecFactory->create(['data' => $couponSpecData]);
72  return $this->couponManagementService->generate($couponSpec);
73  }

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