1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017 |
6
|
|
|
* @package MShop |
7
|
|
|
* @subpackage Coupon |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\MShop\Coupon\Provider\Decorator; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Decorator to allow using a coupon by a customer only once |
16
|
|
|
* |
17
|
|
|
* @package MShop |
18
|
|
|
* @subpackage Coupon |
19
|
|
|
*/ |
20
|
|
|
class Once |
21
|
|
|
extends \Aimeos\MShop\Coupon\Provider\Decorator\Base |
|
|
|
|
22
|
|
|
implements \Aimeos\MShop\Coupon\Provider\Decorator\Iface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Checks for requirements. |
26
|
|
|
* |
27
|
|
|
* @param \Aimeos\MShop\Order\Item\Base\Iface $base Basic order of the customer |
28
|
|
|
* @return boolean True if the requirements are met, false if not |
29
|
|
|
*/ |
30
|
|
|
public function isAvailable( \Aimeos\MShop\Order\Item\Base\Iface $base ) |
31
|
|
|
{ |
32
|
|
|
$addresses = $base->getAddresses(); |
33
|
|
|
|
34
|
|
|
if( isset( $addresses[\Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT] ) ) |
35
|
|
|
{ |
36
|
|
|
$address = $addresses[\Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT]; |
37
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'order' ); |
38
|
|
|
|
39
|
|
|
$search = $manager->createSearch(); |
40
|
|
|
$expr = [ |
41
|
|
|
$search->compare( '==', 'order.base.address.email', $address->getEmail() ), |
42
|
|
|
$search->compare( '==', 'order.base.coupon.code', $this->getCode() ), |
43
|
|
|
$search->compare( '>=', 'order.statuspayment', \Aimeos\MShop\Order\Item\Base::PAY_PENDING ), |
44
|
|
|
]; |
45
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
46
|
|
|
$search->setSlice( 0, 1 ); |
47
|
|
|
|
48
|
|
|
if( count( $manager->searchItems( $search ) ) > 0 ) { |
49
|
|
|
return false; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return parent::isAvailable( $base ); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|