1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2012 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2021 |
7
|
|
|
* @package MShop |
8
|
|
|
* @subpackage Coupon |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
namespace Aimeos\MShop\Coupon\Provider\Decorator; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Basket decorator for coupon provider. |
17
|
|
|
* |
18
|
|
|
* @package MShop |
19
|
|
|
* @subpackage Coupon |
20
|
|
|
*/ |
21
|
|
|
class Basket |
22
|
|
|
extends \Aimeos\MShop\Coupon\Provider\Decorator\Base |
23
|
|
|
implements \Aimeos\MShop\Coupon\Provider\Decorator\Iface |
24
|
|
|
{ |
25
|
|
|
private $beConfig = array( |
26
|
|
|
'basketvalues.total-value-min' => array( |
27
|
|
|
'code' => 'basketvalues.total-value-min', |
28
|
|
|
'internalcode' => 'basketvalues.total-value-min', |
29
|
|
|
'label' => 'Minimum total value of the basket', |
30
|
|
|
'type' => 'map', |
31
|
|
|
'internaltype' => 'array', |
32
|
|
|
'default' => [], |
33
|
|
|
'required' => false, |
34
|
|
|
), |
35
|
|
|
'basketvalues.total-value-max' => array( |
36
|
|
|
'code' => 'basketvalues.total-value-max', |
37
|
|
|
'internalcode' => 'basketvalues.total-value-max', |
38
|
|
|
'label' => 'Maximum total value of the basket', |
39
|
|
|
'type' => 'map', |
40
|
|
|
'internaltype' => 'array', |
41
|
|
|
'default' => [], |
42
|
|
|
'required' => false, |
43
|
|
|
), |
44
|
|
|
); |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Checks the backend configuration attributes for validity. |
49
|
|
|
* |
50
|
|
|
* @param array $attributes Attributes added by the shop owner in the administraton interface |
51
|
|
|
* @return array An array with the attribute keys as key and an error message as values for all attributes that are |
52
|
|
|
* known by the provider but aren't valid |
53
|
|
|
*/ |
54
|
|
|
public function checkConfigBE( array $attributes ) : array |
55
|
|
|
{ |
56
|
|
|
return $this->checkConfig( $this->beConfig, $attributes ); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Returns the configuration attribute definitions of the provider to generate a list of available fields and |
62
|
|
|
* rules for the value of each field in the administration interface. |
63
|
|
|
* |
64
|
|
|
* @return array List of attribute definitions implementing \Aimeos\MW\Common\Critera\Attribute\Iface |
65
|
|
|
*/ |
66
|
|
|
public function getConfigBE() : array |
67
|
|
|
{ |
68
|
|
|
return $this->getConfigItems( $this->beConfig ); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Checks for the min/max order value. |
74
|
|
|
* |
75
|
|
|
* @param \Aimeos\MShop\Order\Item\Base\Iface $base Basic order of the customer |
76
|
|
|
* @return bool True if the basket matches the constraints, false if not |
77
|
|
|
*/ |
78
|
|
|
public function isAvailable( \Aimeos\MShop\Order\Item\Base\Iface $base ) : bool |
79
|
|
|
{ |
80
|
|
|
$price = $base->getPrice(); |
81
|
|
|
$currency = $price->getCurrencyId(); |
82
|
|
|
$value = $price->getValue() + $price->getRebate(); |
83
|
|
|
|
84
|
|
|
$minvalue = $this->getConfigValue( 'basketvalues.total-value-min', [] ); |
85
|
|
|
|
86
|
|
|
if( isset( $minvalue[$currency] ) && $minvalue[$currency] > $value ) { |
87
|
|
|
return false; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$maxvalue = $this->getConfigValue( 'basketvalues.total-value-max', [] ); |
91
|
|
|
|
92
|
|
|
if( isset( $maxvalue[$currency] ) && $maxvalue[$currency] < $value ) { |
93
|
|
|
return false; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return parent::isAvailable( $base ); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|