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 for restricting coupons to suppliers |
16
|
|
|
* |
17
|
|
|
* @package MShop |
18
|
|
|
* @subpackage Coupon |
19
|
|
|
*/ |
20
|
|
|
class Supplier |
21
|
|
|
extends \Aimeos\MShop\Coupon\Provider\Decorator\Base |
|
|
|
|
22
|
|
|
implements \Aimeos\MShop\Coupon\Provider\Decorator\Iface |
23
|
|
|
{ |
24
|
|
|
private $beConfig = array( |
25
|
|
|
'supplier.code' => array( |
26
|
|
|
'code' => 'supplier.code', |
27
|
|
|
'internalcode' => 'supplier.code', |
28
|
|
|
'label' => 'Required code of the supplier', |
29
|
|
|
'type' => 'string', |
30
|
|
|
'internaltype' => 'string', |
31
|
|
|
'default' => '', |
32
|
|
|
'required' => true, |
33
|
|
|
), |
34
|
|
|
); |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Checks the backend configuration attributes for validity. |
39
|
|
|
* |
40
|
|
|
* @param array $attributes Attributes added by the shop owner in the administraton interface |
41
|
|
|
* @return array An array with the attribute keys as key and an error message as values for all attributes that are |
42
|
|
|
* known by the provider but aren't valid |
43
|
|
|
*/ |
44
|
|
|
public function checkConfigBE( array $attributes ) |
45
|
|
|
{ |
46
|
|
|
return $this->checkConfig( $this->beConfig, $attributes ); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Returns the configuration attribute definitions of the provider to generate a list of available fields and |
52
|
|
|
* rules for the value of each field in the administration interface. |
53
|
|
|
* |
54
|
|
|
* @return array List of attribute definitions implementing \Aimeos\MW\Common\Critera\Attribute\Iface |
55
|
|
|
*/ |
56
|
|
|
public function getConfigBE() |
57
|
|
|
{ |
58
|
|
|
return $this->getConfigItems( $this->beConfig ); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Checks for requirements. |
64
|
|
|
* |
65
|
|
|
* @param \Aimeos\MShop\Order\Item\Base\Iface $base Basic order of the customer |
66
|
|
|
* @return boolean True if the requirements are met, false if not |
67
|
|
|
*/ |
68
|
|
|
public function isAvailable( \Aimeos\MShop\Order\Item\Base\Iface $base ) |
69
|
|
|
{ |
70
|
|
|
$services = $base->getServices(); |
71
|
|
|
|
72
|
|
|
if( isset( $services[\Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_DELIVERY] ) ) |
73
|
|
|
{ |
74
|
|
|
$service = $services[\Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_DELIVERY]; |
75
|
|
|
|
76
|
|
|
if( $service->getAttribute( 'supplier.code', 'delivery' ) === $this->getConfigValue( 'supplier.code' ) ) { |
77
|
|
|
return parent::isAvailable( $base ); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return false; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|