Issues (44)

src/Controller/Frontend/Basket/Decorator/Base.php (1 issue)

Labels
Severity
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2016-2024
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
	use \Aimeos\Controller\Frontend\Common\Decorator\Traits;
25
26
27
	private \Aimeos\Controller\Frontend\Basket\Iface $controller;
28
29
30
	/**
31
	 * Initializes the controller decorator.
32
	 *
33
	 * @param \Aimeos\Controller\Frontend\Iface $controller Controller object
34
	 * @param \Aimeos\MShop\ContextIface $context Context object with required objects
35
	 */
36
	public function __construct( \Aimeos\Controller\Frontend\Iface $controller, \Aimeos\MShop\ContextIface $context )
37
	{
38
		parent::__construct( $context );
39
40
		$this->controller = $controller;
41
	}
42
43
44
	/**
45
	 * Passes unknown methods to wrapped objects.
46
	 *
47
	 * @param string $name Name of the method
48
	 * @param array $param List of method parameter
49
	 * @return mixed Returns the value of the called method
50
	 * @throws \Aimeos\Controller\Frontend\Exception If method call failed
51
	 */
52
	public function __call( string $name, array $param )
53
	{
54
		return @call_user_func_array( array( $this->controller, $name ), $param );
55
	}
56
57
58
	/**
59
	 * Adds values like comments to the basket
60
	 *
61
	 * @param array $values Order values like comment
62
	 * @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface
63
	 */
64
	public function add( array $values ) : \Aimeos\Controller\Frontend\Basket\Iface
65
	{
66
		$this->controller->add( $values );
67
		return $this;
68
	}
69
70
71
	/**
72
	 * Empties the basket and removing all products, addresses, services, etc.
73
	 *
74
	 * @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface
75
	 */
76
	public function clear() : \Aimeos\Controller\Frontend\Basket\Iface
77
	{
78
		$this->controller->clear();
79
		return $this;
80
	}
81
82
83
	/**
84
	 * Returns the basket object.
85
	 *
86
	 * @return \Aimeos\MShop\Order\Item\Iface Basket holding products, addresses and delivery/payment options
87
	 */
88
	public function get() : \Aimeos\MShop\Order\Item\Iface
89
	{
90
		return $this->controller->get();
91
	}
92
93
94
	/**
95
	 * Explicitely persists the basket content
96
	 *
97
	 * @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface
98
	 */
99
	public function save() : \Aimeos\Controller\Frontend\Basket\Iface
100
	{
101
		$this->controller->save();
102
		return $this;
103
	}
104
105
106
	/**
107
	 * Sets the new basket type
108
	 *
109
	 * @param string $type Basket type
110
	 * @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface
111
	 */
112
	public function setType( string $type ) : \Aimeos\Controller\Frontend\Basket\Iface
113
	{
114
		$this->controller->setType( $type );
115
		return $this;
116
	}
117
118
119
	/**
120
	 * Creates a new order object from the current basket
121
	 *
122
	 * @return \Aimeos\MShop\Order\Item\Iface Order object including products, addresses and services
123
	 */
124
	public function store() : \Aimeos\MShop\Order\Item\Iface
125
	{
126
		return $this->controller->store();
127
	}
128
129
130
	/**
131
	 * Returns the order object for the given ID
132
	 *
133
	 * @param string $id Unique ID of the order object
134
	 * @param array $ref References items that should be fetched too
135
	 * @param bool $default True to add default criteria (user logged in), false if not
136
	 * @return \Aimeos\MShop\Order\Item\Iface Order object including the given parts
137
	 */
138
	public function load( string $id, array $ref = ['order/address', 'order/coupon', 'order/product', 'order/service'],
139
		bool $default = true ) : \Aimeos\MShop\Order\Item\Iface
140
	{
141
		return $this->controller->load( $id, $ref, $default );
142
	}
143
144
145
	/**
146
	 * Adds a product to the basket of the customer stored in the session
147
	 *
148
	 * @param \Aimeos\MShop\Product\Item\Iface $product Product to add including texts, media, prices, attributes, etc.
149
	 * @param float $quantity Amount of products that should by added
150
	 * @param array $variant List of variant-building attribute IDs that identify an article in a selection product
151
	 * @param array $config List of configurable attribute IDs the customer has chosen from
152
	 * @param array $custom Associative list of attribute IDs as keys and arbitrary values that will be added to the ordered product
153
	 * @param string $stocktype Unique code of the stock type to deliver the products from
154
	 * @param string|null $siteId Unique ID of the site the product should be bought from or NULL for site the product is from
155
	 * @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface
156
	 * @throws \Aimeos\Controller\Frontend\Basket\Exception If the product isn't available
157
	 */
158
	public function addProduct( \Aimeos\MShop\Product\Item\Iface $product, float $quantity = 1,
159
		array $variant = [], array $config = [], array $custom = [], string $stocktype = 'default', string $siteId = null
160
	) : \Aimeos\Controller\Frontend\Basket\Iface
161
	{
162
		$this->controller->addProduct( $product, $quantity, $variant, $config, $custom, $stocktype, $siteId );
163
		return $this;
164
	}
165
166
167
	/**
168
	 * Deletes a product item from the basket.
169
	 *
170
	 * @param int $position Position number (key) of the order product item
171
	 * @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface
172
	 */
173
	public function deleteProduct( int $position ) : \Aimeos\Controller\Frontend\Basket\Iface
174
	{
175
		$this->controller->deleteProduct( $position );
176
		return $this;
177
	}
178
179
180
	/**
181
	 * Edits the quantity of a product item in the basket.
182
	 *
183
	 * @param int $position Position number (key) of the order product item
184
	 * @param float $quantity New quantiy of the product item
185
	 * @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface
186
	 */
187
	public function updateProduct( int $position, float $quantity ) : \Aimeos\Controller\Frontend\Basket\Iface
188
	{
189
		$this->controller->updateProduct( $position, $quantity );
190
		return $this;
191
	}
192
193
194
	/**
195
	 * Adds the given coupon code and updates the basket.
196
	 *
197
	 * @param string $code Coupon code entered by the user
198
	 * @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface
199
	 * @throws \Aimeos\Controller\Frontend\Basket\Exception if the coupon code is invalid or not allowed
200
	 */
201
	public function addCoupon( string $code ) : \Aimeos\Controller\Frontend\Basket\Iface
202
	{
203
		$this->controller->addCoupon( $code );
204
		return $this;
205
	}
206
207
208
	/**
209
	 * Removes the given coupon code and its effects from the basket.
210
	 *
211
	 * @param string $code Coupon code entered by the user
212
	 * @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface
213
	 * @throws \Aimeos\Controller\Frontend\Basket\Exception if the coupon code is invalid
214
	 */
215
	public function deleteCoupon( string $code ) : \Aimeos\Controller\Frontend\Basket\Iface
216
	{
217
		$this->controller->deleteCoupon( $code );
218
		return $this;
219
	}
220
221
222
	/**
223
	 * Adds an address of the customer to the basket
224
	 *
225
	 * @param string $type Address type code like 'payment' or 'delivery'
226
	 * @param array $values Associative list of key/value pairs with address details
227
	 * @param int|null $position Position number (key) of the order address item
228
	 * @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface
229
	 */
230
	public function addAddress( string $type, array $values = [], int $position = null ) : \Aimeos\Controller\Frontend\Basket\Iface
231
	{
232
		$this->controller->addAddress( $type, $values, $position );
233
		return $this;
234
	}
235
236
	/**
237
	 * Removes the address of the given type and position if available
238
	 *
239
	 * @param string $type Address type code like 'payment' or 'delivery'
240
	 * @param int|null $position Position of the address in the list to overwrite
241
	 * @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface
242
	 */
243
	public function deleteAddress( string $type, int $position = null ) : \Aimeos\Controller\Frontend\Basket\Iface
244
	{
245
		$this->controller->deleteAddress( $type, $position );
246
		return $this;
247
	}
248
249
250
	/**
251
	 * Adds the delivery/payment service including the given configuration
252
	 *
253
	 * @param \Aimeos\MShop\Service\Item\Iface $service Service item selected by the customer
254
	 * @param array $config Associative list of key/value pairs with the options selected by the customer
255
	 * @param int|null $position Position of the address in the list to overwrite
256
	 * @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface
257
	 * @throws \Aimeos\Controller\Frontend\Basket\Exception If given service attributes are invalid
258
	 */
259
	public function addService( \Aimeos\MShop\Service\Item\Iface $service, array $config = [], int $position = null ) : \Aimeos\Controller\Frontend\Basket\Iface
260
	{
261
		$this->controller->addService( $service, $config, $position );
262
		return $this;
263
	}
264
265
266
	/**
267
	 * Removes the delivery or payment service items from the basket
268
	 *
269
	 * @param string $type Service type code like 'payment' or 'delivery'
270
	 * @param int|null $position Position of the address in the list to overwrite
271
	 * @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface
272
	 */
273
	public function deleteService( string $type, int $position = null ) : \Aimeos\Controller\Frontend\Basket\Iface
274
	{
275
		$this->controller->deleteService( $type, $position );
276
		return $this;
277
	}
278
279
280
	/**
281
	 * Injects the reference of the outmost object
282
	 *
283
	 * @param \Aimeos\Controller\Frontend\Iface $object Reference to the outmost controller or decorator
284
	 * @return \Aimeos\Controller\Frontend\Iface Controller object for chaining method calls
285
	 */
286
	public function setObject( \Aimeos\Controller\Frontend\Iface $object ) : \Aimeos\Controller\Frontend\Iface
287
	{
288
		parent::setObject( $object );
289
290
		$this->controller->setObject( $object );
0 ignored issues
show
The method setObject() does not exist on Aimeos\Controller\Frontend\Basket\Iface. Since it exists in all sub-types, consider adding an abstract or default implementation to Aimeos\Controller\Frontend\Basket\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

290
		$this->controller->/** @scrutinizer ignore-call */ 
291
                     setObject( $object );
Loading history...
291
292
		return $this;
293
	}
294
295
296
	/**
297
	 * Returns the frontend controller
298
	 *
299
	 * @return \Aimeos\Controller\Frontend\Iface Frontend controller object
300
	 */
301
	protected function getController() : \Aimeos\Controller\Frontend\Iface
302
	{
303
		return $this->controller;
304
	}
305
}
306