Skip to content

Commit dbd6b15

Browse files
committed
ACP2E-1053: Generate coupon codes ignores Code Length
- Modified the implementation.
1 parent c882a97 commit dbd6b15

File tree

2 files changed

+7
-35
lines changed

2 files changed

+7
-35
lines changed

app/code/Magento/SalesRule/Model/Quote/ValidateCouponLengthWithQuantity.php

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,12 @@
99
namespace Magento\SalesRule\Model\Quote;
1010

1111
use Magento\SalesRule\Model\Coupon\Massgenerator;
12-
use Magento\SalesRule\Helper\Coupon;
1312

1413
/**
1514
* Validate the coupon code length and quantity.
1615
*/
17-
class ValidateCouponLengthWithQuantity implements ValidateCouponLengthWithQuantityInterface
16+
class ValidateCouponLengthWithQuantity extends Massgenerator implements ValidateCouponLengthWithQuantityInterface
1817
{
19-
/**
20-
* Initialize Sales rule coupon property
21-
*
22-
* @var Coupon
23-
*/
24-
protected Coupon $salesRuleCoupon;
25-
26-
/**
27-
* Generate constructor.
28-
*
29-
* @param Coupon $salesRuleCoupon
30-
*/
31-
public function __construct(
32-
Coupon $salesRuleCoupon
33-
) {
34-
$this->salesRuleCoupon = $salesRuleCoupon;
35-
}
36-
3718
/**
3819
* Validate coupon code length with quantity
3920
*
@@ -42,20 +23,8 @@ public function __construct(
4223
*/
4324
public function validateCouponCodeLengthWithQuantity(array $couponCodeDataArray): int
4425
{
45-
$maxProbability = Massgenerator::MAX_PROBABILITY_OF_GUESSING;
46-
$chars = count($this->salesRuleCoupon->getCharset($couponCodeDataArray['format']));
47-
$size = $couponCodeDataArray['qty'];
48-
$length = (int)$couponCodeDataArray['length'];
49-
$maxCodes = pow($chars, $length);
50-
$probability = $size / $maxCodes;
51-
52-
if ($probability > $maxProbability) {
53-
do {
54-
$length++;
55-
$maxCodes = pow($chars, $length);
56-
$probability = $size / $maxCodes;
57-
} while ($probability > $maxProbability);
58-
}
59-
return $length;
26+
$this->setData($couponCodeDataArray);
27+
$this->increaseLength();
28+
return $this->getLength();
6029
}
6130
}

app/code/Magento/SalesRule/Model/Quote/ValidateCouponLengthWithQuantityInterface.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
7+
declare(strict_types=1);
8+
69
namespace Magento\SalesRule\Model\Quote;
710

811
/**

0 commit comments

Comments
 (0)