Passed
Push — master ( b5a62a...377249 )
by Aimeos
02:14
created

Base::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2016-2018
6
 * @package Controller
7
 * @subpackage Frontend
8
 */
9
10
11
namespace Aimeos\Controller\Frontend\Basket\Decorator;
12
13
14
/**
15
 * Base for basket frontend controller decorators
16
 *
17
 * @package Controller
18
 * @subpackage Frontend
19
 */
20
abstract class Base
21
	extends \Aimeos\Controller\Frontend\Basket\Base
22
	implements \Aimeos\Controller\Frontend\Common\Decorator\Iface, \Aimeos\Controller\Frontend\Basket\Iface
23
{
24
	private $controller;
25
26
27
	/**
28
	 * Initializes the controller decorator.
29
	 *
30
	 * @param \Aimeos\Controller\Frontend\Iface $controller Controller object
31
	 * @param \Aimeos\MShop\Context\Item\Iface $context Context object with required objects
32
	 */
33
	public function __construct( \Aimeos\Controller\Frontend\Iface $controller, \Aimeos\MShop\Context\Item\Iface $context )
34
	{
35
		parent::__construct( $context );
36
37
		$iface = \Aimeos\Controller\Frontend\Basket\Iface::class;
38
		$this->controller = \Aimeos\MW\Common\Base::checkClass( $iface, $controller );
39
	}
40
41
42
	/**
43
	 * Passes unknown methods to wrapped objects.
44
	 *
45
	 * @param string $name Name of the method
46
	 * @param array $param List of method parameter
47
	 * @return mixed Returns the value of the called method
48
	 * @throws \Aimeos\Controller\Frontend\Exception If method call failed
49
	 */
50
	public function __call( $name, array $param )
51
	{
52
		return @call_user_func_array( array( $this->controller, $name ), $param );
53
	}
54
55
56
	/**
57
	 * Adds values like comments to the basket
58
	 *
59
	 * @param array $values Order base values like comment
60
	 * @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface
61
	 */
62
	public function add( array $values )
63
	{
64
		$this->controller->add( $values );
65
		return $this;
66
	}
67
68
69
	/**
70
	 * Empties the basket and removing all products, addresses, services, etc.
71
	 *
72
	 * @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface
73
	 */
74
	public function clear()
75
	{
76
		$this->controller->clear();
77
		return $this;
78
	}
79
80
81
	/**
82
	 * Returns the basket object.
83
	 *
84
	 * @return \Aimeos\MShop\Order\Item\Base\Iface Basket holding products, addresses and delivery/payment options
85
	 */
86
	public function get()
87
	{
88
		return $this->controller->get();
89
	}
90
91
92
	/**
93
	 * Explicitely persists the basket content
94
	 *
95
	 * @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface
96
	 */
97
	public function save()
98
	{
99
		$this->controller->save();
100
		return $this;
101
	}
102
103
104
	/**
105
	 * Sets the new basket type
106
	 *
107
	 * @param string $type Basket type
108
	 * @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface
109
	 */
110
	public function setType( $type )
111
	{
112
		$this->controller->setType( $type );
113
		return $this;
114
	}
115
116
117
	/**
118
	 * Creates a new order base object from the current basket
119
	 *
120
	 * @return \Aimeos\MShop\Order\Item\Base\Iface Order base object including products, addresses and services
121
	 */
122
	public function store()
123
	{
124
		return $this->controller->store();
125
	}
126
127
128
	/**
129
	 * Returns the order base object for the given ID
130
	 *
131
	 * @param string $id Unique ID of the order base object
132
	 * @param integer $parts Constants which parts of the order base object should be loaded
133
	 * @param boolean $default True to add default criteria (user logged in), false if not
134
	 * @return \Aimeos\MShop\Order\Item\Base\Iface Order base object including the given parts
135
	 */
136
	public function load( $id, $parts = \Aimeos\MShop\Order\Item\Base\Base::PARTS_ALL, $default = true )
137
	{
138
		return $this->controller->load( $id, $parts, $default );
139
	}
140
141
142
	/**
143
	 * Adds a product to the basket of the customer stored in the session
144
	 *
145
	 * @param \Aimeos\MShop\Product\Item\Iface $product Product to add including texts, media, prices, attributes, etc.
146
	 * @param integer $quantity Amount of products that should by added
147
	 * @param array $variant List of variant-building attribute IDs that identify an article in a selection product
148
	 * @param array $config List of configurable attribute IDs the customer has chosen from
149
	 * @param array $custom Associative list of attribute IDs as keys and arbitrary values that will be added to the ordered product
150
	 * @param string $stocktype Unique code of the stock type to deliver the products from
151
	 * @param string|null $supplier Unique supplier code the product is from
152
	 * @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface
153
	 * @throws \Aimeos\Controller\Frontend\Basket\Exception If the product isn't available
154
	 */
155
	public function addProduct( \Aimeos\MShop\Product\Item\Iface $product, $quantity = 1,
156
		array $variant = [], array $config = [], array $custom = [], $stocktype = 'default', $supplier = null )
157
	{
158
		$this->controller->addProduct( $product, $quantity, $variant, $config, $custom, $stocktype, $supplier );
159
		return $this;
160
	}
161
162
163
	/**
164
	 * Deletes a product item from the basket.
165
	 *
166
	 * @param integer $position Position number (key) of the order product item
167
	 * @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface
168
	 */
169
	public function deleteProduct( $position )
170
	{
171
		$this->controller->deleteProduct( $position );
172
		return $this;
173
	}
174
175
176
	/**
177
	 * Edits the quantity of a product item in the basket.
178
	 *
179
	 * @param integer $position Position number (key) of the order product item
180
	 * @param integer $quantity New quantiy of the product item
181
	 * @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface
182
	 */
183
	public function updateProduct( $position, $quantity )
184
	{
185
		$this->controller->updateProduct( $position, $quantity );
186
		return $this;
187
	}
188
189
190
	/**
191
	 * Adds the given coupon code and updates the basket.
192
	 *
193
	 * @param string $code Coupon code entered by the user
194
	 * @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface
195
	 * @throws \Aimeos\Controller\Frontend\Basket\Exception if the coupon code is invalid or not allowed
196
	 */
197
	public function addCoupon( $code )
198
	{
199
		$this->controller->addCoupon( $code );
200
		return $this;
201
	}
202
203
204
	/**
205
	 * Removes the given coupon code and its effects from the basket.
206
	 *
207
	 * @param string $code Coupon code entered by the user
208
	 * @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface
209
	 * @throws \Aimeos\Controller\Frontend\Basket\Exception if the coupon code is invalid
210
	 */
211
	public function deleteCoupon( $code )
212
	{
213
		$this->controller->deleteCoupon( $code );
214
		return $this;
215
	}
216
217
218
	/**
219
	 * Adds the delivery/payment service item based on the service ID.
220
	 *
221
	 * @param string $type Address type constant from \Aimeos\MShop\Order\Item\Base\Address\Base
222
	 * @param \Aimeos\MShop\Common\Item\Address\Iface|array|null $value Address object or array with key/value pairs of address or null to remove address from basket
223
	 * @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface
224
	 * @throws \Aimeos\Controller\Frontend\Basket\Exception If the billing or delivery address is not of any required type of
225
	 * 	if one of the keys is invalid when using an array with key/value pairs
226
	 */
227
	public function setAddress( $type, $value )
228
	{
229
		$this->controller->setAddress( $type, $value );
230
		return $this;
231
	}
232
233
234
	/**
235
	 * Sets the delivery/payment service item based on the service ID.
236
	 *
237
	 * @param string $type Service type code like 'payment' or 'delivery'
238
	 * @param string $id Unique ID of the service item
239
	 * @param array $attributes Associative list of key/value pairs containing the attributes selected or
240
	 * 	entered by the customer when choosing one of the delivery or payment options
241
	 * @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface
242
	 * @throws \Aimeos\Controller\Frontend\Basket\Exception If there is no price to the service item attached
243
	 */
244
	public function addService( $type, $id, array $attributes = [] )
245
	{
246
		$this->controller->addService( $type, $id, $attributes );
247
		return $this;
248
	}
249
250
251
	/**
252
	 * Removes the delivery or payment service items from the basket
253
	 *
254
	 * @param string $type Service type code like 'payment' or 'delivery'
255
	 * @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface
256
	 */
257
	public function deleteService( $type )
258
	{
259
		$this->controller->deleteService( $type );
260
		return $this;
261
	}
262
263
264
	/**
265
	 * Returns the frontend controller
266
	 *
267
	 * @return \Aimeos\Controller\Frontend\Basket\Iface Frontend controller object
268
	 */
269
	protected function getController()
270
	{
271
		return $this->controller;
272
	}
273
}
274