Passed
Push — master ( 3311dc...3c99d6 )
by Aimeos
05:26
created

MShop/Coupon/Provider/Decorator/BasketValues.php (2 issues)

1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2012
6
 * @copyright Aimeos (aimeos.org), 2015-2018
7
 * @package MShop
8
 * @subpackage Coupon
9
 */
10
11
12
namespace Aimeos\MShop\Coupon\Provider\Decorator;
13
14
15
/**
16
 * BasketValues decorator for coupon provider.
17
 *
18
 * @package MShop
19
 * @subpackage Coupon
20
 */
21
class BasketValues
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 )
0 ignored issues
show
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
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()
0 ignored issues
show
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
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 boolean True if the basket matches the constraints, false if not
77
	 */
78
	public function isAvailable( \Aimeos\MShop\Order\Item\Base\Iface $base )
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