Fix voucher code issue

This commit is contained in:
Abhishek Kumar
2024-01-15 12:52:37 +05:30
parent 97ba602fef
commit 83ec4b4306

View File

@@ -664,12 +664,9 @@ abstract class PaymentModuleCore extends Module
unset($voucher->id);
// Set a new voucher code
// For a customer, applying voucher ABCD will create partial vouchers ABCD-2, ABCD-3 and so on, and
// applying voucher ABCD-2 will create vouchers ABCD-2-2, ABCD-2-3 and so on
$voucher->code = empty($voucher->code) ? substr(md5($order->id.'-'.$order->id_customer.'-'.$cart_rule['obj']->id), 0, 16) : $voucher->code.'-2';
if (preg_match('/\-([0-9]{1,2})\-([0-9]{1,2})$/', $voucher->code, $matches) && $matches[1] == $matches[2]) {
$voucher->code = preg_replace('/'.$matches[0].'$/', '-'.(intval($matches[1]) + 1), $voucher->code);
}
// If ABCDEFGH-2 already exists for customer use ABCDEFGH-3
while (CartRule::cartRuleExists($voucher->code, $order->id_customer)) {
if (preg_match('/\-([0-9]{1,2})$/', $voucher->code, $matches)) {
$voucher->code = preg_replace('/'.$matches[1].'$/', (intval($matches[1]) + 1), $voucher->code);