Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions source/Application/Model/Voucher.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public function getVoucherByNr($sVoucherNr, $aVouchers = [], $blCheckavalability
$sQ .= "( {$sViewName}.oxorderid is NULL || {$sViewName}.oxorderid = '' ) ";
$sQ .= " and ( {$sViewName}.oxdateused is NULL || {$sViewName}.oxdateused = 0 ) ";

// Validate end date of voucher (To prevent issue in case same voucher number been used for multiple voucherseries)
$sQ .= " and ({$sSeriesViewName}.oxenddate >= NOW() OR {$sSeriesViewName}.oxenddate = '0000-00-00 00:00:00')";

//voucher timeout for 3 hours
if ($blCheckavalability) {
$iTime = time() - $this->getVoucherTimeout();
Expand Down
53 changes: 53 additions & 0 deletions tests/Integration/Application/Model/Vouchers/VoucherTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/

declare(strict_types=1);

namespace OxidEsales\EshopCommunity\Tests\Integration\Application\Model\Vouchers;

use OxidEsales\EshopCommunity\Tests\Integration\IntegrationTestCase;

class VoucherTest extends IntegrationTestCase
{
public function testSameReusedVoucherNumberOfEndedSerieCanBeCorrectlySelected(): void
{
$serie1 = oxNew('oxvoucherserie');
$serie1->assign([
'oxserienr' => 'Reused finished serie',
'oxenddate' => date('Y-m-d H:i:s', time() - 3600 * 3)
]);
$serie1->save();

$serie2 = oxNew('oxvoucherserie');
$serie2->assign([
'oxserienr' => 'Reused active serie',
'oxenddate' => date('Y-m-d H:i:s', time() + 3600 * 3)
]);
$serie2->save();

$reusedVoucherNumber = uniqid();

$voucher1 = oxNew("oxvoucher");
$voucher1->assign([
'OXVOUCHERNR' => $reusedVoucherNumber,
'OXVOUCHERSERIEID' => $serie1->getId()
]);
$voucher1->save();

$voucher2 = oxNew("oxvoucher");
$voucher2->assign([
'OXVOUCHERNR' => $reusedVoucherNumber,
'OXVOUCHERSERIEID' => $serie2->getId()
]);
$voucher2->save();

$voucherTry = oxNew("oxvoucher");
$voucherTry->getVoucherByNr($reusedVoucherNumber);

$this->assertSame($serie2->getId(), $voucherTry->getFieldData('OXVOUCHERSERIEID'));
}
}