Completed
Push — master ( 71898e...52c730 )
by Aimeos
09:01
created

Supplier::getConfigBE()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
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
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces between "Base" and comma; 1 found
Loading history...
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