Completed
Push — master ( b5acf4...f7db67 )
by Aimeos
02:50
created
controller/frontend/src/Controller/Frontend/Basket/Standard.php 1 patch
Spacing   +131 added lines, -131 removed lines patch added patch discarded remove patch
@@ -33,11 +33,11 @@  discard block
 block discarded – undo
33 33
 	 * @param \Aimeos\MShop\Context\Item\Iface $context Object storing the required instances for manaing databases
34 34
 	 *  connections, logger, session, etc.
35 35
 	 */
36
-	public function __construct( \Aimeos\MShop\Context\Item\Iface $context )
36
+	public function __construct(\Aimeos\MShop\Context\Item\Iface $context)
37 37
 	{
38
-		parent::__construct( $context );
38
+		parent::__construct($context);
39 39
 
40
-		$this->domainManager = \Aimeos\MShop\Factory::createManager( $context, 'order/base' );
40
+		$this->domainManager = \Aimeos\MShop\Factory::createManager($context, 'order/base');
41 41
 	}
42 42
 
43 43
 
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 	public function clear()
50 50
 	{
51 51
 		$this->baskets[$this->type] = $this->domainManager->createItem();
52
-		$this->domainManager->setSession( $this->baskets[$this->type], $this->type );
52
+		$this->domainManager->setSession($this->baskets[$this->type], $this->type);
53 53
 
54 54
 		return $this;
55 55
 	}
@@ -62,10 +62,10 @@  discard block
 block discarded – undo
62 62
 	 */
63 63
 	public function get()
64 64
 	{
65
-		if( !isset( $this->baskets[$this->type] ) )
65
+		if (!isset($this->baskets[$this->type]))
66 66
 		{
67
-			$this->baskets[$this->type] = $this->domainManager->getSession( $this->type );
68
-			$this->checkLocale( $this->type );
67
+			$this->baskets[$this->type] = $this->domainManager->getSession($this->type);
68
+			$this->checkLocale($this->type);
69 69
 		}
70 70
 
71 71
 		return $this->baskets[$this->type];
@@ -79,8 +79,8 @@  discard block
 block discarded – undo
79 79
 	 */
80 80
 	public function save()
81 81
 	{
82
-		if( isset( $this->baskets[$this->type] ) && $this->baskets[$this->type]->isModified() ) {
83
-			$this->domainManager->setSession( $this->baskets[$this->type], $this->type );
82
+		if (isset($this->baskets[$this->type]) && $this->baskets[$this->type]->isModified()) {
83
+			$this->domainManager->setSession($this->baskets[$this->type], $this->type);
84 84
 		}
85 85
 
86 86
 		return $this;
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 	 * @param string $type Basket type
94 94
 	 * @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object
95 95
 	 */
96
-	public function setType( $type )
96
+	public function setType($type)
97 97
 	{
98 98
 		$this->type = $type;
99 99
 		return $this;
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 		 * @category Developer
127 127
 		 * @see controller/frontend/basket/limit-seconds
128 128
 		 */
129
-		$count = $config->get( 'controller/frontend/basket/limit-count', 5 );
129
+		$count = $config->get('controller/frontend/basket/limit-count', 5);
130 130
 
131 131
 		/** controller/frontend/basket/limit-seconds
132 132
 		 * Order limitation time frame in seconds
@@ -144,27 +144,27 @@  discard block
 block discarded – undo
144 144
 		 * @category Developer
145 145
 		 * @see controller/frontend/basket/limit-count
146 146
 		 */
147
-		$seconds = $config->get( 'controller/frontend/basket/limit-seconds', 300 );
147
+		$seconds = $config->get('controller/frontend/basket/limit-seconds', 300);
148 148
 
149 149
 		$search = $this->domainManager->createSearch();
150 150
 		$expr = [
151
-			$search->compare( '==', 'order.base.editor', $this->getContext()->getEditor() ),
152
-			$search->compare( '>=', 'order.base.ctime', date( 'Y-m-d H:i:s', time() - $seconds ) ),
151
+			$search->compare('==', 'order.base.editor', $this->getContext()->getEditor()),
152
+			$search->compare('>=', 'order.base.ctime', date('Y-m-d H:i:s', time() - $seconds)),
153 153
 		];
154
-		$search->setConditions( $search->combine( '&&', $expr ) );
155
-		$search->setSlice( 0, 0 );
154
+		$search->setConditions($search->combine('&&', $expr));
155
+		$search->setSlice(0, 0);
156 156
 
157
-		$this->domainManager->searchItems( $search, [], $total );
157
+		$this->domainManager->searchItems($search, [], $total);
158 158
 
159
-		if( $total > $count ) {
160
-			throw new \Aimeos\Controller\Frontend\Basket\Exception( sprintf( 'Temporary order limit reached' ) );
159
+		if ($total > $count) {
160
+			throw new \Aimeos\Controller\Frontend\Basket\Exception(sprintf('Temporary order limit reached'));
161 161
 		}
162 162
 
163 163
 
164 164
 		$basket = $this->get()->finish();
165 165
 
166 166
 		$this->domainManager->begin();
167
-		$this->domainManager->store( $basket );
167
+		$this->domainManager->store($basket);
168 168
 		$this->domainManager->commit();
169 169
 
170 170
 		return $basket;
@@ -179,9 +179,9 @@  discard block
 block discarded – undo
179 179
 	 * @param boolean $default True to add default criteria (user logged in), false if not
180 180
 	 * @return \Aimeos\MShop\Order\Item\Base\Iface Order base object including the given parts
181 181
 	 */
182
-	public function load( $id, $parts = \Aimeos\MShop\Order\Manager\Base\Base::PARTS_ALL, $default = true )
182
+	public function load($id, $parts = \Aimeos\MShop\Order\Manager\Base\Base::PARTS_ALL, $default = true)
183 183
 	{
184
-		return $this->domainManager->load( $id, $parts, false, $default );
184
+		return $this->domainManager->load($id, $parts, false, $default);
185 185
 	}
186 186
 
187 187
 
@@ -201,36 +201,36 @@  discard block
 block discarded – undo
201 201
 	 * @param string $stocktype Unique code of the stock type to deliver the products from
202 202
 	 * @throws \Aimeos\Controller\Frontend\Basket\Exception If the product isn't available
203 203
 	 */
204
-	public function addProduct( $prodid, $quantity = 1, array $options = [], array $variantAttributeIds = [],
204
+	public function addProduct($prodid, $quantity = 1, array $options = [], array $variantAttributeIds = [],
205 205
 		array $configAttributeIds = [], array $hiddenAttributeIds = [], array $customAttributeValues = [],
206
-		$stocktype = 'default' )
206
+		$stocktype = 'default')
207 207
 	{
208 208
 		$context = $this->getContext();
209
-		$productManager = \Aimeos\MShop\Factory::createManager( $context, 'product' );
210
-		$productItem = $productManager->getItem( $prodid, array( 'media', 'supplier', 'price', 'product', 'text' ), true );
209
+		$productManager = \Aimeos\MShop\Factory::createManager($context, 'product');
210
+		$productItem = $productManager->getItem($prodid, array('media', 'supplier', 'price', 'product', 'text'), true);
211 211
 
212
-		$orderBaseProductItem = \Aimeos\MShop\Factory::createManager( $context, 'order/base/product' )->createItem();
213
-		$orderBaseProductItem->copyFrom( $productItem );
214
-		$orderBaseProductItem->setQuantity( $quantity );
215
-		$orderBaseProductItem->setStockType( $stocktype );
212
+		$orderBaseProductItem = \Aimeos\MShop\Factory::createManager($context, 'order/base/product')->createItem();
213
+		$orderBaseProductItem->copyFrom($productItem);
214
+		$orderBaseProductItem->setQuantity($quantity);
215
+		$orderBaseProductItem->setStockType($stocktype);
216 216
 
217 217
 		$attr = [];
218
-		$prices = $productItem->getRefItems( 'price', 'default', 'default' );
218
+		$prices = $productItem->getRefItems('price', 'default', 'default');
219 219
 
220
-		$priceManager = \Aimeos\MShop\Factory::createManager( $context, 'price' );
221
-		$price = $priceManager->getLowestPrice( $prices, $quantity );
220
+		$priceManager = \Aimeos\MShop\Factory::createManager($context, 'price');
221
+		$price = $priceManager->getLowestPrice($prices, $quantity);
222 222
 
223
-		$attr = array_merge( $attr, $this->createOrderProductAttributes( $price, $prodid, $quantity, $configAttributeIds, 'config' ) );
224
-		$attr = array_merge( $attr, $this->createOrderProductAttributes( $price, $prodid, $quantity, $hiddenAttributeIds, 'hidden' ) );
225
-		$attr = array_merge( $attr, $this->createOrderProductAttributes( $price, $prodid, $quantity, array_keys( $customAttributeValues ), 'custom', $customAttributeValues ) );
223
+		$attr = array_merge($attr, $this->createOrderProductAttributes($price, $prodid, $quantity, $configAttributeIds, 'config'));
224
+		$attr = array_merge($attr, $this->createOrderProductAttributes($price, $prodid, $quantity, $hiddenAttributeIds, 'hidden'));
225
+		$attr = array_merge($attr, $this->createOrderProductAttributes($price, $prodid, $quantity, array_keys($customAttributeValues), 'custom', $customAttributeValues));
226 226
 
227 227
 		// remove product rebate of original price in favor to rebates granted for the order
228
-		$price->setRebate( '0.00' );
228
+		$price->setRebate('0.00');
229 229
 
230
-		$orderBaseProductItem->setPrice( $price );
231
-		$orderBaseProductItem->setAttributes( $attr );
230
+		$orderBaseProductItem->setPrice($price);
231
+		$orderBaseProductItem->setAttributes($attr);
232 232
 
233
-		$this->get()->addProduct( $orderBaseProductItem );
233
+		$this->get()->addProduct($orderBaseProductItem);
234 234
 		$this->save();
235 235
 	}
236 236
 
@@ -240,17 +240,17 @@  discard block
 block discarded – undo
240 240
 	 *
241 241
 	 * @param integer $position Position number (key) of the order product item
242 242
 	 */
243
-	public function deleteProduct( $position )
243
+	public function deleteProduct($position)
244 244
 	{
245
-		$product = $this->get()->getProduct( $position );
245
+		$product = $this->get()->getProduct($position);
246 246
 
247
-		if( $product->getFlags() === \Aimeos\MShop\Order\Item\Base\Product\Base::FLAG_IMMUTABLE )
247
+		if ($product->getFlags() === \Aimeos\MShop\Order\Item\Base\Product\Base::FLAG_IMMUTABLE)
248 248
 		{
249
-			$msg = sprintf( 'Basket item at position "%1$d" cannot be deleted manually', $position );
250
-			throw new \Aimeos\Controller\Frontend\Basket\Exception( $msg );
249
+			$msg = sprintf('Basket item at position "%1$d" cannot be deleted manually', $position);
250
+			throw new \Aimeos\Controller\Frontend\Basket\Exception($msg);
251 251
 		}
252 252
 
253
-		$this->get()->deleteProduct( $position );
253
+		$this->get()->deleteProduct($position);
254 254
 		$this->save();
255 255
 	}
256 256
 
@@ -264,35 +264,35 @@  discard block
 block discarded – undo
264 264
 	 * 	The 'stock'=>false option allows adding products without being in stock.
265 265
 	 * @param string[] $configAttributeCodes Codes of the product config attributes that should be REMOVED
266 266
 	 */
267
-	public function editProduct( $position, $quantity, array $options = [],
268
-		array $configAttributeCodes = [] )
267
+	public function editProduct($position, $quantity, array $options = [],
268
+		array $configAttributeCodes = [])
269 269
 	{
270
-		$product = $this->get()->getProduct( $position );
270
+		$product = $this->get()->getProduct($position);
271 271
 
272
-		if( $product->getFlags() & \Aimeos\MShop\Order\Item\Base\Product\Base::FLAG_IMMUTABLE )
272
+		if ($product->getFlags() & \Aimeos\MShop\Order\Item\Base\Product\Base::FLAG_IMMUTABLE)
273 273
 		{
274
-			$msg = sprintf( 'Basket item at position "%1$d" cannot be changed', $position );
275
-			throw new \Aimeos\Controller\Frontend\Basket\Exception( $msg );
274
+			$msg = sprintf('Basket item at position "%1$d" cannot be changed', $position);
275
+			throw new \Aimeos\Controller\Frontend\Basket\Exception($msg);
276 276
 		}
277 277
 
278
-		$product->setQuantity( $quantity );
278
+		$product->setQuantity($quantity);
279 279
 
280 280
 		$attributes = $product->getAttributes();
281
-		foreach( $attributes as $key => $attribute )
281
+		foreach ($attributes as $key => $attribute)
282 282
 		{
283
-			if( in_array( $attribute->getCode(), $configAttributeCodes ) ) {
284
-				unset( $attributes[$key] );
283
+			if (in_array($attribute->getCode(), $configAttributeCodes)) {
284
+				unset($attributes[$key]);
285 285
 			}
286 286
 		}
287
-		$product->setAttributes( $attributes );
287
+		$product->setAttributes($attributes);
288 288
 
289
-		$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product' );
290
-		$productItem = $manager->findItem( $product->getProductCode(), array( 'price', 'text' ) );
291
-		$prices = $productItem->getRefItems( 'price', 'default' );
292
-		$product->setPrice( $this->calcPrice( $product, $prices, $quantity ) );
289
+		$manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product');
290
+		$productItem = $manager->findItem($product->getProductCode(), array('price', 'text'));
291
+		$prices = $productItem->getRefItems('price', 'default');
292
+		$product->setPrice($this->calcPrice($product, $prices, $quantity));
293 293
 
294
-		$this->get()->deleteProduct( $position );
295
-		$this->get()->addProduct( $product, $position );
294
+		$this->get()->deleteProduct($position);
295
+		$this->get()->addProduct($product, $position);
296 296
 
297 297
 		$this->save();
298 298
 	}
@@ -304,49 +304,49 @@  discard block
 block discarded – undo
304 304
 	 * @param string $code Coupon code entered by the user
305 305
 	 * @throws \Aimeos\Controller\Frontend\Basket\Exception if the coupon code is invalid or not allowed
306 306
 	 */
307
-	public function addCoupon( $code )
307
+	public function addCoupon($code)
308 308
 	{
309
-		$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'coupon' );
310
-		$codeManager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'coupon/code' );
309
+		$manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'coupon');
310
+		$codeManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'coupon/code');
311 311
 
312 312
 
313
-		$search = $codeManager->createSearch( true );
313
+		$search = $codeManager->createSearch(true);
314 314
 		$expr = array(
315
-			$search->compare( '==', 'coupon.code.code', $code ),
315
+			$search->compare('==', 'coupon.code.code', $code),
316 316
 			$search->getConditions(),
317 317
 		);
318
-		$search->setConditions( $search->combine( '&&', $expr ) );
319
-		$search->setSlice( 0, 1 );
318
+		$search->setConditions($search->combine('&&', $expr));
319
+		$search->setSlice(0, 1);
320 320
 
321
-		$result = $codeManager->searchItems( $search );
321
+		$result = $codeManager->searchItems($search);
322 322
 
323
-		if( ( $codeItem = reset( $result ) ) === false ) {
324
-			throw new \Aimeos\Controller\Frontend\Basket\Exception( sprintf( 'Coupon code "%1$s" is invalid or not available any more', $code ) );
323
+		if (($codeItem = reset($result)) === false) {
324
+			throw new \Aimeos\Controller\Frontend\Basket\Exception(sprintf('Coupon code "%1$s" is invalid or not available any more', $code));
325 325
 		}
326 326
 
327 327
 
328
-		$search = $manager->createSearch( true );
328
+		$search = $manager->createSearch(true);
329 329
 		$expr = array(
330
-			$search->compare( '==', 'coupon.id', $codeItem->getParentId() ),
330
+			$search->compare('==', 'coupon.id', $codeItem->getParentId()),
331 331
 			$search->getConditions(),
332 332
 		);
333
-		$search->setConditions( $search->combine( '&&', $expr ) );
334
-		$search->setSlice( 0, 1 );
333
+		$search->setConditions($search->combine('&&', $expr));
334
+		$search->setSlice(0, 1);
335 335
 
336
-		$result = $manager->searchItems( $search );
336
+		$result = $manager->searchItems($search);
337 337
 
338
-		if( ( $item = reset( $result ) ) === false ) {
339
-			throw new \Aimeos\Controller\Frontend\Basket\Exception( sprintf( 'Coupon for code "%1$s" is not available any more', $code ) );
338
+		if (($item = reset($result)) === false) {
339
+			throw new \Aimeos\Controller\Frontend\Basket\Exception(sprintf('Coupon for code "%1$s" is not available any more', $code));
340 340
 		}
341 341
 
342 342
 
343
-		$provider = $manager->getProvider( $item, $code );
343
+		$provider = $manager->getProvider($item, $code);
344 344
 
345
-		if( $provider->isAvailable( $this->get() ) !== true ) {
346
-			throw new \Aimeos\Controller\Frontend\Basket\Exception( sprintf( 'Requirements for coupon code "%1$s" aren\'t met', $code ) );
345
+		if ($provider->isAvailable($this->get()) !== true) {
346
+			throw new \Aimeos\Controller\Frontend\Basket\Exception(sprintf('Requirements for coupon code "%1$s" aren\'t met', $code));
347 347
 		}
348 348
 
349
-		$provider->addCoupon( $this->get() );
349
+		$provider->addCoupon($this->get());
350 350
 		$this->save();
351 351
 	}
352 352
 
@@ -357,21 +357,21 @@  discard block
 block discarded – undo
357 357
 	 * @param string $code Coupon code entered by the user
358 358
 	 * @throws \Aimeos\Controller\Frontend\Basket\Exception if the coupon code is invalid
359 359
 	 */
360
-	public function deleteCoupon( $code )
360
+	public function deleteCoupon($code)
361 361
 	{
362
-		$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'coupon' );
362
+		$manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'coupon');
363 363
 
364 364
 		$search = $manager->createSearch();
365
-		$search->setConditions( $search->compare( '==', 'coupon.code.code', $code ) );
366
-		$search->setSlice( 0, 1 );
365
+		$search->setConditions($search->compare('==', 'coupon.code.code', $code));
366
+		$search->setSlice(0, 1);
367 367
 
368
-		$result = $manager->searchItems( $search );
368
+		$result = $manager->searchItems($search);
369 369
 
370
-		if( ( $item = reset( $result ) ) === false ) {
371
-			throw new \Aimeos\Controller\Frontend\Basket\Exception( sprintf( 'Coupon code "%1$s" is invalid', $code ) );
370
+		if (($item = reset($result)) === false) {
371
+			throw new \Aimeos\Controller\Frontend\Basket\Exception(sprintf('Coupon code "%1$s" is invalid', $code));
372 372
 		}
373 373
 
374
-		$manager->getProvider( $item, $code )->deleteCoupon( $this->get() );
374
+		$manager->getProvider($item, $code)->deleteCoupon($this->get());
375 375
 		$this->save();
376 376
 	}
377 377
 
@@ -384,28 +384,28 @@  discard block
 block discarded – undo
384 384
 	 * @throws \Aimeos\Controller\Frontend\Basket\Exception If the billing or delivery address is not of any required type of
385 385
 	 * 	if one of the keys is invalid when using an array with key/value pairs
386 386
 	 */
387
-	public function setAddress( $type, $value )
387
+	public function setAddress($type, $value)
388 388
 	{
389
-		$address = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'order/base/address' )->createItem();
390
-		$address->setType( $type );
389
+		$address = \Aimeos\MShop\Factory::createManager($this->getContext(), 'order/base/address')->createItem();
390
+		$address->setType($type);
391 391
 
392
-		if( $value instanceof \Aimeos\MShop\Common\Item\Address\Iface )
392
+		if ($value instanceof \Aimeos\MShop\Common\Item\Address\Iface)
393 393
 		{
394
-			$address->copyFrom( $value );
395
-			$this->get()->setAddress( $address, $type );
394
+			$address->copyFrom($value);
395
+			$this->get()->setAddress($address, $type);
396 396
 		}
397
-		else if( is_array( $value ) )
397
+		else if (is_array($value))
398 398
 		{
399
-			$this->setAddressFromArray( $address, $value );
400
-			$this->get()->setAddress( $address, $type );
399
+			$this->setAddressFromArray($address, $value);
400
+			$this->get()->setAddress($address, $type);
401 401
 		}
402
-		else if( $value === null )
402
+		else if ($value === null)
403 403
 		{
404
-			$this->get()->deleteAddress( $type );
404
+			$this->get()->deleteAddress($type);
405 405
 		}
406 406
 		else
407 407
 		{
408
-			throw new \Aimeos\Controller\Frontend\Basket\Exception( sprintf( 'Invalid value for address type "%1$s"', $type ) );
408
+			throw new \Aimeos\Controller\Frontend\Basket\Exception(sprintf('Invalid value for address type "%1$s"', $type));
409 409
 		}
410 410
 
411 411
 		$this->save();
@@ -421,48 +421,48 @@  discard block
 block discarded – undo
421 421
 	 * 	entered by the customer when choosing one of the delivery or payment options
422 422
 	 * @throws \Aimeos\Controller\Frontend\Basket\Exception If there is no price to the service item attached
423 423
 	 */
424
-	public function setService( $type, $id, array $attributes = [] )
424
+	public function setService($type, $id, array $attributes = [])
425 425
 	{
426
-		if( $id === null )
426
+		if ($id === null)
427 427
 		{
428
-			$this->get()->deleteService( $type );
428
+			$this->get()->deleteService($type);
429 429
 			$this->save();
430 430
 			return;
431 431
 		}
432 432
 
433 433
 		$context = $this->getContext();
434 434
 
435
-		$serviceManager = \Aimeos\MShop\Factory::createManager( $context, 'service' );
436
-		$serviceItem = $serviceManager->getItem( $id, array( 'media', 'price', 'text' ) );
435
+		$serviceManager = \Aimeos\MShop\Factory::createManager($context, 'service');
436
+		$serviceItem = $serviceManager->getItem($id, array('media', 'price', 'text'));
437 437
 
438
-		$provider = $serviceManager->getProvider( $serviceItem );
439
-		$result = $provider->checkConfigFE( $attributes );
440
-		$unknown = array_diff_key( $attributes, $result );
438
+		$provider = $serviceManager->getProvider($serviceItem);
439
+		$result = $provider->checkConfigFE($attributes);
440
+		$unknown = array_diff_key($attributes, $result);
441 441
 
442
-		if( count( $unknown ) > 0 )
442
+		if (count($unknown) > 0)
443 443
 		{
444
-			$msg = sprintf( 'Unknown attributes "%1$s"', implode( '","', array_keys( $unknown ) ) );
445
-			throw new \Aimeos\Controller\Frontend\Basket\Exception( $msg );
444
+			$msg = sprintf('Unknown attributes "%1$s"', implode('","', array_keys($unknown)));
445
+			throw new \Aimeos\Controller\Frontend\Basket\Exception($msg);
446 446
 		}
447 447
 
448
-		foreach( $result as $key => $value )
448
+		foreach ($result as $key => $value)
449 449
 		{
450
-			if( $value !== null ) {
451
-				throw new \Aimeos\Controller\Frontend\Basket\Exception( $value );
450
+			if ($value !== null) {
451
+				throw new \Aimeos\Controller\Frontend\Basket\Exception($value);
452 452
 			}
453 453
 		}
454 454
 
455
-		$orderBaseServiceManager = \Aimeos\MShop\Factory::createManager( $context, 'order/base/service' );
455
+		$orderBaseServiceManager = \Aimeos\MShop\Factory::createManager($context, 'order/base/service');
456 456
 		$orderServiceItem = $orderBaseServiceManager->createItem();
457
-		$orderServiceItem->copyFrom( $serviceItem );
457
+		$orderServiceItem->copyFrom($serviceItem);
458 458
 
459 459
 		// remove service rebate of original price
460
-		$price = $provider->calcPrice( $this->get() )->setRebate( '0.00' );
461
-		$orderServiceItem->setPrice( $price );
460
+		$price = $provider->calcPrice($this->get())->setRebate('0.00');
461
+		$orderServiceItem->setPrice($price);
462 462
 
463
-		$provider->setConfigFE( $orderServiceItem, $attributes );
463
+		$provider->setConfigFE($orderServiceItem, $attributes);
464 464
 
465
-		$this->get()->setService( $orderServiceItem, $type );
465
+		$this->get()->setService($orderServiceItem, $type);
466 466
 		$this->save();
467 467
 	}
468 468
 
@@ -475,18 +475,18 @@  discard block
 block discarded – undo
475 475
 	 * 	an address item.
476 476
 	 * @throws \Aimeos\Controller\Frontend\Basket\Exception
477 477
 	 */
478
-	protected function setAddressFromArray( \Aimeos\MShop\Order\Item\Base\Address\Iface $address, array $map )
478
+	protected function setAddressFromArray(\Aimeos\MShop\Order\Item\Base\Address\Iface $address, array $map)
479 479
 	{
480
-		foreach( $map as $key => $value ) {
481
-			$map[$key] = strip_tags( $value ); // prevent XSS
480
+		foreach ($map as $key => $value) {
481
+			$map[$key] = strip_tags($value); // prevent XSS
482 482
 		}
483 483
 
484
-		$errors = $address->fromArray( $map );
484
+		$errors = $address->fromArray($map);
485 485
 
486
-		if( count( $errors ) > 0 )
486
+		if (count($errors) > 0)
487 487
 		{
488
-			$msg = sprintf( 'Invalid address properties, please check your input' );
489
-			throw new \Aimeos\Controller\Frontend\Basket\Exception( $msg, 0, null, $errors );
488
+			$msg = sprintf('Invalid address properties, please check your input');
489
+			throw new \Aimeos\Controller\Frontend\Basket\Exception($msg, 0, null, $errors);
490 490
 		}
491 491
 	}
492 492
 }
Please login to merge, or discard this patch.
controller/frontend/src/Controller/Frontend/Basket/Base.php 1 patch
Spacing   +150 added lines, -150 removed lines patch added patch discarded remove patch
@@ -31,32 +31,32 @@  discard block
 block discarded – undo
31 31
 	 * @param integer $quantity New product quantity
32 32
 	 * @return \Aimeos\MShop\Price\Item\Iface Price item with calculated price
33 33
 	 */
34
-	protected function calcPrice( \Aimeos\MShop\Order\Item\Base\Product\Iface $product, array $prices, $quantity )
34
+	protected function calcPrice(\Aimeos\MShop\Order\Item\Base\Product\Iface $product, array $prices, $quantity)
35 35
 	{
36 36
 		$context = $this->getContext();
37 37
 
38
-		if( empty( $prices ) )
38
+		if (empty($prices))
39 39
 		{
40
-			$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product' );
41
-			$prices = $manager->getItem( $product->getProductId(), array( 'price' ) )->getRefItems( 'price', 'default' );
40
+			$manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product');
41
+			$prices = $manager->getItem($product->getProductId(), array('price'))->getRefItems('price', 'default');
42 42
 		}
43 43
 
44
-		$priceManager = \Aimeos\MShop\Factory::createManager( $context, 'price' );
45
-		$price = $priceManager->getLowestPrice( $prices, $quantity );
44
+		$priceManager = \Aimeos\MShop\Factory::createManager($context, 'price');
45
+		$price = $priceManager->getLowestPrice($prices, $quantity);
46 46
 
47
-		foreach( $this->getAttributeItems( $product->getAttributes() ) as $attrItem )
47
+		foreach ($this->getAttributeItems($product->getAttributes()) as $attrItem)
48 48
 		{
49
-			$prices = $attrItem->getRefItems( 'price', 'default' );
49
+			$prices = $attrItem->getRefItems('price', 'default');
50 50
 
51
-			if( count( $prices ) > 0 )
51
+			if (count($prices) > 0)
52 52
 			{
53
-				$attrPrice = $priceManager->getLowestPrice( $prices, $quantity );
54
-				$price->addItem( $attrPrice );
53
+				$attrPrice = $priceManager->getLowestPrice($prices, $quantity);
54
+				$price->addItem($attrPrice);
55 55
 			}
56 56
 		}
57 57
 
58 58
 		// remove product rebate of original price in favor to rebates granted for the order
59
-		$price->setRebate( '0.00' );
59
+		$price->setRebate('0.00');
60 60
 
61 61
 		return $price;
62 62
 	}
@@ -71,34 +71,34 @@  discard block
 block discarded – undo
71 71
 	 * @param array $refIds List of IDs that must be associated to the product
72 72
 	 * @throws \Aimeos\Controller\Frontend\Basket\Exception If one or more of the IDs are not associated
73 73
 	 */
74
-	protected function checkReferences( $prodId, $domain, $listTypeId, array $refIds )
74
+	protected function checkReferences($prodId, $domain, $listTypeId, array $refIds)
75 75
 	{
76
-		$productManager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product' );
77
-		$search = $productManager->createSearch( true );
76
+		$productManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product');
77
+		$search = $productManager->createSearch(true);
78 78
 
79 79
 		$expr = array(
80
-			$search->compare( '==', 'product.id', $prodId ),
80
+			$search->compare('==', 'product.id', $prodId),
81 81
 			$search->getConditions(),
82 82
 		);
83 83
 
84
-		if( count( $refIds ) > 0 )
84
+		if (count($refIds) > 0)
85 85
 		{
86
-			foreach( $refIds as $key => $refId ) {
86
+			foreach ($refIds as $key => $refId) {
87 87
 				$refIds[$key] = (string) $refId;
88 88
 			}
89 89
 
90
-			$param = array( $domain, $listTypeId, $refIds );
91
-			$cmpfunc = $search->createFunction( 'product.contains', $param );
90
+			$param = array($domain, $listTypeId, $refIds);
91
+			$cmpfunc = $search->createFunction('product.contains', $param);
92 92
 
93
-			$expr[] = $search->compare( '==', $cmpfunc, count( $refIds ) );
93
+			$expr[] = $search->compare('==', $cmpfunc, count($refIds));
94 94
 		}
95 95
 
96
-		$search->setConditions( $search->combine( '&&', $expr ) );
96
+		$search->setConditions($search->combine('&&', $expr));
97 97
 
98
-		if( count( $productManager->searchItems( $search, [] ) ) === 0 )
98
+		if (count($productManager->searchItems($search, [])) === 0)
99 99
 		{
100
-			$msg = sprintf( 'Invalid "%1$s" references for product with ID %2$s', $domain, json_encode( $prodId ) );
101
-			throw new \Aimeos\Controller\Frontend\Basket\Exception( $msg );
100
+			$msg = sprintf('Invalid "%1$s" references for product with ID %2$s', $domain, json_encode($prodId));
101
+			throw new \Aimeos\Controller\Frontend\Basket\Exception($msg);
102 102
 		}
103 103
 	}
104 104
 
@@ -108,41 +108,41 @@  discard block
 block discarded – undo
108 108
 	 *
109 109
 	 * @param string $type Basket type
110 110
 	 */
111
-	protected function checkLocale( $type )
111
+	protected function checkLocale($type)
112 112
 	{
113 113
 		$errors = [];
114 114
 		$context = $this->getContext();
115 115
 		$session = $context->getSession();
116 116
 		$locale = $this->get()->getLocale();
117 117
 
118
-		$localeStr = $session->get( 'aimeos/basket/locale' );
118
+		$localeStr = $session->get('aimeos/basket/locale');
119 119
 		$localeKey = $locale->getSite()->getCode() . '|' . $locale->getLanguageId() . '|' . $locale->getCurrencyId();
120 120
 
121
-		if( $localeStr !== null && $localeStr !== $localeKey )
121
+		if ($localeStr !== null && $localeStr !== $localeKey)
122 122
 		{
123
-			$locParts = explode( '|', $localeStr );
124
-			$locSite = ( isset( $locParts[0] ) ? $locParts[0] : '' );
125
-			$locLanguage = ( isset( $locParts[1] ) ? $locParts[1] : '' );
126
-			$locCurrency = ( isset( $locParts[2] ) ? $locParts[2] : '' );
123
+			$locParts = explode('|', $localeStr);
124
+			$locSite = (isset($locParts[0]) ? $locParts[0] : '');
125
+			$locLanguage = (isset($locParts[1]) ? $locParts[1] : '');
126
+			$locCurrency = (isset($locParts[2]) ? $locParts[2] : '');
127 127
 
128
-			$localeManager = \Aimeos\MShop\Factory::createManager( $context, 'locale' );
129
-			$locale = $localeManager->bootstrap( $locSite, $locLanguage, $locCurrency, false );
128
+			$localeManager = \Aimeos\MShop\Factory::createManager($context, 'locale');
129
+			$locale = $localeManager->bootstrap($locSite, $locLanguage, $locCurrency, false);
130 130
 
131 131
 			$context = clone $context;
132
-			$context->setLocale( $locale );
132
+			$context->setLocale($locale);
133 133
 
134
-			$manager = \Aimeos\MShop\Order\Manager\Factory::createManager( $context )->getSubManager( 'base' );
135
-			$basket = $manager->getSession( $type );
134
+			$manager = \Aimeos\MShop\Order\Manager\Factory::createManager($context)->getSubManager('base');
135
+			$basket = $manager->getSession($type);
136 136
 
137
-			$this->copyAddresses( $basket, $errors, $localeKey );
138
-			$this->copyServices( $basket, $errors );
139
-			$this->copyProducts( $basket, $errors, $localeKey );
140
-			$this->copyCoupons( $basket, $errors, $localeKey );
137
+			$this->copyAddresses($basket, $errors, $localeKey);
138
+			$this->copyServices($basket, $errors);
139
+			$this->copyProducts($basket, $errors, $localeKey);
140
+			$this->copyCoupons($basket, $errors, $localeKey);
141 141
 
142
-			$manager->setSession( $basket, $type );
142
+			$manager->setSession($basket, $type);
143 143
 		}
144 144
 
145
-		$session->set( 'aimeos/basket/locale', $localeKey );
145
+		$session->set('aimeos/basket/locale', $localeKey);
146 146
 	}
147 147
 
148 148
 
@@ -154,20 +154,20 @@  discard block
 block discarded – undo
154 154
 	 * @param string $localeKey Unique identifier of the site, language and currency
155 155
 	 * @return array Associative list of errors occured
156 156
 	 */
157
-	protected function copyAddresses( \Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors, $localeKey )
157
+	protected function copyAddresses(\Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors, $localeKey)
158 158
 	{
159
-		foreach( $basket->getAddresses() as $type => $item )
159
+		foreach ($basket->getAddresses() as $type => $item)
160 160
 		{
161 161
 			try
162 162
 			{
163
-				$this->setAddress( $type, $item->toArray() );
164
-				$basket->deleteAddress( $type );
163
+				$this->setAddress($type, $item->toArray());
164
+				$basket->deleteAddress($type);
165 165
 			}
166
-			catch( \Exception $e )
166
+			catch (\Exception $e)
167 167
 			{
168 168
 				$logger = $this->getContext()->getLogger();
169 169
 				$str = 'Error migrating address with type "%1$s" in basket to locale "%2$s": %3$s';
170
-				$logger->log( sprintf( $str, $type, $localeKey, $e->getMessage() ), \Aimeos\MW\Logger\Base::INFO );
170
+				$logger->log(sprintf($str, $type, $localeKey, $e->getMessage()), \Aimeos\MW\Logger\Base::INFO);
171 171
 				$errors['address'][$type] = $e->getMessage();
172 172
 			}
173 173
 		}
@@ -184,20 +184,20 @@  discard block
 block discarded – undo
184 184
 	 * @param string $localeKey Unique identifier of the site, language and currency
185 185
 	 * @return array Associative list of errors occured
186 186
 	 */
187
-	protected function copyCoupons( \Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors, $localeKey )
187
+	protected function copyCoupons(\Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors, $localeKey)
188 188
 	{
189
-		foreach( $basket->getCoupons() as $code => $list )
189
+		foreach ($basket->getCoupons() as $code => $list)
190 190
 		{
191 191
 			try
192 192
 			{
193
-				$this->addCoupon( $code );
194
-				$basket->deleteCoupon( $code, true );
193
+				$this->addCoupon($code);
194
+				$basket->deleteCoupon($code, true);
195 195
 			}
196
-			catch( \Exception $e )
196
+			catch (\Exception $e)
197 197
 			{
198 198
 				$logger = $this->getContext()->getLogger();
199 199
 				$str = 'Error migrating coupon with code "%1$s" in basket to locale "%2$s": %3$s';
200
-				$logger->log( sprintf( $str, $code, $localeKey, $e->getMessage() ), \Aimeos\MW\Logger\Base::INFO );
200
+				$logger->log(sprintf($str, $code, $localeKey, $e->getMessage()), \Aimeos\MW\Logger\Base::INFO);
201 201
 				$errors['coupon'][$code] = $e->getMessage();
202 202
 			}
203 203
 		}
@@ -214,11 +214,11 @@  discard block
 block discarded – undo
214 214
 	 * @param string $localeKey Unique identifier of the site, language and currency
215 215
 	 * @return array Associative list of errors occured
216 216
 	 */
217
-	protected function copyProducts( \Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors, $localeKey )
217
+	protected function copyProducts(\Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors, $localeKey)
218 218
 	{
219
-		foreach( $basket->getProducts() as $pos => $product )
219
+		foreach ($basket->getProducts() as $pos => $product)
220 220
 		{
221
-			if( $product->getFlags() & \Aimeos\MShop\Order\Item\Base\Product\Base::FLAG_IMMUTABLE ) {
221
+			if ($product->getFlags() & \Aimeos\MShop\Order\Item\Base\Product\Base::FLAG_IMMUTABLE) {
222 222
 				continue;
223 223
 			}
224 224
 
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 			{
227 227
 				$attrIds = [];
228 228
 
229
-				foreach( $product->getAttributes() as $attrItem ) {
229
+				foreach ($product->getAttributes() as $attrItem) {
230 230
 					$attrIds[$attrItem->getType()][] = $attrItem->getAttributeId();
231 231
 				}
232 232
 
@@ -234,23 +234,23 @@  discard block
 block discarded – undo
234 234
 					$product->getProductId(),
235 235
 					$product->getQuantity(),
236 236
 					[],
237
-					$this->getValue( $attrIds, 'variant', [] ),
238
-					$this->getValue( $attrIds, 'config', [] ),
239
-					$this->getValue( $attrIds, 'hidden', [] ),
240
-					$this->getValue( $attrIds, 'custom', [] ),
237
+					$this->getValue($attrIds, 'variant', []),
238
+					$this->getValue($attrIds, 'config', []),
239
+					$this->getValue($attrIds, 'hidden', []),
240
+					$this->getValue($attrIds, 'custom', []),
241 241
 					$product->getStockType()
242 242
 				);
243 243
 
244
-				$basket->deleteProduct( $pos );
244
+				$basket->deleteProduct($pos);
245 245
 			}
246
-			catch( \Exception $e )
246
+			catch (\Exception $e)
247 247
 			{
248 248
 				$code = $product->getProductCode();
249 249
 				$logger = $this->getContext()->getLogger();
250 250
 				$errors['product'][$pos] = $e->getMessage();
251 251
 
252 252
 				$str = 'Error migrating product with code "%1$s" in basket to locale "%2$s": %3$s';
253
-				$logger->log( sprintf( $str, $code, $localeKey, $e->getMessage() ), \Aimeos\MW\Logger\Base::INFO );
253
+				$logger->log(sprintf($str, $code, $localeKey, $e->getMessage()), \Aimeos\MW\Logger\Base::INFO);
254 254
 			}
255 255
 		}
256 256
 
@@ -265,22 +265,22 @@  discard block
 block discarded – undo
265 265
 	 * @param array $errors Associative list of previous errors
266 266
 	 * @return array Associative list of errors occured
267 267
 	 */
268
-	protected function copyServices( \Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors )
268
+	protected function copyServices(\Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors)
269 269
 	{
270
-		foreach( $basket->getServices() as $type => $item )
270
+		foreach ($basket->getServices() as $type => $item)
271 271
 		{
272 272
 			try
273 273
 			{
274 274
 				$attributes = [];
275 275
 
276
-				foreach( $item->getAttributes() as $attrItem ) {
276
+				foreach ($item->getAttributes() as $attrItem) {
277 277
 					$attributes[$attrItem->getCode()] = $attrItem->getValue();
278 278
 				}
279 279
 
280
-				$this->setService( $type, $item->getServiceId(), $attributes );
281
-				$basket->deleteService( $type );
280
+				$this->setService($type, $item->getServiceId(), $attributes);
281
+				$basket->deleteService($type);
282 282
 			}
283
-			catch( \Exception $e ) { ; } // Don't notify the user as appropriate services can be added automatically
283
+			catch (\Exception $e) {; } // Don't notify the user as appropriate services can be added automatically
284 284
 		}
285 285
 
286 286
 		return $errors;
@@ -298,36 +298,36 @@  discard block
 block discarded – undo
298 298
 	 * @param array $attributeValues Associative list of attribute IDs as keys and their codes as values
299 299
 	 * @return array List of items implementing \Aimeos\MShop\Order\Item\Product\Attribute\Iface
300 300
 	 */
301
-	protected function createOrderProductAttributes( \Aimeos\MShop\Price\Item\Iface $price, $prodid, $quantity,
302
-			array $attributeIds, $type, array $attributeValues = [] )
301
+	protected function createOrderProductAttributes(\Aimeos\MShop\Price\Item\Iface $price, $prodid, $quantity,
302
+			array $attributeIds, $type, array $attributeValues = [])
303 303
 	{
304
-		if( empty( $attributeIds ) ) {
304
+		if (empty($attributeIds)) {
305 305
 			return [];
306 306
 		}
307 307
 
308
-		$attrTypeId = $this->getProductListTypeItem( 'attribute', $type )->getId();
309
-		$this->checkReferences( $prodid, 'attribute', $attrTypeId, $attributeIds );
308
+		$attrTypeId = $this->getProductListTypeItem('attribute', $type)->getId();
309
+		$this->checkReferences($prodid, 'attribute', $attrTypeId, $attributeIds);
310 310
 
311 311
 		$list = [];
312 312
 		$context = $this->getContext();
313 313
 
314
-		$priceManager = \Aimeos\MShop\Factory::createManager( $context, 'price' );
315
-		$orderProductAttributeManager = \Aimeos\MShop\Factory::createManager( $context, 'order/base/product/attribute' );
314
+		$priceManager = \Aimeos\MShop\Factory::createManager($context, 'price');
315
+		$orderProductAttributeManager = \Aimeos\MShop\Factory::createManager($context, 'order/base/product/attribute');
316 316
 
317
-		foreach( $this->getAttributes( $attributeIds ) as $id => $attrItem )
317
+		foreach ($this->getAttributes($attributeIds) as $id => $attrItem)
318 318
 		{
319
-			$prices = $attrItem->getRefItems( 'price', 'default', 'default' );
319
+			$prices = $attrItem->getRefItems('price', 'default', 'default');
320 320
 
321
-			if( !empty( $prices ) ) {
322
-				$price->addItem( $priceManager->getLowestPrice( $prices, $quantity ) );
321
+			if (!empty($prices)) {
322
+				$price->addItem($priceManager->getLowestPrice($prices, $quantity));
323 323
 			}
324 324
 
325 325
 			$item = $orderProductAttributeManager->createItem();
326
-			$item->copyFrom( $attrItem );
327
-			$item->setType( $type );
326
+			$item->copyFrom($attrItem);
327
+			$item->setType($type);
328 328
 
329
-			if( isset( $attributeValues[$id] ) ) {
330
-				$item->setValue( $attributeValues[$id] );
329
+			if (isset($attributeValues[$id])) {
330
+				$item->setValue($attributeValues[$id]);
331 331
 			}
332 332
 
333 333
 			$list[] = $item;
@@ -345,31 +345,31 @@  discard block
 block discarded – undo
345 345
 	 * @return array List of items implementing \Aimeos\MShop\Attribute\Item\Iface
346 346
 	 * @throws \Aimeos\Controller\Frontend\Basket\Exception If the actual attribute number doesn't match the expected one
347 347
 	 */
348
-	protected function getAttributes( array $attributeIds, array $domains = array( 'price', 'text' ) )
348
+	protected function getAttributes(array $attributeIds, array $domains = array('price', 'text'))
349 349
 	{
350
-		if( empty( $attributeIds ) ) {
350
+		if (empty($attributeIds)) {
351 351
 			return [];
352 352
 		}
353 353
 
354
-		$attributeManager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'attribute' );
354
+		$attributeManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'attribute');
355 355
 
356
-		$search = $attributeManager->createSearch( true );
356
+		$search = $attributeManager->createSearch(true);
357 357
 		$expr = array(
358
-				$search->compare( '==', 'attribute.id', $attributeIds ),
358
+				$search->compare('==', 'attribute.id', $attributeIds),
359 359
 				$search->getConditions(),
360 360
 		);
361
-		$search->setConditions( $search->combine( '&&', $expr ) );
362
-		$search->setSlice( 0, 0x7fffffff );
361
+		$search->setConditions($search->combine('&&', $expr));
362
+		$search->setSlice(0, 0x7fffffff);
363 363
 
364
-		$attrItems = $attributeManager->searchItems( $search, $domains );
364
+		$attrItems = $attributeManager->searchItems($search, $domains);
365 365
 
366
-		if( count( $attrItems ) !== count( $attributeIds ) )
366
+		if (count($attrItems) !== count($attributeIds))
367 367
 		{
368
-			$expected = implode( ',', $attributeIds );
369
-			$actual = implode( ',', array_keys( $attrItems ) );
370
-			$msg = sprintf( 'Available attribute IDs "%1$s" do not match the given attribute IDs "%2$s"', $actual, $expected );
368
+			$expected = implode(',', $attributeIds);
369
+			$actual = implode(',', array_keys($attrItems));
370
+			$msg = sprintf('Available attribute IDs "%1$s" do not match the given attribute IDs "%2$s"', $actual, $expected);
371 371
 
372
-			throw new \Aimeos\Controller\Frontend\Basket\Exception( $msg );
372
+			throw new \Aimeos\Controller\Frontend\Basket\Exception($msg);
373 373
 		}
374 374
 
375 375
 		return $attrItems;
@@ -382,31 +382,31 @@  discard block
 block discarded – undo
382 382
 	 * @param \Aimeos\MShop\Order\Item\Base\Product\Attribute\Item[] $orderAttributes List of order product attribute items
383 383
 	 * @return \Aimeos\MShop\Attribute\Item\Iface[] Associative list of attribute IDs as key and attribute items as values
384 384
 	 */
385
-	protected function getAttributeItems( array $orderAttributes )
385
+	protected function getAttributeItems(array $orderAttributes)
386 386
 	{
387
-		if( empty( $orderAttributes ) ) {
387
+		if (empty($orderAttributes)) {
388 388
 			return [];
389 389
 		}
390 390
 
391
-		$attributeManager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'attribute' );
392
-		$search = $attributeManager->createSearch( true );
391
+		$attributeManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'attribute');
392
+		$search = $attributeManager->createSearch(true);
393 393
 		$expr = [];
394 394
 
395
-		foreach( $orderAttributes as $item )
395
+		foreach ($orderAttributes as $item)
396 396
 		{
397 397
 			$tmp = array(
398
-				$search->compare( '==', 'attribute.domain', 'product' ),
399
-				$search->compare( '==', 'attribute.code', $item->getValue() ),
400
-				$search->compare( '==', 'attribute.type.domain', 'product' ),
401
-				$search->compare( '==', 'attribute.type.code', $item->getCode() ),
402
-				$search->compare( '>', 'attribute.type.status', 0 ),
398
+				$search->compare('==', 'attribute.domain', 'product'),
399
+				$search->compare('==', 'attribute.code', $item->getValue()),
400
+				$search->compare('==', 'attribute.type.domain', 'product'),
401
+				$search->compare('==', 'attribute.type.code', $item->getCode()),
402
+				$search->compare('>', 'attribute.type.status', 0),
403 403
 				$search->getConditions(),
404 404
 			);
405
-			$expr[] = $search->combine( '&&', $tmp );
405
+			$expr[] = $search->combine('&&', $tmp);
406 406
 		}
407 407
 
408
-		$search->setConditions( $search->combine( '||', $expr ) );
409
-		return $attributeManager->searchItems( $search, array( 'price' ) );
408
+		$search->setConditions($search->combine('||', $expr));
409
+		return $attributeManager->searchItems($search, array('price'));
410 410
 	}
411 411
 
412 412
 
@@ -421,23 +421,23 @@  discard block
 block discarded – undo
421 421
 	 * @throws \Aimeos\Controller\Frontend\Basket\Exception
422 422
 	 * @deprecated Use getItem() or findItem() instead
423 423
 	 */
424
-	protected function getDomainItem( $domain, $key, $value, array $ref )
424
+	protected function getDomainItem($domain, $key, $value, array $ref)
425 425
 	{
426
-		$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), $domain );
426
+		$manager = \Aimeos\MShop\Factory::createManager($this->getContext(), $domain);
427 427
 
428
-		$search = $manager->createSearch( true );
428
+		$search = $manager->createSearch(true);
429 429
 		$expr = array(
430
-			$search->compare( '==', $key, $value ),
430
+			$search->compare('==', $key, $value),
431 431
 			$search->getConditions(),
432 432
 		);
433
-		$search->setConditions( $search->combine( '&&', $expr ) );
433
+		$search->setConditions($search->combine('&&', $expr));
434 434
 
435
-		$result = $manager->searchItems( $search, $ref );
435
+		$result = $manager->searchItems($search, $ref);
436 436
 
437
-		if( ( $item = reset( $result ) ) === false )
437
+		if (($item = reset($result)) === false)
438 438
 		{
439
-			$msg = sprintf( 'No item for "%1$s" (%2$s) found', $value, $key );
440
-			throw new \Aimeos\Controller\Frontend\Basket\Exception( $msg );
439
+			$msg = sprintf('No item for "%1$s" (%2$s) found', $value, $key);
440
+			throw new \Aimeos\Controller\Frontend\Basket\Exception($msg);
441 441
 		}
442 442
 
443 443
 		return $item;
@@ -451,26 +451,26 @@  discard block
 block discarded – undo
451 451
 	 * @param string $code Code of the list type
452 452
 	 * @return \Aimeos\MShop\Common\Item\Type\Iface List type item
453 453
 	 */
454
-	protected function getProductListTypeItem( $domain, $code )
454
+	protected function getProductListTypeItem($domain, $code)
455 455
 	{
456
-		if( !isset( $this->listTypeAttributes[$domain][$code] ) )
456
+		if (!isset($this->listTypeAttributes[$domain][$code]))
457 457
 		{
458
-			$listTypeManager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product/lists/type' );
458
+			$listTypeManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product/lists/type');
459 459
 
460
-			$listTypeSearch = $listTypeManager->createSearch( true );
460
+			$listTypeSearch = $listTypeManager->createSearch(true);
461 461
 			$expr = array(
462
-				$listTypeSearch->compare( '==', 'product.lists.type.domain', $domain ),
463
-				$listTypeSearch->compare( '==', 'product.lists.type.code', $code ),
462
+				$listTypeSearch->compare('==', 'product.lists.type.domain', $domain),
463
+				$listTypeSearch->compare('==', 'product.lists.type.code', $code),
464 464
 				$listTypeSearch->getConditions(),
465 465
 			);
466
-			$listTypeSearch->setConditions( $listTypeSearch->combine( '&&', $expr ) );
466
+			$listTypeSearch->setConditions($listTypeSearch->combine('&&', $expr));
467 467
 
468
-			$listTypeItems = $listTypeManager->searchItems( $listTypeSearch );
468
+			$listTypeItems = $listTypeManager->searchItems($listTypeSearch);
469 469
 
470
-			if( ( $listTypeItem = reset( $listTypeItems ) ) === false )
470
+			if (($listTypeItem = reset($listTypeItems)) === false)
471 471
 			{
472
-				$msg = sprintf( 'List type for domain "%1$s" and code "%2$s" not found', $domain, $code );
473
-				throw new \Aimeos\Controller\Frontend\Basket\Exception( $msg );
472
+				$msg = sprintf('List type for domain "%1$s" and code "%2$s" not found', $domain, $code);
473
+				throw new \Aimeos\Controller\Frontend\Basket\Exception($msg);
474 474
 			}
475 475
 
476 476
 			$this->listTypeAttributes[$domain][$code] = $listTypeItem;
@@ -488,43 +488,43 @@  discard block
 block discarded – undo
488 488
 	 * @param array $domains Names of the domain items that should be fetched too
489 489
 	 * @return array List of products matching the given attributes
490 490
 	 */
491
-	protected function getProductVariants( \Aimeos\MShop\Product\Item\Iface $productItem, array $variantAttributeIds,
492
-			array $domains = array( 'attribute', 'media', 'price', 'text' ) )
491
+	protected function getProductVariants(\Aimeos\MShop\Product\Item\Iface $productItem, array $variantAttributeIds,
492
+			array $domains = array('attribute', 'media', 'price', 'text'))
493 493
 	{
494 494
 		$subProductIds = [];
495
-		foreach( $productItem->getRefItems( 'product', 'default', 'default' ) as $item ) {
495
+		foreach ($productItem->getRefItems('product', 'default', 'default') as $item) {
496 496
 			$subProductIds[] = $item->getId();
497 497
 		}
498 498
 
499
-		if( count( $subProductIds ) === 0 ) {
499
+		if (count($subProductIds) === 0) {
500 500
 			return [];
501 501
 		}
502 502
 
503
-		$productManager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product' );
504
-		$search = $productManager->createSearch( true );
503
+		$productManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product');
504
+		$search = $productManager->createSearch(true);
505 505
 
506 506
 		$expr = array(
507
-			$search->compare( '==', 'product.id', $subProductIds ),
507
+			$search->compare('==', 'product.id', $subProductIds),
508 508
 			$search->getConditions(),
509 509
 		);
510 510
 
511
-		if( count( $variantAttributeIds ) > 0 )
511
+		if (count($variantAttributeIds) > 0)
512 512
 		{
513
-			foreach( $variantAttributeIds as $key => $id ) {
513
+			foreach ($variantAttributeIds as $key => $id) {
514 514
 				$variantAttributeIds[$key] = (string) $id;
515 515
 			}
516 516
 
517
-			$listTypeItem = $this->getProductListTypeItem( 'attribute', 'variant' );
517
+			$listTypeItem = $this->getProductListTypeItem('attribute', 'variant');
518 518
 
519
-			$param = array( 'attribute', $listTypeItem->getId(), $variantAttributeIds );
520
-			$cmpfunc = $search->createFunction( 'product.contains', $param );
519
+			$param = array('attribute', $listTypeItem->getId(), $variantAttributeIds);
520
+			$cmpfunc = $search->createFunction('product.contains', $param);
521 521
 
522
-			$expr[] = $search->compare( '==', $cmpfunc, count( $variantAttributeIds ) );
522
+			$expr[] = $search->compare('==', $cmpfunc, count($variantAttributeIds));
523 523
 		}
524 524
 
525
-		$search->setConditions( $search->combine( '&&', $expr ) );
525
+		$search->setConditions($search->combine('&&', $expr));
526 526
 
527
-		return $productManager->searchItems( $search, $domains );
527
+		return $productManager->searchItems($search, $domains);
528 528
 	}
529 529
 
530 530
 
@@ -536,9 +536,9 @@  discard block
 block discarded – undo
536 536
 	 * @param mixed $default Default value if no value is available for the given name
537 537
 	 * @return mixed Value from the array or default value
538 538
 	 */
539
-	protected function getValue( array $values, $name, $default = null )
539
+	protected function getValue(array $values, $name, $default = null)
540 540
 	{
541
-		if( isset( $values[$name] ) ) {
541
+		if (isset($values[$name])) {
542 542
 			return $values[$name];
543 543
 		}
544 544
 
Please login to merge, or discard this patch.