Completed
Push — master ( ac3c49...e09568 )
by Aimeos
02:38
created

Base::addService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 3
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2016-2017
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
		$iface = '\Aimeos\Controller\Frontend\Basket\Iface';
36
		if( !( $controller instanceof $iface ) )
37
		{
38
			$msg = sprintf( 'Class "%1$s" does not implement interface "%2$s"', get_class( $controller ), $iface );
39
			throw new \Aimeos\Controller\Frontend\Exception( $msg );
40
		}
41
42
		$this->controller = $controller;
43
44
		parent::__construct( $context );
45
	}
46
47
48
	/**
49
	 * Passes unknown methods to wrapped objects.
50
	 *
51
	 * @param string $name Name of the method
52
	 * @param array $param List of method parameter
53
	 * @return mixed Returns the value of the called method
54
	 * @throws \Aimeos\Controller\Frontend\Exception If method call failed
55
	 */
56
	public function __call( $name, array $param )
57
	{
58
		return @call_user_func_array( array( $this->controller, $name ), $param );
59
	}
60
61
62
	/**
63
	 * Empties the basket and removing all products, addresses, services, etc.
64
	 * @return void
65
	 */
66
	public function clear()
67
	{
68
		$this->controller->clear();
69
		return $this;
70
	}
71
72
73
	/**
74
	 * Returns the basket object.
75
	 *
76
	 * @return \Aimeos\MShop\Order\Item\Base\Iface Basket holding products, addresses and delivery/payment options
77
	 */
78
	public function get()
79
	{
80
		return $this->controller->get();
81
	}
82
83
84
	/**
85
	 * Explicitely persists the basket content
86
	 */
87
	public function save()
88
	{
89
		$this->controller->save();
90
		return $this;
91
	}
92
93
94
	/**
95
	 * Sets the new basket type
96
	 *
97
	 * @param string $type Basket type
98
	 * @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object
99
	 */
100
	public function setType( $type )
101
	{
102
		$this->controller->setType( $type );
103
		return $this;
104
	}
105
106
107
	/**
108
	 * Creates a new order base object from the current basket
109
	 *
110
	 * @return \Aimeos\MShop\Order\Item\Base\Iface Order base object including products, addresses and services
111
	 */
112
	public function store()
113
	{
114
		return $this->controller->store();
115
	}
116
117
118
	/**
119
	 * Returns the order base object for the given ID
120
	 *
121
	 * @param string $id Unique ID of the order base object
122
	 * @param integer $parts Constants which parts of the order base object should be loaded
123
	 * @param boolean $default True to add default criteria (user logged in), false if not
124
	 * @return \Aimeos\MShop\Order\Item\Base\Iface Order base object including the given parts
125
	 */
126
	public function load( $id, $parts = \Aimeos\MShop\Order\Manager\Base\Base::PARTS_ALL, $default = true )
127
	{
128
		return $this->controller->load( $id, $parts, $default );
129
	}
130
131
132
	/**
133
	 * Adds a categorized product to the basket of the user stored in the session.
134
	 *
135
	 * @param string $prodid ID of the base product to add
136
	 * @param integer $quantity Amount of products that should by added
137
	 * @param array $options Possible options are: 'stock'=>true|false and 'variant'=>true|false
138
	 * 	The 'stock'=>false option allows adding products without being in stock.
139
	 * 	The 'variant'=>false option allows adding the selection product to the basket
140
	 * 	instead of the specific sub-product if the variant-building attribute IDs
141
	 * 	doesn't match a specific sub-product or if the attribute IDs are missing.
142
	 * @param array $variantAttributeIds List of variant-building attribute IDs that identify a specific product
143
	 * 	in a selection products
144
	 * @param array $configAttributeIds  List of attribute IDs that doesn't identify a specific product in a
145
	 * 	selection of products but are stored together with the product (e.g. for configurable products)
146
	 * @param array $hiddenAttributeIds List of attribute IDs that should be stored along with the product in the order
147
	 * @param array $customAttributeValues Associative list of attribute IDs and arbitrary values that should be stored
148
	 * 	along with the product in the order
149
	 * @param string $stocktype Unique code of the stock type to deliver the products from
150
	 * @throws \Aimeos\Controller\Frontend\Basket\Exception If the product isn't available
151
	 * @return void
152
	 */
153
	public function addProduct( $prodid, $quantity = 1, array $options = [], array $variantAttributeIds = [],
154
		array $configAttributeIds = [], array $hiddenAttributeIds = [], array $customAttributeValues = [],
155
		$stocktype = 'default' )
156
	{
157
		$this->controller->addProduct(
158
			$prodid, $quantity, $options, $variantAttributeIds, $configAttributeIds,
159
			$hiddenAttributeIds, $customAttributeValues, $stocktype
160
		);
161
	}
162
163
164
	/**
165
	 * Deletes a product item from the basket.
166
	 *
167
	 * @param integer $position Position number (key) of the order product item
168
	 * @return void
169
	 */
170
	public function deleteProduct( $position )
171
	{
172
		$this->controller->deleteProduct( $position );
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
	 * @param array $options Possible options are: 'stock'=>true|false
182
	 * @param array $configAttributeCodes Codes of the product config attributes that should be REMOVED
183
	 * @return void
184
	 */
185
	public function editProduct( $position, $quantity, array $options = [], array $configAttributeCodes = [] )
186
	{
187
		$this->controller->editProduct( $position, $quantity, $options, $configAttributeCodes );
188
	}
189
190
191
	/**
192
	 * Adds the given coupon code and updates the basket.
193
	 *
194
	 * @param string $code Coupon code entered by the user
195
	 * @throws \Aimeos\Controller\Frontend\Basket\Exception if the coupon code is invalid or not allowed
196
	 * @return void
197
	 */
198
	public function addCoupon( $code )
199
	{
200
		$this->controller->addCoupon( $code );
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
	 * @throws \Aimeos\Controller\Frontend\Basket\Exception if the coupon code is invalid
209
	 * @return void
210
	 */
211
	public function deleteCoupon( $code )
212
	{
213
		$this->controller->deleteCoupon( $code );
214
	}
215
216
217
	/**
218
	 * Adds the delivery/payment service item based on the service ID.
219
	 *
220
	 * @param string $type Address type constant from \Aimeos\MShop\Order\Item\Base\Address\Base
221
	 * @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
222
	 * @throws \Aimeos\Controller\Frontend\Basket\Exception If the billing or delivery address is not of any required type of
223
	 * 	if one of the keys is invalid when using an array with key/value pairs
224
	 * @return void
225
	 */
226
	public function setAddress( $type, $value )
227
	{
228
		$this->controller->setAddress( $type, $value );
229
	}
230
231
232
	/**
233
	 * Sets the delivery/payment service item based on the service ID.
234
	 *
235
	 * @param string $type Service type code like 'payment' or 'delivery'
236
	 * @param string $id Unique ID of the service item
237
	 * @param array $attributes Associative list of key/value pairs containing the attributes selected or
238
	 * 	entered by the customer when choosing one of the delivery or payment options
239
	 * @throws \Aimeos\Controller\Frontend\Basket\Exception If there is no price to the service item attached
240
	 * @return void
241
	 */
242
	public function addService( $type, $id, array $attributes = [] )
243
	{
244
		$this->controller->addService( $type, $id, $attributes );
245
	}
246
247
248
	/**
249
	 * Removes the delivery or payment service items from the basket
250
	 *
251
	 * @param string $type Service type code like 'payment' or 'delivery'
252
	 */
253
	public function deleteService( $type )
254
	{
255
		$this->controller->deleteService( $type );
256
	}
257
258
259
	/**
260
	 * Returns the frontend controller
261
	 *
262
	 * @return \Aimeos\Controller\Frontend\Basket\Iface Frontend controller object
263
	 */
264
	protected function getController()
265
	{
266
		return $this->controller;
267
	}
268
}
269