Skip to content

Commit a72498d

Browse files
faraz-glsreenia806
authored andcommitted
AC-8753: Coupon quantity generation checks
* Validation and renaming of variables and text
1 parent 741b8f2 commit a72498d

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/Generate.php

100644100755
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ class Generate extends Quote implements HttpPostActionInterface
6161
private ScopeConfigInterface $scopeConfig;
6262

6363
/**
64-
* Handle coupon quantity system name
64+
* Coupon quantity limit config path
6565
*/
66-
private const XML_COUPON_QUANTITY = 'promo/auto_generated_coupon_codes/quantity';
66+
private const XML_CONFIG_COUPON_QUANTITY_LIMIT = 'promo/auto_generated_coupon_codes/quantity_limit';
6767

6868
/**
6969
* Generate constructor.
@@ -163,13 +163,14 @@ public function execute(): void
163163

164164
$data['quantity'] = $data['qty'] ?? null;
165165
$couponQuantity = (int)$this->scopeConfig->getValue(
166-
self::XML_COUPON_QUANTITY,
166+
self::XML_CONFIG_COUPON_QUANTITY_LIMIT,
167167
ScopeInterface::SCOPE_STORE
168168
);
169-
if ($data['quantity'] && $couponQuantity && $data['quantity'] > $couponQuantity) {
169+
// @codingStandardsIgnoreStart
170+
if ($data['quantity'] && $data['quantity'] > 0 && $couponQuantity && $data['quantity'] > $couponQuantity) {
170171
$this->messageManager->addErrorMessage(
171172
__(
172-
'Coupon qty should be less than or equal to the coupon qty in the store configuration.'
173+
'Coupon quantity should be less than or equal to the coupon quantity in the store configuration.'
173174
)
174175
);
175176
} else {

app/code/Magento/SalesRule/Test/Unit/Controller/Adminhtml/Promo/Quote/GenerateTest.php

100644100755
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@
3838
*/
3939
class GenerateTest extends TestCase
4040
{
41-
/** @const XML_COUPON_QUANTITY_TEST */
42-
private const XML_COUPON_QUANTITY_TEST = 'promo/auto_generated_coupon_codes/quantity';
41+
/** @const XML_COUPON_QUANTITY_LIMIT_PATH_TEST */
42+
private const XML_COUPON_QUANTITY_LIMIT_PATH_TEST = 'promo/auto_generated_coupon_codes/quantity_limit';
4343

44-
/** @const XML_COUPON_QUANTITY_TEST_VALUE */
45-
private const XML_COUPON_QUANTITY_TEST_VALUE = 250000;
44+
/** @const XML_COUPON_QUANTITY_LIMIT_VALUE_TEST */
45+
private const XML_COUPON_QUANTITY_LIMIT_VALUE_TEST = 250000;
4646

4747
/**
4848
* @var array
@@ -410,8 +410,8 @@ public function testExecuteWithInvalidCouponQuantity()
410410
$this->scopeConfigMock
411411
->expects($this->once())
412412
->method('getValue')
413-
->with(self::XML_COUPON_QUANTITY_TEST)
414-
->willReturn(self::XML_COUPON_QUANTITY_TEST_VALUE);
413+
->with(self::XML_COUPON_QUANTITY_LIMIT_PATH_TEST)
414+
->willReturn(self::XML_COUPON_QUANTITY_LIMIT_VALUE_TEST);
415415
$this->getCouponCodeLength->expects($this->once())
416416
->method('fetchCouponCodeLength')
417417
->willReturn(10);

app/code/Magento/SalesRule/etc/adminhtml/system.xml

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
<comment>Excluding prefix, suffix and separators.</comment>
2020
<frontend_class>validate-digits</frontend_class>
2121
</field>
22-
<field id="quantity" translate="label comment" type="text" sortOrder="20" showInDefault="1" canRestore="1">
23-
<label>Code Quantity</label>
22+
<field id="quantity_limit" translate="label comment" type="text" sortOrder="20" showInDefault="1" canRestore="1">
23+
<label>Code Quantity Limit</label>
2424
<comment>For better performance max value allowed is 250,000.</comment>
2525
<frontend_class>required-entry validate-number-range number-range-1-250000</frontend_class>
2626
</field>

app/code/Magento/SalesRule/i18n/en_US.csv

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,4 @@ Apply,Apply
169169
"Sorry, something went wrong while triggering recollect totals for affected quotes. Please see log for details.","Sorry, something went wrong while triggering recollect totals for affected quotes. Please see log for details."
170170
"When coupon quantity exceeds %1, the coupon code length must be minimum %2", "When coupon quantity exceeds %1, the coupon code length must be minimum %2"
171171
"Discount amount is distributed among subtotal and shipping amount. Cases when multiple discounts applied to shipping amount are not supported. The option is going to be removed in future releases.ly","Discount amount is distributed among subtotal and shipping amount. Cases when multiple discounts applied to shipping amount are not supported. The option is going to be removed in future releases."
172-
"Coupon qty should be less than or equal to the coupon qty in the store configuration.","Coupon qty should be less than or equal to the coupon qty in the store configuration."
172+
"Coupon quantity should be less than or equal to the coupon quantity in the store configuration.","Coupon quantity should be less than or equal to the coupon quantity in the store configuration."

0 commit comments

Comments
 (0)