Completed
Push — master ( 4ffab1...137f58 )
by Aimeos
07:59
created
controller/frontend/src/Controller/Frontend/Basket/Standard.php 1 patch
Spacing   +214 added lines, -214 removed lines patch added patch discarded remove patch
@@ -30,11 +30,11 @@  discard block
 block discarded – undo
30 30
 	 * @param \Aimeos\MShop\Context\Item\Iface $context Object storing the required instances for manaing databases
31 31
 	 *  connections, logger, session, etc.
32 32
 	 */
33
-	public function __construct( \Aimeos\MShop\Context\Item\Iface $context )
33
+	public function __construct(\Aimeos\MShop\Context\Item\Iface $context)
34 34
 	{
35
-		parent::__construct( $context );
35
+		parent::__construct($context);
36 36
 
37
-		$this->domainManager = \Aimeos\MShop\Factory::createManager( $context, 'order/base' );
37
+		$this->domainManager = \Aimeos\MShop\Factory::createManager($context, 'order/base');
38 38
 		$this->basket = $this->domainManager->getSession();
39 39
 
40 40
 		$this->checkLocale();
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 	public function clear()
48 48
 	{
49 49
 		$this->basket = $this->domainManager->createItem();
50
-		$this->domainManager->setSession( $this->basket );
50
+		$this->domainManager->setSession($this->basket);
51 51
 	}
52 52
 
53 53
 
@@ -82,47 +82,47 @@  discard block
 block discarded – undo
82 82
 	 * @param string $warehouse Unique code of the warehouse to deliver the products from
83 83
 	 * @throws \Aimeos\Controller\Frontend\Basket\Exception If the product isn't available
84 84
 	 */
85
-	public function addProduct( $prodid, $quantity = 1, array $options = array(), array $variantAttributeIds = array(),
85
+	public function addProduct($prodid, $quantity = 1, array $options = array(), array $variantAttributeIds = array(),
86 86
 		array $configAttributeIds = array(), array $hiddenAttributeIds = array(), array $customAttributeValues = array(),
87
-		$warehouse = 'default' )
87
+		$warehouse = 'default')
88 88
 	{
89 89
 		$context = $this->getContext();
90 90
 
91
-		$productItem = $this->getDomainItem( 'product', 'product.id', $prodid, array( 'media', 'supplier', 'price', 'product', 'text' ) );
91
+		$productItem = $this->getDomainItem('product', 'product.id', $prodid, array('media', 'supplier', 'price', 'product', 'text'));
92 92
 
93
-		$orderBaseProductItem = \Aimeos\MShop\Factory::createManager( $context, 'order/base/product' )->createItem();
94
-		$orderBaseProductItem->copyFrom( $productItem );
95
-		$orderBaseProductItem->setQuantity( $quantity );
96
-		$orderBaseProductItem->setWarehouseCode( $warehouse );
93
+		$orderBaseProductItem = \Aimeos\MShop\Factory::createManager($context, 'order/base/product')->createItem();
94
+		$orderBaseProductItem->copyFrom($productItem);
95
+		$orderBaseProductItem->setQuantity($quantity);
96
+		$orderBaseProductItem->setWarehouseCode($warehouse);
97 97
 
98 98
 		$attr = array();
99
-		$prices = $productItem->getRefItems( 'price', 'default', 'default' );
99
+		$prices = $productItem->getRefItems('price', 'default', 'default');
100 100
 
101
-		switch( $productItem->getType() )
101
+		switch ($productItem->getType())
102 102
 		{
103 103
 			case 'select':
104
-				$attr = $this->getVariantDetails( $orderBaseProductItem, $productItem, $prices, $variantAttributeIds, $options );
104
+				$attr = $this->getVariantDetails($orderBaseProductItem, $productItem, $prices, $variantAttributeIds, $options);
105 105
 				break;
106 106
 			case 'bundle':
107
-				$this->addBundleProducts( $orderBaseProductItem, $productItem, $variantAttributeIds, $warehouse );
107
+				$this->addBundleProducts($orderBaseProductItem, $productItem, $variantAttributeIds, $warehouse);
108 108
 				break;
109 109
 		}
110 110
 
111
-		$priceManager = \Aimeos\MShop\Factory::createManager( $context, 'price' );
112
-		$price = $priceManager->getLowestPrice( $prices, $quantity );
111
+		$priceManager = \Aimeos\MShop\Factory::createManager($context, 'price');
112
+		$price = $priceManager->getLowestPrice($prices, $quantity);
113 113
 
114
-		$attr = array_merge( $attr, $this->createOrderProductAttributes( $price, $prodid, $quantity, $configAttributeIds, 'config' ) );
115
-		$attr = array_merge( $attr, $this->createOrderProductAttributes( $price, $prodid, $quantity, $hiddenAttributeIds, 'hidden' ) );
116
-		$attr = array_merge( $attr, $this->createOrderProductAttributes( $price, $prodid, $quantity, array_keys( $customAttributeValues ), 'custom', $customAttributeValues ) );
114
+		$attr = array_merge($attr, $this->createOrderProductAttributes($price, $prodid, $quantity, $configAttributeIds, 'config'));
115
+		$attr = array_merge($attr, $this->createOrderProductAttributes($price, $prodid, $quantity, $hiddenAttributeIds, 'hidden'));
116
+		$attr = array_merge($attr, $this->createOrderProductAttributes($price, $prodid, $quantity, array_keys($customAttributeValues), 'custom', $customAttributeValues));
117 117
 
118 118
 		// remove product rebate of original price in favor to rebates granted for the order
119
-		$price->setRebate( '0.00' );
119
+		$price->setRebate('0.00');
120 120
 
121
-		$orderBaseProductItem->setPrice( $price );
122
-		$orderBaseProductItem->setAttributes( $attr );
121
+		$orderBaseProductItem->setPrice($price);
122
+		$orderBaseProductItem->setAttributes($attr);
123 123
 
124
-		$this->basket->addProduct( $orderBaseProductItem );
125
-		$this->domainManager->setSession( $this->basket );
124
+		$this->basket->addProduct($orderBaseProductItem);
125
+		$this->domainManager->setSession($this->basket);
126 126
 	}
127 127
 
128 128
 
@@ -131,18 +131,18 @@  discard block
 block discarded – undo
131 131
 	 *
132 132
 	 * @param integer $position Position number (key) of the order product item
133 133
 	 */
134
-	public function deleteProduct( $position )
134
+	public function deleteProduct($position)
135 135
 	{
136
-		$product = $this->basket->getProduct( $position );
136
+		$product = $this->basket->getProduct($position);
137 137
 
138
-		if( $product->getFlags() === \Aimeos\MShop\Order\Item\Base\Product\Base::FLAG_IMMUTABLE )
138
+		if ($product->getFlags() === \Aimeos\MShop\Order\Item\Base\Product\Base::FLAG_IMMUTABLE)
139 139
 		{
140
-			$msg = sprintf( 'Basket item at position "%1$d" cannot be deleted manually', $position );
141
-			throw new \Aimeos\Controller\Frontend\Basket\Exception( $msg );
140
+			$msg = sprintf('Basket item at position "%1$d" cannot be deleted manually', $position);
141
+			throw new \Aimeos\Controller\Frontend\Basket\Exception($msg);
142 142
 		}
143 143
 
144
-		$this->basket->deleteProduct( $position );
145
-		$this->domainManager->setSession( $this->basket );
144
+		$this->basket->deleteProduct($position);
145
+		$this->domainManager->setSession($this->basket);
146 146
 	}
147 147
 
148 148
 
@@ -155,36 +155,36 @@  discard block
 block discarded – undo
155 155
 	 * 	The 'stock'=>false option allows adding products without being in stock.
156 156
 	 * @param string[] $configAttributeCodes Codes of the product config attributes that should be REMOVED
157 157
 	 */
158
-	public function editProduct( $position, $quantity, array $options = array(),
159
-		array $configAttributeCodes = array() )
158
+	public function editProduct($position, $quantity, array $options = array(),
159
+		array $configAttributeCodes = array())
160 160
 	{
161
-		$product = $this->basket->getProduct( $position );
162
-		$product->setQuantity( $quantity ); // Enforce check immediately
161
+		$product = $this->basket->getProduct($position);
162
+		$product->setQuantity($quantity); // Enforce check immediately
163 163
 
164
-		if( $product->getFlags() & \Aimeos\MShop\Order\Item\Base\Product\Base::FLAG_IMMUTABLE )
164
+		if ($product->getFlags() & \Aimeos\MShop\Order\Item\Base\Product\Base::FLAG_IMMUTABLE)
165 165
 		{
166
-			$msg = sprintf( 'Basket item at position "%1$d" cannot be changed', $position );
167
-			throw new \Aimeos\Controller\Frontend\Basket\Exception( $msg );
166
+			$msg = sprintf('Basket item at position "%1$d" cannot be changed', $position);
167
+			throw new \Aimeos\Controller\Frontend\Basket\Exception($msg);
168 168
 		}
169 169
 
170 170
 		$attributes = $product->getAttributes();
171
-		foreach( $attributes as $key => $attribute )
171
+		foreach ($attributes as $key => $attribute)
172 172
 		{
173
-			if( in_array( $attribute->getCode(), $configAttributeCodes ) ) {
174
-				unset( $attributes[$key] );
173
+			if (in_array($attribute->getCode(), $configAttributeCodes)) {
174
+				unset($attributes[$key]);
175 175
 			}
176 176
 		}
177
-		$product->setAttributes( $attributes );
177
+		$product->setAttributes($attributes);
178 178
 
179
-		$productItem = $this->getDomainItem( 'product', 'product.code', $product->getProductCode(), array( 'price', 'text' ) );
180
-		$prices = $productItem->getRefItems( 'price', 'default' );
179
+		$productItem = $this->getDomainItem('product', 'product.code', $product->getProductCode(), array('price', 'text'));
180
+		$prices = $productItem->getRefItems('price', 'default');
181 181
 
182
-		$product->setPrice( $this->calcPrice( $product, $prices, $quantity ) );
182
+		$product->setPrice($this->calcPrice($product, $prices, $quantity));
183 183
 
184
-		$this->basket->deleteProduct( $position );
185
-		$this->basket->addProduct( $product, $position );
184
+		$this->basket->deleteProduct($position);
185
+		$this->basket->addProduct($product, $position);
186 186
 
187
-		$this->domainManager->setSession( $this->basket );
187
+		$this->domainManager->setSession($this->basket);
188 188
 	}
189 189
 
190 190
 
@@ -194,50 +194,50 @@  discard block
 block discarded – undo
194 194
 	 * @param string $code Coupon code entered by the user
195 195
 	 * @throws \Aimeos\Controller\Frontend\Basket\Exception if the coupon code is invalid or not allowed
196 196
 	 */
197
-	public function addCoupon( $code )
197
+	public function addCoupon($code)
198 198
 	{
199
-		$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'coupon' );
200
-		$codeManager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'coupon/code' );
199
+		$manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'coupon');
200
+		$codeManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'coupon/code');
201 201
 
202 202
 
203
-		$search = $codeManager->createSearch( true );
203
+		$search = $codeManager->createSearch(true);
204 204
 		$expr = array(
205
-			$search->compare( '==', 'coupon.code.code', $code ),
205
+			$search->compare('==', 'coupon.code.code', $code),
206 206
 			$search->getConditions(),
207 207
 		);
208
-		$search->setConditions( $search->combine( '&&', $expr ) );
209
-		$search->setSlice( 0, 1 );
208
+		$search->setConditions($search->combine('&&', $expr));
209
+		$search->setSlice(0, 1);
210 210
 
211
-		$result = $codeManager->searchItems( $search );
211
+		$result = $codeManager->searchItems($search);
212 212
 
213
-		if( ( $codeItem = reset( $result ) ) === false ) {
214
-			throw new \Aimeos\Controller\Frontend\Basket\Exception( sprintf( 'Coupon code "%1$s" is invalid or not available any more', $code ) );
213
+		if (($codeItem = reset($result)) === false) {
214
+			throw new \Aimeos\Controller\Frontend\Basket\Exception(sprintf('Coupon code "%1$s" is invalid or not available any more', $code));
215 215
 		}
216 216
 
217 217
 
218
-		$search = $manager->createSearch( true );
218
+		$search = $manager->createSearch(true);
219 219
 		$expr = array(
220
-			$search->compare( '==', 'coupon.id', $codeItem->getParentId() ),
220
+			$search->compare('==', 'coupon.id', $codeItem->getParentId()),
221 221
 			$search->getConditions(),
222 222
 		);
223
-		$search->setConditions( $search->combine( '&&', $expr ) );
224
-		$search->setSlice( 0, 1 );
223
+		$search->setConditions($search->combine('&&', $expr));
224
+		$search->setSlice(0, 1);
225 225
 
226
-		$result = $manager->searchItems( $search );
226
+		$result = $manager->searchItems($search);
227 227
 
228
-		if( ( $item = reset( $result ) ) === false ) {
229
-			throw new \Aimeos\Controller\Frontend\Basket\Exception( sprintf( 'Coupon for code "%1$s" is not available any more', $code ) );
228
+		if (($item = reset($result)) === false) {
229
+			throw new \Aimeos\Controller\Frontend\Basket\Exception(sprintf('Coupon for code "%1$s" is not available any more', $code));
230 230
 		}
231 231
 
232 232
 
233
-		$provider = $manager->getProvider( $item, $code );
233
+		$provider = $manager->getProvider($item, $code);
234 234
 
235
-		if( $provider->isAvailable( $this->basket ) !== true ) {
236
-			throw new \Aimeos\Controller\Frontend\Basket\Exception( sprintf( 'Requirements for coupon code "%1$s" aren\'t met', $code ) );
235
+		if ($provider->isAvailable($this->basket) !== true) {
236
+			throw new \Aimeos\Controller\Frontend\Basket\Exception(sprintf('Requirements for coupon code "%1$s" aren\'t met', $code));
237 237
 		}
238 238
 
239
-		$provider->addCoupon( $this->basket );
240
-		$this->domainManager->setSession( $this->basket );
239
+		$provider->addCoupon($this->basket);
240
+		$this->domainManager->setSession($this->basket);
241 241
 	}
242 242
 
243 243
 
@@ -247,22 +247,22 @@  discard block
 block discarded – undo
247 247
 	 * @param string $code Coupon code entered by the user
248 248
 	 * @throws \Aimeos\Controller\Frontend\Basket\Exception if the coupon code is invalid
249 249
 	 */
250
-	public function deleteCoupon( $code )
250
+	public function deleteCoupon($code)
251 251
 	{
252
-		$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'coupon' );
252
+		$manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'coupon');
253 253
 
254 254
 		$search = $manager->createSearch();
255
-		$search->setConditions( $search->compare( '==', 'coupon.code.code', $code ) );
256
-		$search->setSlice( 0, 1 );
255
+		$search->setConditions($search->compare('==', 'coupon.code.code', $code));
256
+		$search->setSlice(0, 1);
257 257
 
258
-		$result = $manager->searchItems( $search );
258
+		$result = $manager->searchItems($search);
259 259
 
260
-		if( ( $item = reset( $result ) ) === false ) {
261
-			throw new \Aimeos\Controller\Frontend\Basket\Exception( sprintf( 'Coupon code "%1$s" is invalid', $code ) );
260
+		if (($item = reset($result)) === false) {
261
+			throw new \Aimeos\Controller\Frontend\Basket\Exception(sprintf('Coupon code "%1$s" is invalid', $code));
262 262
 		}
263 263
 
264
-		$manager->getProvider( $item, $code )->deleteCoupon( $this->basket );
265
-		$this->domainManager->setSession( $this->basket );
264
+		$manager->getProvider($item, $code)->deleteCoupon($this->basket);
265
+		$this->domainManager->setSession($this->basket);
266 266
 	}
267 267
 
268 268
 
@@ -274,31 +274,31 @@  discard block
 block discarded – undo
274 274
 	 * @throws \Aimeos\Controller\Frontend\Basket\Exception If the billing or delivery address is not of any required type of
275 275
 	 * 	if one of the keys is invalid when using an array with key/value pairs
276 276
 	 */
277
-	public function setAddress( $type, $value )
277
+	public function setAddress($type, $value)
278 278
 	{
279
-		$address = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'order/base/address' )->createItem();
280
-		$address->setType( $type );
279
+		$address = \Aimeos\MShop\Factory::createManager($this->getContext(), 'order/base/address')->createItem();
280
+		$address->setType($type);
281 281
 
282
-		if( $value instanceof \Aimeos\MShop\Common\Item\Address\Iface )
282
+		if ($value instanceof \Aimeos\MShop\Common\Item\Address\Iface)
283 283
 		{
284
-			$address->copyFrom( $value );
285
-			$this->basket->setAddress( $address, $type );
284
+			$address->copyFrom($value);
285
+			$this->basket->setAddress($address, $type);
286 286
 		}
287
-		else if( is_array( $value ) )
287
+		else if (is_array($value))
288 288
 		{
289
-			$this->setAddressFromArray( $address, $value );
290
-			$this->basket->setAddress( $address, $type );
289
+			$this->setAddressFromArray($address, $value);
290
+			$this->basket->setAddress($address, $type);
291 291
 		}
292
-		else if( $value === null )
292
+		else if ($value === null)
293 293
 		{
294
-			$this->basket->deleteAddress( $type );
294
+			$this->basket->deleteAddress($type);
295 295
 		}
296 296
 		else
297 297
 		{
298
-			throw new \Aimeos\Controller\Frontend\Basket\Exception( sprintf( 'Invalid value for address type "%1$s"', $type ) );
298
+			throw new \Aimeos\Controller\Frontend\Basket\Exception(sprintf('Invalid value for address type "%1$s"', $type));
299 299
 		}
300 300
 
301
-		$this->domainManager->setSession( $this->basket );
301
+		$this->domainManager->setSession($this->basket);
302 302
 	}
303 303
 
304 304
 
@@ -311,43 +311,43 @@  discard block
 block discarded – undo
311 311
 	 * 	entered by the customer when choosing one of the delivery or payment options
312 312
 	 * @throws \Aimeos\Controller\Frontend\Basket\Exception If there is no price to the service item attached
313 313
 	 */
314
-	public function setService( $type, $id, array $attributes = array() )
314
+	public function setService($type, $id, array $attributes = array())
315 315
 	{
316 316
 		$context = $this->getContext();
317 317
 
318
-		$serviceManager = \Aimeos\MShop\Factory::createManager( $context, 'service' );
319
-		$serviceItem = $this->getDomainItem( 'service', 'service.id', $id, array( 'media', 'price', 'text' ) );
318
+		$serviceManager = \Aimeos\MShop\Factory::createManager($context, 'service');
319
+		$serviceItem = $this->getDomainItem('service', 'service.id', $id, array('media', 'price', 'text'));
320 320
 
321
-		$provider = $serviceManager->getProvider( $serviceItem );
322
-		$result = $provider->checkConfigFE( $attributes );
323
-		$unknown = array_diff_key( $attributes, $result );
321
+		$provider = $serviceManager->getProvider($serviceItem);
322
+		$result = $provider->checkConfigFE($attributes);
323
+		$unknown = array_diff_key($attributes, $result);
324 324
 
325
-		if( count( $unknown ) > 0 )
325
+		if (count($unknown) > 0)
326 326
 		{
327
-			$msg = sprintf( 'Unknown attributes "%1$s"', implode( '","', array_keys( $unknown ) ) );
328
-			throw new \Aimeos\Controller\Frontend\Basket\Exception( $msg );
327
+			$msg = sprintf('Unknown attributes "%1$s"', implode('","', array_keys($unknown)));
328
+			throw new \Aimeos\Controller\Frontend\Basket\Exception($msg);
329 329
 		}
330 330
 
331
-		foreach( $result as $key => $value )
331
+		foreach ($result as $key => $value)
332 332
 		{
333
-			if( $value !== null ) {
334
-				throw new \Aimeos\Controller\Frontend\Basket\Exception( $value );
333
+			if ($value !== null) {
334
+				throw new \Aimeos\Controller\Frontend\Basket\Exception($value);
335 335
 			}
336 336
 		}
337 337
 
338
-		$orderBaseServiceManager = \Aimeos\MShop\Factory::createManager( $context, 'order/base/service' );
338
+		$orderBaseServiceManager = \Aimeos\MShop\Factory::createManager($context, 'order/base/service');
339 339
 		$orderServiceItem = $orderBaseServiceManager->createItem();
340
-		$orderServiceItem->copyFrom( $serviceItem );
340
+		$orderServiceItem->copyFrom($serviceItem);
341 341
 
342
-		$price = $provider->calcPrice( $this->basket );
342
+		$price = $provider->calcPrice($this->basket);
343 343
 		// remove service rebate of original price
344
-		$price->setRebate( '0.00' );
345
-		$orderServiceItem->setPrice( $price );
344
+		$price->setRebate('0.00');
345
+		$orderServiceItem->setPrice($price);
346 346
 
347
-		$provider->setConfigFE( $orderServiceItem, $attributes );
347
+		$provider->setConfigFE($orderServiceItem, $attributes);
348 348
 
349
-		$this->basket->setService( $orderServiceItem, $type );
350
-		$this->domainManager->setSession( $this->basket );
349
+		$this->basket->setService($orderServiceItem, $type);
350
+		$this->domainManager->setSession($this->basket);
351 351
 	}
352 352
 
353 353
 
@@ -359,44 +359,44 @@  discard block
 block discarded – undo
359 359
 	 * @param array $variantAttributeIds List of product variant attribute IDs
360 360
 	 * @param string $warehouse
361 361
 	 */
362
-	protected function addBundleProducts( \Aimeos\MShop\Order\Item\Base\Product\Iface $orderBaseProductItem,
363
-		\Aimeos\MShop\Product\Item\Iface $productItem, array $variantAttributeIds, $warehouse )
362
+	protected function addBundleProducts(\Aimeos\MShop\Order\Item\Base\Product\Iface $orderBaseProductItem,
363
+		\Aimeos\MShop\Product\Item\Iface $productItem, array $variantAttributeIds, $warehouse)
364 364
 	{
365 365
 		$quantity = $orderBaseProductItem->getQuantity();
366 366
 		$products = $subProductIds = $orderProducts = array();
367
-		$orderProductManager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'order/base/product' );
367
+		$orderProductManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'order/base/product');
368 368
 
369
-		foreach( $productItem->getRefItems( 'product', null, 'default' ) as $item ) {
369
+		foreach ($productItem->getRefItems('product', null, 'default') as $item) {
370 370
 			$subProductIds[] = $item->getId();
371 371
 		}
372 372
 
373
-		if( count( $subProductIds ) > 0 )
373
+		if (count($subProductIds) > 0)
374 374
 		{
375
-			$productManager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product' );
375
+			$productManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product');
376 376
 
377
-			$search = $productManager->createSearch( true );
377
+			$search = $productManager->createSearch(true);
378 378
 			$expr = array(
379
-				$search->compare( '==', 'product.id', $subProductIds ),
379
+				$search->compare('==', 'product.id', $subProductIds),
380 380
 				$search->getConditions(),
381 381
 			);
382
-			$search->setConditions( $search->combine( '&&', $expr ) );
382
+			$search->setConditions($search->combine('&&', $expr));
383 383
 
384
-			$products = $productManager->searchItems( $search, array( 'attribute', 'media', 'price', 'text' ) );
384
+			$products = $productManager->searchItems($search, array('attribute', 'media', 'price', 'text'));
385 385
 		}
386 386
 
387
-		foreach( $products as $product )
387
+		foreach ($products as $product)
388 388
 		{
389
-			$prices = $product->getRefItems( 'price', 'default', 'default' );
389
+			$prices = $product->getRefItems('price', 'default', 'default');
390 390
 
391 391
 			$orderProduct = $orderProductManager->createItem();
392
-			$orderProduct->copyFrom( $product );
393
-			$orderProduct->setWarehouseCode( $warehouse );
394
-			$orderProduct->setPrice( $this->calcPrice( $orderProduct, $prices, $quantity ) );
392
+			$orderProduct->copyFrom($product);
393
+			$orderProduct->setWarehouseCode($warehouse);
394
+			$orderProduct->setPrice($this->calcPrice($orderProduct, $prices, $quantity));
395 395
 
396 396
 			$orderProducts[] = $orderProduct;
397 397
 		}
398 398
 
399
-		$orderBaseProductItem->setProducts( $orderProducts );
399
+		$orderBaseProductItem->setProducts($orderProducts);
400 400
 	}
401 401
 
402 402
 
@@ -410,34 +410,34 @@  discard block
 block discarded – undo
410 410
 		$session = $context->getSession();
411 411
 		$locale = $this->basket->getLocale();
412 412
 
413
-		$localeStr = $session->get( 'aimeos/basket/locale' );
413
+		$localeStr = $session->get('aimeos/basket/locale');
414 414
 		$localeKey = $locale->getSite()->getCode() . '|' . $locale->getLanguageId() . '|' . $locale->getCurrencyId();
415 415
 
416
-		if( $localeStr !== null && $localeStr !== $localeKey )
416
+		if ($localeStr !== null && $localeStr !== $localeKey)
417 417
 		{
418
-			$locParts = explode( '|', $localeStr );
419
-			$locSite = ( isset( $locParts[0] ) ? $locParts[0] : '' );
420
-			$locLanguage = ( isset( $locParts[1] ) ? $locParts[1] : '' );
421
-			$locCurrency = ( isset( $locParts[2] ) ? $locParts[2] : '' );
418
+			$locParts = explode('|', $localeStr);
419
+			$locSite = (isset($locParts[0]) ? $locParts[0] : '');
420
+			$locLanguage = (isset($locParts[1]) ? $locParts[1] : '');
421
+			$locCurrency = (isset($locParts[2]) ? $locParts[2] : '');
422 422
 
423
-			$localeManager = \Aimeos\MShop\Factory::createManager( $context, 'locale' );
424
-			$locale = $localeManager->bootstrap( $locSite, $locLanguage, $locCurrency, false );
423
+			$localeManager = \Aimeos\MShop\Factory::createManager($context, 'locale');
424
+			$locale = $localeManager->bootstrap($locSite, $locLanguage, $locCurrency, false);
425 425
 
426 426
 			$context = clone $context;
427
-			$context->setLocale( $locale );
427
+			$context->setLocale($locale);
428 428
 
429
-			$manager = \Aimeos\MShop\Order\Manager\Factory::createManager( $context )->getSubManager( 'base' );
429
+			$manager = \Aimeos\MShop\Order\Manager\Factory::createManager($context)->getSubManager('base');
430 430
 			$basket = $manager->getSession();
431 431
 
432
-			$this->copyAddresses( $basket, $errors, $localeKey );
433
-			$this->copyServices( $basket, $errors );
434
-			$this->copyProducts( $basket, $errors, $localeKey );
435
-			$this->copyCoupons( $basket, $errors, $localeKey );
432
+			$this->copyAddresses($basket, $errors, $localeKey);
433
+			$this->copyServices($basket, $errors);
434
+			$this->copyProducts($basket, $errors, $localeKey);
435
+			$this->copyCoupons($basket, $errors, $localeKey);
436 436
 
437
-			$manager->setSession( $basket );
437
+			$manager->setSession($basket);
438 438
 		}
439 439
 
440
-		$session->set( 'aimeos/basket/locale', $localeKey );
440
+		$session->set('aimeos/basket/locale', $localeKey);
441 441
 	}
442 442
 
443 443
 
@@ -449,20 +449,20 @@  discard block
 block discarded – undo
449 449
 	 * @param string $localeKey Unique identifier of the site, language and currency
450 450
 	 * @return array Associative list of errors occured
451 451
 	 */
452
-	protected function copyAddresses( \Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors, $localeKey )
452
+	protected function copyAddresses(\Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors, $localeKey)
453 453
 	{
454
-		foreach( $basket->getAddresses() as $type => $item )
454
+		foreach ($basket->getAddresses() as $type => $item)
455 455
 		{
456 456
 			try
457 457
 			{
458
-				$this->setAddress( $type, $item->toArray() );
459
-				$basket->deleteAddress( $type );
458
+				$this->setAddress($type, $item->toArray());
459
+				$basket->deleteAddress($type);
460 460
 			}
461
-			catch( \Exception $e )
461
+			catch (\Exception $e)
462 462
 			{
463 463
 				$logger = $this->getContext()->getLogger();
464 464
 				$str = 'Error migrating address with type "%1$s" in basket to locale "%2$s": %3$s';
465
-				$logger->log( sprintf( $str, $type, $localeKey, $e->getMessage() ), \Aimeos\MW\Logger\Base::INFO );
465
+				$logger->log(sprintf($str, $type, $localeKey, $e->getMessage()), \Aimeos\MW\Logger\Base::INFO);
466 466
 				$errors['address'][$type] = $e->getMessage();
467 467
 			}
468 468
 		}
@@ -479,20 +479,20 @@  discard block
 block discarded – undo
479 479
 	 * @param string $localeKey Unique identifier of the site, language and currency
480 480
 	 * @return array Associative list of errors occured
481 481
 	 */
482
-	protected function copyCoupons( \Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors, $localeKey )
482
+	protected function copyCoupons(\Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors, $localeKey)
483 483
 	{
484
-		foreach( $basket->getCoupons() as $code => $list )
484
+		foreach ($basket->getCoupons() as $code => $list)
485 485
 		{
486 486
 			try
487 487
 			{
488
-				$this->addCoupon( $code );
489
-				$basket->deleteCoupon( $code, true );
488
+				$this->addCoupon($code);
489
+				$basket->deleteCoupon($code, true);
490 490
 			}
491
-			catch( \Exception $e )
491
+			catch (\Exception $e)
492 492
 			{
493 493
 				$logger = $this->getContext()->getLogger();
494 494
 				$str = 'Error migrating coupon with code "%1$s" in basket to locale "%2$s": %3$s';
495
-				$logger->log( sprintf( $str, $code, $localeKey, $e->getMessage() ), \Aimeos\MW\Logger\Base::INFO );
495
+				$logger->log(sprintf($str, $code, $localeKey, $e->getMessage()), \Aimeos\MW\Logger\Base::INFO);
496 496
 				$errors['coupon'][$code] = $e->getMessage();
497 497
 			}
498 498
 		}
@@ -509,11 +509,11 @@  discard block
 block discarded – undo
509 509
 	 * @param string $localeKey Unique identifier of the site, language and currency
510 510
 	 * @return array Associative list of errors occured
511 511
 	 */
512
-	protected function copyProducts( \Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors, $localeKey )
512
+	protected function copyProducts(\Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors, $localeKey)
513 513
 	{
514
-		foreach( $basket->getProducts() as $pos => $product )
514
+		foreach ($basket->getProducts() as $pos => $product)
515 515
 		{
516
-			if( $product->getFlags() & \Aimeos\MShop\Order\Item\Base\Product\Base::FLAG_IMMUTABLE ) {
516
+			if ($product->getFlags() & \Aimeos\MShop\Order\Item\Base\Product\Base::FLAG_IMMUTABLE) {
517 517
 				continue;
518 518
 			}
519 519
 
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
 			{
522 522
 				$attrIds = array();
523 523
 
524
-				foreach( $product->getAttributes() as $attrItem ) {
524
+				foreach ($product->getAttributes() as $attrItem) {
525 525
 					$attrIds[$attrItem->getType()][] = $attrItem->getAttributeId();
526 526
 				}
527 527
 
@@ -529,21 +529,21 @@  discard block
 block discarded – undo
529 529
 					$product->getProductId(),
530 530
 					$product->getQuantity(),
531 531
 					array(),
532
-					$this->getValue( $attrIds, 'variant', array() ),
533
-					$this->getValue( $attrIds, 'config', array() ),
534
-					$this->getValue( $attrIds, 'hidden', array() ),
535
-					$this->getValue( $attrIds, 'custom', array() ),
532
+					$this->getValue($attrIds, 'variant', array()),
533
+					$this->getValue($attrIds, 'config', array()),
534
+					$this->getValue($attrIds, 'hidden', array()),
535
+					$this->getValue($attrIds, 'custom', array()),
536 536
 					$product->getWarehouseCode()
537 537
 				);
538 538
 
539
-				$basket->deleteProduct( $pos );
539
+				$basket->deleteProduct($pos);
540 540
 			}
541
-			catch( \Exception $e )
541
+			catch (\Exception $e)
542 542
 			{
543 543
 				$code = $product->getProductCode();
544 544
 				$logger = $this->getContext()->getLogger();
545 545
 				$str = 'Error migrating product with code "%1$s" in basket to locale "%2$s": %3$s';
546
-				$logger->log( sprintf( $str, $code, $localeKey, $e->getMessage() ), \Aimeos\MW\Logger\Base::INFO );
546
+				$logger->log(sprintf($str, $code, $localeKey, $e->getMessage()), \Aimeos\MW\Logger\Base::INFO);
547 547
 				$errors['product'][$pos] = $e->getMessage();
548 548
 			}
549 549
 		}
@@ -559,22 +559,22 @@  discard block
 block discarded – undo
559 559
 	 * @param array $errors Associative list of previous errors
560 560
 	 * @return array Associative list of errors occured
561 561
 	 */
562
-	protected function copyServices( \Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors )
562
+	protected function copyServices(\Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors)
563 563
 	{
564
-		foreach( $basket->getServices() as $type => $item )
564
+		foreach ($basket->getServices() as $type => $item)
565 565
 		{
566 566
 			try
567 567
 			{
568 568
 				$attributes = array();
569 569
 
570
-				foreach( $item->getAttributes() as $attrItem ) {
570
+				foreach ($item->getAttributes() as $attrItem) {
571 571
 					$attributes[$attrItem->getCode()] = $attrItem->getValue();
572 572
 				}
573 573
 
574
-				$this->setService( $type, $item->getServiceId(), $attributes );
575
-				$basket->deleteService( $type );
574
+				$this->setService($type, $item->getServiceId(), $attributes);
575
+				$basket->deleteService($type);
576 576
 			}
577
-			catch( \Exception $e ) {; } // Don't notify the user as appropriate services can be added automatically
577
+			catch (\Exception $e) {; } // Don't notify the user as appropriate services can be added automatically
578 578
 		}
579 579
 
580 580
 		return $errors;
@@ -589,18 +589,18 @@  discard block
 block discarded – undo
589 589
 	 * 	an address item.
590 590
 	 * @throws \Aimeos\Controller\Frontend\Basket\Exception
591 591
 	 */
592
-	protected function setAddressFromArray( \Aimeos\MShop\Order\Item\Base\Address\Iface $address, array $map )
592
+	protected function setAddressFromArray(\Aimeos\MShop\Order\Item\Base\Address\Iface $address, array $map)
593 593
 	{
594
-		foreach( $map as $key => $value ) {
595
-			$map[$key] = strip_tags( $value ); // prevent XSS
594
+		foreach ($map as $key => $value) {
595
+			$map[$key] = strip_tags($value); // prevent XSS
596 596
 		}
597 597
 
598
-		$errors = $address->fromArray( $map );
598
+		$errors = $address->fromArray($map);
599 599
 
600
-		if( count( $errors ) > 0 )
600
+		if (count($errors) > 0)
601 601
 		{
602
-			$msg = sprintf( 'Invalid address properties, please check your input' );
603
-			throw new \Aimeos\Controller\Frontend\Basket\Exception( $msg, 0, null, $errors );
602
+			$msg = sprintf('Invalid address properties, please check your input');
603
+			throw new \Aimeos\Controller\Frontend\Basket\Exception($msg, 0, null, $errors);
604 604
 		}
605 605
 	}
606 606
 
@@ -613,43 +613,43 @@  discard block
 block discarded – undo
613 613
 	 * @param array $domains Names of the domain items that should be fetched too
614 614
 	 * @return array List of products matching the given attributes
615 615
 	 */
616
-	protected function getProductVariants( \Aimeos\MShop\Product\Item\Iface $productItem, array $variantAttributeIds,
617
-		array $domains = array( 'attribute', 'media', 'price', 'text' ) )
616
+	protected function getProductVariants(\Aimeos\MShop\Product\Item\Iface $productItem, array $variantAttributeIds,
617
+		array $domains = array('attribute', 'media', 'price', 'text'))
618 618
 	{
619 619
 		$subProductIds = array();
620
-		foreach( $productItem->getRefItems( 'product', 'default', 'default' ) as $item ) {
620
+		foreach ($productItem->getRefItems('product', 'default', 'default') as $item) {
621 621
 			$subProductIds[] = $item->getId();
622 622
 		}
623 623
 
624
-		if( count( $subProductIds ) === 0 ) {
624
+		if (count($subProductIds) === 0) {
625 625
 			return array();
626 626
 		}
627 627
 
628
-		$productManager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product' );
629
-		$search = $productManager->createSearch( true );
628
+		$productManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product');
629
+		$search = $productManager->createSearch(true);
630 630
 
631 631
 		$expr = array(
632
-			$search->compare( '==', 'product.id', $subProductIds ),
632
+			$search->compare('==', 'product.id', $subProductIds),
633 633
 			$search->getConditions(),
634 634
 		);
635 635
 
636
-		if( count( $variantAttributeIds ) > 0 )
636
+		if (count($variantAttributeIds) > 0)
637 637
 		{
638
-			foreach( $variantAttributeIds as $key => $id ) {
638
+			foreach ($variantAttributeIds as $key => $id) {
639 639
 				$variantAttributeIds[$key] = (string) $id;
640 640
 			}
641 641
 
642
-			$listTypeItem = $this->getProductListTypeItem( 'attribute', 'variant' );
642
+			$listTypeItem = $this->getProductListTypeItem('attribute', 'variant');
643 643
 
644
-			$param = array( 'attribute', $listTypeItem->getId(), $variantAttributeIds );
645
-			$cmpfunc = $search->createFunction( 'product.contains', $param );
644
+			$param = array('attribute', $listTypeItem->getId(), $variantAttributeIds);
645
+			$cmpfunc = $search->createFunction('product.contains', $param);
646 646
 
647
-			$expr[] = $search->compare( '==', $cmpfunc, count( $variantAttributeIds ) );
647
+			$expr[] = $search->compare('==', $cmpfunc, count($variantAttributeIds));
648 648
 		}
649 649
 
650
-		$search->setConditions( $search->combine( '&&', $expr ) );
650
+		$search->setConditions($search->combine('&&', $expr));
651 651
 
652
-		return $productManager->searchItems( $search, $domains );
652
+		return $productManager->searchItems($search, $domains);
653 653
 	}
654 654
 
655 655
 
@@ -664,44 +664,44 @@  discard block
 block discarded – undo
664 664
 	 * @return \Aimeos\MShop\Order\Item\Base\Product\Attribute\Iface[] List of order product attributes
665 665
 	 * @throws \Aimeos\Controller\Frontend\Basket\Exception If no product variant is found
666 666
 	 */
667
-	protected function getVariantDetails( \Aimeos\MShop\Order\Item\Base\Product\Iface $orderBaseProductItem,
668
-		\Aimeos\MShop\Product\Item\Iface &$productItem, array &$prices, array $variantAttributeIds, array $options )
667
+	protected function getVariantDetails(\Aimeos\MShop\Order\Item\Base\Product\Iface $orderBaseProductItem,
668
+		\Aimeos\MShop\Product\Item\Iface & $productItem, array &$prices, array $variantAttributeIds, array $options)
669 669
 	{
670 670
 		$attr = array();
671
-		$productItems = $this->getProductVariants( $productItem, $variantAttributeIds );
671
+		$productItems = $this->getProductVariants($productItem, $variantAttributeIds);
672 672
 
673
-		if( count( $productItems ) > 1 )
673
+		if (count($productItems) > 1)
674 674
 		{
675
-			$msg = sprintf( 'No unique article found for selected attributes and product ID "%1$s"', $productItem->getId() );
676
-			throw new \Aimeos\Controller\Frontend\Basket\Exception( $msg );
675
+			$msg = sprintf('No unique article found for selected attributes and product ID "%1$s"', $productItem->getId());
676
+			throw new \Aimeos\Controller\Frontend\Basket\Exception($msg);
677 677
 		}
678
-		else if( ( $result = reset( $productItems ) ) !== false ) // count == 1
678
+		else if (($result = reset($productItems)) !== false) // count == 1
679 679
 		{
680 680
 			$productItem = $result;
681
-			$orderBaseProductItem->setProductCode( $productItem->getCode() );
681
+			$orderBaseProductItem->setProductCode($productItem->getCode());
682 682
 
683
-			$subprices = $productItem->getRefItems( 'price', 'default', 'default' );
683
+			$subprices = $productItem->getRefItems('price', 'default', 'default');
684 684
 
685
-			if( count( $subprices ) > 0 ) {
685
+			if (count($subprices) > 0) {
686 686
 				$prices = $subprices;
687 687
 			}
688 688
 
689
-			$orderProductAttrManager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'order/base/product/attribute' );
690
-			$variantAttributes = $productItem->getRefItems( 'attribute', null, 'variant' );
689
+			$orderProductAttrManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'order/base/product/attribute');
690
+			$variantAttributes = $productItem->getRefItems('attribute', null, 'variant');
691 691
 
692
-			foreach( $this->getAttributes( array_keys( $variantAttributes ), array( 'text' ) ) as $attrItem )
692
+			foreach ($this->getAttributes(array_keys($variantAttributes), array('text')) as $attrItem)
693 693
 			{
694 694
 				$orderAttributeItem = $orderProductAttrManager->createItem();
695
-				$orderAttributeItem->copyFrom( $attrItem );
696
-				$orderAttributeItem->setType( 'variant' );
695
+				$orderAttributeItem->copyFrom($attrItem);
696
+				$orderAttributeItem->setType('variant');
697 697
 
698 698
 				$attr[] = $orderAttributeItem;
699 699
 			}
700 700
 		}
701
-		else if( !isset( $options['variant'] ) || $options['variant'] != false ) // count == 0
701
+		else if (!isset($options['variant']) || $options['variant'] != false) // count == 0
702 702
 		{
703
-			$msg = sprintf( 'No article found for selected attributes and product ID "%1$s"', $productItem->getId() );
704
-			throw new \Aimeos\Controller\Frontend\Basket\Exception( $msg );
703
+			$msg = sprintf('No article found for selected attributes and product ID "%1$s"', $productItem->getId());
704
+			throw new \Aimeos\Controller\Frontend\Basket\Exception($msg);
705 705
 		}
706 706
 
707 707
 		return $attr;
Please login to merge, or discard this patch.