@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | |
16 | 16 | protected function setUp() |
17 | 17 | { |
18 | - $this->object = new \Aimeos\Controller\Frontend\Exception( 'msg', 1, null, array( 'key' => 'value' ) ); |
|
18 | + $this->object = new \Aimeos\Controller\Frontend\Exception('msg', 1, null, array('key' => 'value')); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | |
@@ -26,18 +26,18 @@ discard block |
||
26 | 26 | |
27 | 27 | public function testGetMessage() |
28 | 28 | { |
29 | - $this->assertEquals( 'msg', $this->object->getMessage() ); |
|
29 | + $this->assertEquals('msg', $this->object->getMessage()); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | |
33 | 33 | public function testGetCode() |
34 | 34 | { |
35 | - $this->assertEquals( 1, $this->object->getCode() ); |
|
35 | + $this->assertEquals(1, $this->object->getCode()); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | |
39 | 39 | public function testGetErrorList() |
40 | 40 | { |
41 | - $this->assertEquals( array( 'key' => 'value' ), $this->object->getErrorList() ); |
|
41 | + $this->assertEquals(array('key' => 'value'), $this->object->getErrorList()); |
|
42 | 42 | } |
43 | 43 | } |
@@ -14,31 +14,31 @@ |
||
14 | 14 | { |
15 | 15 | $target = '\\Aimeos\\Controller\\Frontend\\Basket\\Iface'; |
16 | 16 | |
17 | - $controller = \Aimeos\Controller\Frontend\Basket\Factory::createController( \TestHelperFrontend::getContext() ); |
|
18 | - $this->assertInstanceOf( $target, $controller ); |
|
17 | + $controller = \Aimeos\Controller\Frontend\Basket\Factory::createController(\TestHelperFrontend::getContext()); |
|
18 | + $this->assertInstanceOf($target, $controller); |
|
19 | 19 | |
20 | - $controller = \Aimeos\Controller\Frontend\Basket\Factory::createController( \TestHelperFrontend::getContext(), 'Standard' ); |
|
21 | - $this->assertInstanceOf( $target, $controller ); |
|
20 | + $controller = \Aimeos\Controller\Frontend\Basket\Factory::createController(\TestHelperFrontend::getContext(), 'Standard'); |
|
21 | + $this->assertInstanceOf($target, $controller); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | |
25 | 25 | public function testCreateControllerInvalidImplementation() |
26 | 26 | { |
27 | - $this->setExpectedException( '\\Aimeos\\Controller\\Frontend\\Exception' ); |
|
28 | - \Aimeos\Controller\Frontend\Basket\Factory::createController( \TestHelperFrontend::getContext(), 'Invalid' ); |
|
27 | + $this->setExpectedException('\\Aimeos\\Controller\\Frontend\\Exception'); |
|
28 | + \Aimeos\Controller\Frontend\Basket\Factory::createController(\TestHelperFrontend::getContext(), 'Invalid'); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | |
32 | 32 | public function testCreateControllerInvalidName() |
33 | 33 | { |
34 | - $this->setExpectedException( '\\Aimeos\\Controller\\Frontend\\Exception' ); |
|
35 | - \Aimeos\Controller\Frontend\Basket\Factory::createController( \TestHelperFrontend::getContext(), '%^' ); |
|
34 | + $this->setExpectedException('\\Aimeos\\Controller\\Frontend\\Exception'); |
|
35 | + \Aimeos\Controller\Frontend\Basket\Factory::createController(\TestHelperFrontend::getContext(), '%^'); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | |
39 | 39 | public function testCreateControllerNotExisting() |
40 | 40 | { |
41 | - $this->setExpectedException( '\\Aimeos\\Controller\\Frontend\\Exception' ); |
|
42 | - \Aimeos\Controller\Frontend\Basket\Factory::createController( \TestHelperFrontend::getContext(), 'notexist' ); |
|
41 | + $this->setExpectedException('\\Aimeos\\Controller\\Frontend\\Exception'); |
|
42 | + \Aimeos\Controller\Frontend\Basket\Factory::createController(\TestHelperFrontend::getContext(), 'notexist'); |
|
43 | 43 | } |
44 | 44 | } |
@@ -14,31 +14,31 @@ |
||
14 | 14 | { |
15 | 15 | $target = '\\Aimeos\\Controller\\Frontend\\Catalog\\Iface'; |
16 | 16 | |
17 | - $controller = \Aimeos\Controller\Frontend\Catalog\Factory::createController( \TestHelperFrontend::getContext() ); |
|
18 | - $this->assertInstanceOf( $target, $controller ); |
|
17 | + $controller = \Aimeos\Controller\Frontend\Catalog\Factory::createController(\TestHelperFrontend::getContext()); |
|
18 | + $this->assertInstanceOf($target, $controller); |
|
19 | 19 | |
20 | - $controller = \Aimeos\Controller\Frontend\Catalog\Factory::createController( \TestHelperFrontend::getContext(), 'Standard' ); |
|
21 | - $this->assertInstanceOf( $target, $controller ); |
|
20 | + $controller = \Aimeos\Controller\Frontend\Catalog\Factory::createController(\TestHelperFrontend::getContext(), 'Standard'); |
|
21 | + $this->assertInstanceOf($target, $controller); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | |
25 | 25 | public function testCreateControllerInvalidImplementation() |
26 | 26 | { |
27 | - $this->setExpectedException( '\\Aimeos\\Controller\\Frontend\\Exception' ); |
|
28 | - \Aimeos\Controller\Frontend\Catalog\Factory::createController( \TestHelperFrontend::getContext(), 'Invalid' ); |
|
27 | + $this->setExpectedException('\\Aimeos\\Controller\\Frontend\\Exception'); |
|
28 | + \Aimeos\Controller\Frontend\Catalog\Factory::createController(\TestHelperFrontend::getContext(), 'Invalid'); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | |
32 | 32 | public function testCreateControllerInvalidName() |
33 | 33 | { |
34 | - $this->setExpectedException( '\\Aimeos\\Controller\\Frontend\\Exception' ); |
|
35 | - \Aimeos\Controller\Frontend\Catalog\Factory::createController( \TestHelperFrontend::getContext(), '%^' ); |
|
34 | + $this->setExpectedException('\\Aimeos\\Controller\\Frontend\\Exception'); |
|
35 | + \Aimeos\Controller\Frontend\Catalog\Factory::createController(\TestHelperFrontend::getContext(), '%^'); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | |
39 | 39 | public function testCreateControllerNotExisting() |
40 | 40 | { |
41 | - $this->setExpectedException( '\\Aimeos\\Controller\\Frontend\\Exception' ); |
|
42 | - \Aimeos\Controller\Frontend\Catalog\Factory::createController( \TestHelperFrontend::getContext(), 'notexist' ); |
|
41 | + $this->setExpectedException('\\Aimeos\\Controller\\Frontend\\Exception'); |
|
42 | + \Aimeos\Controller\Frontend\Catalog\Factory::createController(\TestHelperFrontend::getContext(), 'notexist'); |
|
43 | 43 | } |
44 | 44 | } |
@@ -14,31 +14,31 @@ |
||
14 | 14 | { |
15 | 15 | $target = '\\Aimeos\\Controller\\Frontend\\Order\\Iface'; |
16 | 16 | |
17 | - $controller = \Aimeos\Controller\Frontend\Order\Factory::createController( \TestHelperFrontend::getContext() ); |
|
18 | - $this->assertInstanceOf( $target, $controller ); |
|
17 | + $controller = \Aimeos\Controller\Frontend\Order\Factory::createController(\TestHelperFrontend::getContext()); |
|
18 | + $this->assertInstanceOf($target, $controller); |
|
19 | 19 | |
20 | - $controller = \Aimeos\Controller\Frontend\Order\Factory::createController( \TestHelperFrontend::getContext(), 'Standard' ); |
|
21 | - $this->assertInstanceOf( $target, $controller ); |
|
20 | + $controller = \Aimeos\Controller\Frontend\Order\Factory::createController(\TestHelperFrontend::getContext(), 'Standard'); |
|
21 | + $this->assertInstanceOf($target, $controller); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | |
25 | 25 | public function testCreateControllerInvalidImplementation() |
26 | 26 | { |
27 | - $this->setExpectedException( '\\Aimeos\\Controller\\Frontend\\Exception' ); |
|
28 | - \Aimeos\Controller\Frontend\Order\Factory::createController( \TestHelperFrontend::getContext(), 'Invalid' ); |
|
27 | + $this->setExpectedException('\\Aimeos\\Controller\\Frontend\\Exception'); |
|
28 | + \Aimeos\Controller\Frontend\Order\Factory::createController(\TestHelperFrontend::getContext(), 'Invalid'); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | |
32 | 32 | public function testCreateControllerInvalidName() |
33 | 33 | { |
34 | - $this->setExpectedException( '\\Aimeos\\Controller\\Frontend\\Exception' ); |
|
35 | - \Aimeos\Controller\Frontend\Order\Factory::createController( \TestHelperFrontend::getContext(), '%^' ); |
|
34 | + $this->setExpectedException('\\Aimeos\\Controller\\Frontend\\Exception'); |
|
35 | + \Aimeos\Controller\Frontend\Order\Factory::createController(\TestHelperFrontend::getContext(), '%^'); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | |
39 | 39 | public function testCreateControllerNotExisting() |
40 | 40 | { |
41 | - $this->setExpectedException( '\\Aimeos\\Controller\\Frontend\\Exception' ); |
|
42 | - \Aimeos\Controller\Frontend\Order\Factory::createController( \TestHelperFrontend::getContext(), 'notexist' ); |
|
41 | + $this->setExpectedException('\\Aimeos\\Controller\\Frontend\\Exception'); |
|
42 | + \Aimeos\Controller\Frontend\Order\Factory::createController(\TestHelperFrontend::getContext(), 'notexist'); |
|
43 | 43 | } |
44 | 44 | } |
@@ -11,22 +11,22 @@ |
||
11 | 11 | * Set error reporting to maximum |
12 | 12 | */ |
13 | 13 | error_reporting( -1 ); |
14 | -ini_set( 'display_errors', '1' ); |
|
14 | +ini_set('display_errors', '1'); |
|
15 | 15 | |
16 | -date_default_timezone_set( 'UTC' ); |
|
16 | +date_default_timezone_set('UTC'); |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * Set locale settings to reasonable defaults |
20 | 20 | */ |
21 | -setlocale( LC_ALL, 'en_US.UTF-8' ); |
|
22 | -setlocale( LC_NUMERIC, 'POSIX' ); |
|
23 | -setlocale( LC_CTYPE, 'en_US.UTF-8' ); |
|
24 | -setlocale( LC_TIME, 'POSIX' ); |
|
21 | +setlocale(LC_ALL, 'en_US.UTF-8'); |
|
22 | +setlocale(LC_NUMERIC, 'POSIX'); |
|
23 | +setlocale(LC_CTYPE, 'en_US.UTF-8'); |
|
24 | +setlocale(LC_TIME, 'POSIX'); |
|
25 | 25 | |
26 | 26 | /* |
27 | 27 | * Set include path for tests |
28 | 28 | */ |
29 | -define( 'PATH_TESTS', __DIR__ ); |
|
29 | +define('PATH_TESTS', __DIR__); |
|
30 | 30 | |
31 | 31 | require_once 'TestHelperFrontend.php'; |
32 | 32 | \TestHelperFrontend::bootstrap(); |
@@ -27,5 +27,5 @@ |
||
27 | 27 | * @param string|null $name Name of the controller implementation (Default if null) |
28 | 28 | * @return \Aimeos\Controller\Frontend\Common\Iface Controller object |
29 | 29 | */ |
30 | - public static function createController( \Aimeos\MShop\Context\Item\Iface $context, $name = null ); |
|
30 | + public static function createController(\Aimeos\MShop\Context\Item\Iface $context, $name = null); |
|
31 | 31 | } |
@@ -160,8 +160,7 @@ discard block |
||
160 | 160 | { |
161 | 161 | $this->setAddress( $type, $item->toArray() ); |
162 | 162 | $basket->deleteAddress( $type ); |
163 | - } |
|
164 | - catch( \Exception $e ) |
|
163 | + } catch( \Exception $e ) |
|
165 | 164 | { |
166 | 165 | $logger = $this->getContext()->getLogger(); |
167 | 166 | $str = 'Error migrating address with type "%1$s" in basket to locale "%2$s": %3$s'; |
@@ -190,8 +189,7 @@ discard block |
||
190 | 189 | { |
191 | 190 | $this->addCoupon( $code ); |
192 | 191 | $basket->deleteCoupon( $code, true ); |
193 | - } |
|
194 | - catch( \Exception $e ) |
|
192 | + } catch( \Exception $e ) |
|
195 | 193 | { |
196 | 194 | $logger = $this->getContext()->getLogger(); |
197 | 195 | $str = 'Error migrating coupon with code "%1$s" in basket to locale "%2$s": %3$s'; |
@@ -240,8 +238,7 @@ discard block |
||
240 | 238 | ); |
241 | 239 | |
242 | 240 | $basket->deleteProduct( $pos ); |
243 | - } |
|
244 | - catch( \Exception $e ) |
|
241 | + } catch( \Exception $e ) |
|
245 | 242 | { |
246 | 243 | $code = $product->getProductCode(); |
247 | 244 | $logger = $this->getContext()->getLogger(); |
@@ -276,8 +273,7 @@ discard block |
||
276 | 273 | |
277 | 274 | $this->setService( $type, $item->getServiceId(), $attributes ); |
278 | 275 | $basket->deleteService( $type ); |
279 | - } |
|
280 | - catch( \Exception $e ) { ; } // Don't notify the user as appropriate services can be added automatically |
|
276 | + } catch( \Exception $e ) { ; } // Don't notify the user as appropriate services can be added automatically |
|
281 | 277 | } |
282 | 278 | |
283 | 279 | return $errors; |
@@ -31,46 +31,46 @@ discard block |
||
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 | 44 | |
45 | - $priceManager = \Aimeos\MShop\Factory::createManager( $context, 'price' ); |
|
46 | - $price = $priceManager->getLowestPrice( $prices, $quantity ); |
|
45 | + $priceManager = \Aimeos\MShop\Factory::createManager($context, 'price'); |
|
46 | + $price = $priceManager->getLowestPrice($prices, $quantity); |
|
47 | 47 | |
48 | 48 | // customers can pay what they would like to pay |
49 | - if( ( $attr = $product->getAttributeItem( 'price', 'custom' ) ) !== null ) |
|
49 | + if (($attr = $product->getAttributeItem('price', 'custom')) !== null) |
|
50 | 50 | { |
51 | 51 | $amount = $attr->getValue(); |
52 | 52 | |
53 | - if( preg_match( '/^[0-9]*(\.[0-9]+)?$/', $amount ) !== 1 || ((double) $amount) < 0.01 ) { |
|
54 | - throw new \Aimeos\Controller\Frontend\Basket\Exception( sprintf( 'Invalid price value "%1$s"', $amount ) ); |
|
53 | + if (preg_match('/^[0-9]*(\.[0-9]+)?$/', $amount) !== 1 || ((double) $amount) < 0.01) { |
|
54 | + throw new \Aimeos\Controller\Frontend\Basket\Exception(sprintf('Invalid price value "%1$s"', $amount)); |
|
55 | 55 | } |
56 | 56 | |
57 | - $price->setValue( $amount ); |
|
57 | + $price->setValue($amount); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | // add prices of (optional) attributes |
61 | - foreach( $this->getAttributeItems( $product->getAttributes() ) as $attrItem ) |
|
61 | + foreach ($this->getAttributeItems($product->getAttributes()) as $attrItem) |
|
62 | 62 | { |
63 | - $prices = $attrItem->getRefItems( 'price', 'default' ); |
|
63 | + $prices = $attrItem->getRefItems('price', 'default'); |
|
64 | 64 | |
65 | - if( count( $prices ) > 0 ) |
|
65 | + if (count($prices) > 0) |
|
66 | 66 | { |
67 | - $attrPrice = $priceManager->getLowestPrice( $prices, $quantity ); |
|
68 | - $price->addItem( $attrPrice ); |
|
67 | + $attrPrice = $priceManager->getLowestPrice($prices, $quantity); |
|
68 | + $price->addItem($attrPrice); |
|
69 | 69 | } |
70 | 70 | } |
71 | 71 | |
72 | 72 | // remove product rebate of original price in favor to rebates granted for the order |
73 | - $price->setRebate( '0.00' ); |
|
73 | + $price->setRebate('0.00'); |
|
74 | 74 | |
75 | 75 | return $price; |
76 | 76 | } |
@@ -84,42 +84,42 @@ discard block |
||
84 | 84 | * @param array $refMap Associative list of list type codes as keys and lists of reference IDs as values |
85 | 85 | * @throws \Aimeos\Controller\Frontend\Basket\Exception If one or more of the IDs are not associated |
86 | 86 | */ |
87 | - protected function checkListRef( $prodId, $domain, array $refMap ) |
|
87 | + protected function checkListRef($prodId, $domain, array $refMap) |
|
88 | 88 | { |
89 | - if( empty( $refMap ) ) { |
|
89 | + if (empty($refMap)) { |
|
90 | 90 | return; |
91 | 91 | } |
92 | 92 | |
93 | - $productManager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product' ); |
|
94 | - $search = $productManager->createSearch( true ); |
|
93 | + $productManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product'); |
|
94 | + $search = $productManager->createSearch(true); |
|
95 | 95 | |
96 | 96 | $expr = array( |
97 | - $search->compare( '==', 'product.id', $prodId ), |
|
97 | + $search->compare('==', 'product.id', $prodId), |
|
98 | 98 | $search->getConditions(), |
99 | 99 | ); |
100 | 100 | |
101 | - foreach( $refMap as $listType => $refIds ) |
|
101 | + foreach ($refMap as $listType => $refIds) |
|
102 | 102 | { |
103 | - if( empty( $refIds ) ) { |
|
103 | + if (empty($refIds)) { |
|
104 | 104 | continue; |
105 | 105 | } |
106 | 106 | |
107 | - foreach( $refIds as $key => $refId ) { |
|
107 | + foreach ($refIds as $key => $refId) { |
|
108 | 108 | $refIds[$key] = (string) $refId; |
109 | 109 | } |
110 | 110 | |
111 | - $param = array( $domain, $this->getProductListTypeItem( $domain, $listType )->getId(), $refIds ); |
|
112 | - $cmpfunc = $search->createFunction( 'product.contains', $param ); |
|
111 | + $param = array($domain, $this->getProductListTypeItem($domain, $listType)->getId(), $refIds); |
|
112 | + $cmpfunc = $search->createFunction('product.contains', $param); |
|
113 | 113 | |
114 | - $expr[] = $search->compare( '==', $cmpfunc, count( $refIds ) ); |
|
114 | + $expr[] = $search->compare('==', $cmpfunc, count($refIds)); |
|
115 | 115 | } |
116 | 116 | |
117 | - $search->setConditions( $search->combine( '&&', $expr ) ); |
|
117 | + $search->setConditions($search->combine('&&', $expr)); |
|
118 | 118 | |
119 | - if( count( $productManager->searchItems( $search, [] ) ) === 0 ) |
|
119 | + if (count($productManager->searchItems($search, [])) === 0) |
|
120 | 120 | { |
121 | - $msg = sprintf( 'Invalid "%1$s" references for product with ID %2$s', $domain, json_encode( $prodId ) ); |
|
122 | - throw new \Aimeos\Controller\Frontend\Basket\Exception( $msg ); |
|
121 | + $msg = sprintf('Invalid "%1$s" references for product with ID %2$s', $domain, json_encode($prodId)); |
|
122 | + throw new \Aimeos\Controller\Frontend\Basket\Exception($msg); |
|
123 | 123 | } |
124 | 124 | } |
125 | 125 | |
@@ -134,34 +134,34 @@ discard block |
||
134 | 134 | * @throws \Aimeos\Controller\Frontend\Basket\Exception If one or more of the IDs are not associated |
135 | 135 | * @deprecated Use checkListRef() instead |
136 | 136 | */ |
137 | - protected function checkReferences( $prodId, $domain, $listTypeId, array $refIds ) |
|
137 | + protected function checkReferences($prodId, $domain, $listTypeId, array $refIds) |
|
138 | 138 | { |
139 | - $productManager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product' ); |
|
140 | - $search = $productManager->createSearch( true ); |
|
139 | + $productManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product'); |
|
140 | + $search = $productManager->createSearch(true); |
|
141 | 141 | |
142 | 142 | $expr = array( |
143 | - $search->compare( '==', 'product.id', $prodId ), |
|
143 | + $search->compare('==', 'product.id', $prodId), |
|
144 | 144 | $search->getConditions(), |
145 | 145 | ); |
146 | 146 | |
147 | - if( count( $refIds ) > 0 ) |
|
147 | + if (count($refIds) > 0) |
|
148 | 148 | { |
149 | - foreach( $refIds as $key => $refId ) { |
|
149 | + foreach ($refIds as $key => $refId) { |
|
150 | 150 | $refIds[$key] = (string) $refId; |
151 | 151 | } |
152 | 152 | |
153 | - $param = array( $domain, $listTypeId, $refIds ); |
|
154 | - $cmpfunc = $search->createFunction( 'product.contains', $param ); |
|
153 | + $param = array($domain, $listTypeId, $refIds); |
|
154 | + $cmpfunc = $search->createFunction('product.contains', $param); |
|
155 | 155 | |
156 | - $expr[] = $search->compare( '==', $cmpfunc, count( $refIds ) ); |
|
156 | + $expr[] = $search->compare('==', $cmpfunc, count($refIds)); |
|
157 | 157 | } |
158 | 158 | |
159 | - $search->setConditions( $search->combine( '&&', $expr ) ); |
|
159 | + $search->setConditions($search->combine('&&', $expr)); |
|
160 | 160 | |
161 | - if( count( $productManager->searchItems( $search, [] ) ) === 0 ) |
|
161 | + if (count($productManager->searchItems($search, [])) === 0) |
|
162 | 162 | { |
163 | - $msg = sprintf( 'Invalid "%1$s" references for product with ID %2$s', $domain, json_encode( $prodId ) ); |
|
164 | - throw new \Aimeos\Controller\Frontend\Basket\Exception( $msg ); |
|
163 | + $msg = sprintf('Invalid "%1$s" references for product with ID %2$s', $domain, json_encode($prodId)); |
|
164 | + throw new \Aimeos\Controller\Frontend\Basket\Exception($msg); |
|
165 | 165 | } |
166 | 166 | } |
167 | 167 | |
@@ -171,41 +171,41 @@ discard block |
||
171 | 171 | * |
172 | 172 | * @param string $type Basket type |
173 | 173 | */ |
174 | - protected function checkLocale( $type ) |
|
174 | + protected function checkLocale($type) |
|
175 | 175 | { |
176 | 176 | $errors = []; |
177 | 177 | $context = $this->getContext(); |
178 | 178 | $session = $context->getSession(); |
179 | 179 | $locale = $this->get()->getLocale(); |
180 | 180 | |
181 | - $localeStr = $session->get( 'aimeos/basket/locale' ); |
|
181 | + $localeStr = $session->get('aimeos/basket/locale'); |
|
182 | 182 | $localeKey = $locale->getSite()->getCode() . '|' . $locale->getLanguageId() . '|' . $locale->getCurrencyId(); |
183 | 183 | |
184 | - if( $localeStr !== null && $localeStr !== $localeKey ) |
|
184 | + if ($localeStr !== null && $localeStr !== $localeKey) |
|
185 | 185 | { |
186 | - $locParts = explode( '|', $localeStr ); |
|
187 | - $locSite = ( isset( $locParts[0] ) ? $locParts[0] : '' ); |
|
188 | - $locLanguage = ( isset( $locParts[1] ) ? $locParts[1] : '' ); |
|
189 | - $locCurrency = ( isset( $locParts[2] ) ? $locParts[2] : '' ); |
|
186 | + $locParts = explode('|', $localeStr); |
|
187 | + $locSite = (isset($locParts[0]) ? $locParts[0] : ''); |
|
188 | + $locLanguage = (isset($locParts[1]) ? $locParts[1] : ''); |
|
189 | + $locCurrency = (isset($locParts[2]) ? $locParts[2] : ''); |
|
190 | 190 | |
191 | - $localeManager = \Aimeos\MShop\Factory::createManager( $context, 'locale' ); |
|
192 | - $locale = $localeManager->bootstrap( $locSite, $locLanguage, $locCurrency, false ); |
|
191 | + $localeManager = \Aimeos\MShop\Factory::createManager($context, 'locale'); |
|
192 | + $locale = $localeManager->bootstrap($locSite, $locLanguage, $locCurrency, false); |
|
193 | 193 | |
194 | 194 | $context = clone $context; |
195 | - $context->setLocale( $locale ); |
|
195 | + $context->setLocale($locale); |
|
196 | 196 | |
197 | - $manager = \Aimeos\MShop\Order\Manager\Factory::createManager( $context )->getSubManager( 'base' ); |
|
198 | - $basket = $manager->getSession( $type ); |
|
197 | + $manager = \Aimeos\MShop\Order\Manager\Factory::createManager($context)->getSubManager('base'); |
|
198 | + $basket = $manager->getSession($type); |
|
199 | 199 | |
200 | - $this->copyAddresses( $basket, $errors, $localeKey ); |
|
201 | - $this->copyServices( $basket, $errors ); |
|
202 | - $this->copyProducts( $basket, $errors, $localeKey ); |
|
203 | - $this->copyCoupons( $basket, $errors, $localeKey ); |
|
200 | + $this->copyAddresses($basket, $errors, $localeKey); |
|
201 | + $this->copyServices($basket, $errors); |
|
202 | + $this->copyProducts($basket, $errors, $localeKey); |
|
203 | + $this->copyCoupons($basket, $errors, $localeKey); |
|
204 | 204 | |
205 | - $manager->setSession( $basket, $type ); |
|
205 | + $manager->setSession($basket, $type); |
|
206 | 206 | } |
207 | 207 | |
208 | - $session->set( 'aimeos/basket/locale', $localeKey ); |
|
208 | + $session->set('aimeos/basket/locale', $localeKey); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | |
@@ -217,20 +217,20 @@ discard block |
||
217 | 217 | * @param string $localeKey Unique identifier of the site, language and currency |
218 | 218 | * @return array Associative list of errors occured |
219 | 219 | */ |
220 | - protected function copyAddresses( \Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors, $localeKey ) |
|
220 | + protected function copyAddresses(\Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors, $localeKey) |
|
221 | 221 | { |
222 | - foreach( $basket->getAddresses() as $type => $item ) |
|
222 | + foreach ($basket->getAddresses() as $type => $item) |
|
223 | 223 | { |
224 | 224 | try |
225 | 225 | { |
226 | - $this->setAddress( $type, $item->toArray() ); |
|
227 | - $basket->deleteAddress( $type ); |
|
226 | + $this->setAddress($type, $item->toArray()); |
|
227 | + $basket->deleteAddress($type); |
|
228 | 228 | } |
229 | - catch( \Exception $e ) |
|
229 | + catch (\Exception $e) |
|
230 | 230 | { |
231 | 231 | $logger = $this->getContext()->getLogger(); |
232 | 232 | $str = 'Error migrating address with type "%1$s" in basket to locale "%2$s": %3$s'; |
233 | - $logger->log( sprintf( $str, $type, $localeKey, $e->getMessage() ), \Aimeos\MW\Logger\Base::INFO ); |
|
233 | + $logger->log(sprintf($str, $type, $localeKey, $e->getMessage()), \Aimeos\MW\Logger\Base::INFO); |
|
234 | 234 | $errors['address'][$type] = $e->getMessage(); |
235 | 235 | } |
236 | 236 | } |
@@ -247,20 +247,20 @@ discard block |
||
247 | 247 | * @param string $localeKey Unique identifier of the site, language and currency |
248 | 248 | * @return array Associative list of errors occured |
249 | 249 | */ |
250 | - protected function copyCoupons( \Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors, $localeKey ) |
|
250 | + protected function copyCoupons(\Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors, $localeKey) |
|
251 | 251 | { |
252 | - foreach( $basket->getCoupons() as $code => $list ) |
|
252 | + foreach ($basket->getCoupons() as $code => $list) |
|
253 | 253 | { |
254 | 254 | try |
255 | 255 | { |
256 | - $this->addCoupon( $code ); |
|
257 | - $basket->deleteCoupon( $code, true ); |
|
256 | + $this->addCoupon($code); |
|
257 | + $basket->deleteCoupon($code, true); |
|
258 | 258 | } |
259 | - catch( \Exception $e ) |
|
259 | + catch (\Exception $e) |
|
260 | 260 | { |
261 | 261 | $logger = $this->getContext()->getLogger(); |
262 | 262 | $str = 'Error migrating coupon with code "%1$s" in basket to locale "%2$s": %3$s'; |
263 | - $logger->log( sprintf( $str, $code, $localeKey, $e->getMessage() ), \Aimeos\MW\Logger\Base::INFO ); |
|
263 | + $logger->log(sprintf($str, $code, $localeKey, $e->getMessage()), \Aimeos\MW\Logger\Base::INFO); |
|
264 | 264 | $errors['coupon'][$code] = $e->getMessage(); |
265 | 265 | } |
266 | 266 | } |
@@ -277,11 +277,11 @@ discard block |
||
277 | 277 | * @param string $localeKey Unique identifier of the site, language and currency |
278 | 278 | * @return array Associative list of errors occured |
279 | 279 | */ |
280 | - protected function copyProducts( \Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors, $localeKey ) |
|
280 | + protected function copyProducts(\Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors, $localeKey) |
|
281 | 281 | { |
282 | - foreach( $basket->getProducts() as $pos => $product ) |
|
282 | + foreach ($basket->getProducts() as $pos => $product) |
|
283 | 283 | { |
284 | - if( $product->getFlags() & \Aimeos\MShop\Order\Item\Base\Product\Base::FLAG_IMMUTABLE ) { |
|
284 | + if ($product->getFlags() & \Aimeos\MShop\Order\Item\Base\Product\Base::FLAG_IMMUTABLE) { |
|
285 | 285 | continue; |
286 | 286 | } |
287 | 287 | |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | { |
290 | 290 | $attrIds = []; |
291 | 291 | |
292 | - foreach( $product->getAttributes() as $attrItem ) { |
|
292 | + foreach ($product->getAttributes() as $attrItem) { |
|
293 | 293 | $attrIds[$attrItem->getType()][] = $attrItem->getAttributeId(); |
294 | 294 | } |
295 | 295 | |
@@ -297,23 +297,23 @@ discard block |
||
297 | 297 | $product->getProductId(), |
298 | 298 | $product->getQuantity(), |
299 | 299 | [], |
300 | - $this->getValue( $attrIds, 'variant', [] ), |
|
301 | - $this->getValue( $attrIds, 'config', [] ), |
|
302 | - $this->getValue( $attrIds, 'hidden', [] ), |
|
303 | - $this->getValue( $attrIds, 'custom', [] ), |
|
300 | + $this->getValue($attrIds, 'variant', []), |
|
301 | + $this->getValue($attrIds, 'config', []), |
|
302 | + $this->getValue($attrIds, 'hidden', []), |
|
303 | + $this->getValue($attrIds, 'custom', []), |
|
304 | 304 | $product->getStockType() |
305 | 305 | ); |
306 | 306 | |
307 | - $basket->deleteProduct( $pos ); |
|
307 | + $basket->deleteProduct($pos); |
|
308 | 308 | } |
309 | - catch( \Exception $e ) |
|
309 | + catch (\Exception $e) |
|
310 | 310 | { |
311 | 311 | $code = $product->getProductCode(); |
312 | 312 | $logger = $this->getContext()->getLogger(); |
313 | 313 | $errors['product'][$pos] = $e->getMessage(); |
314 | 314 | |
315 | 315 | $str = 'Error migrating product with code "%1$s" in basket to locale "%2$s": %3$s'; |
316 | - $logger->log( sprintf( $str, $code, $localeKey, $e->getMessage() ), \Aimeos\MW\Logger\Base::INFO ); |
|
316 | + $logger->log(sprintf($str, $code, $localeKey, $e->getMessage()), \Aimeos\MW\Logger\Base::INFO); |
|
317 | 317 | } |
318 | 318 | } |
319 | 319 | |
@@ -328,22 +328,22 @@ discard block |
||
328 | 328 | * @param array $errors Associative list of previous errors |
329 | 329 | * @return array Associative list of errors occured |
330 | 330 | */ |
331 | - protected function copyServices( \Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors ) |
|
331 | + protected function copyServices(\Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors) |
|
332 | 332 | { |
333 | - foreach( $basket->getServices() as $type => $item ) |
|
333 | + foreach ($basket->getServices() as $type => $item) |
|
334 | 334 | { |
335 | 335 | try |
336 | 336 | { |
337 | 337 | $attributes = []; |
338 | 338 | |
339 | - foreach( $item->getAttributes() as $attrItem ) { |
|
339 | + foreach ($item->getAttributes() as $attrItem) { |
|
340 | 340 | $attributes[$attrItem->getCode()] = $attrItem->getValue(); |
341 | 341 | } |
342 | 342 | |
343 | - $this->setService( $type, $item->getServiceId(), $attributes ); |
|
344 | - $basket->deleteService( $type ); |
|
343 | + $this->setService($type, $item->getServiceId(), $attributes); |
|
344 | + $basket->deleteService($type); |
|
345 | 345 | } |
346 | - catch( \Exception $e ) { ; } // Don't notify the user as appropriate services can be added automatically |
|
346 | + catch (\Exception $e) {; } // Don't notify the user as appropriate services can be added automatically |
|
347 | 347 | } |
348 | 348 | |
349 | 349 | return $errors; |
@@ -362,36 +362,36 @@ discard block |
||
362 | 362 | * @return array List of items implementing \Aimeos\MShop\Order\Item\Product\Attribute\Iface |
363 | 363 | * @deprecated Use getOrderProductAttributes(), checkReferences() and calcPrice() instead |
364 | 364 | */ |
365 | - protected function createOrderProductAttributes( \Aimeos\MShop\Price\Item\Iface $price, $prodid, $quantity, |
|
366 | - array $attributeIds, $type, array $attributeValues = [] ) |
|
365 | + protected function createOrderProductAttributes(\Aimeos\MShop\Price\Item\Iface $price, $prodid, $quantity, |
|
366 | + array $attributeIds, $type, array $attributeValues = []) |
|
367 | 367 | { |
368 | - if( empty( $attributeIds ) ) { |
|
368 | + if (empty($attributeIds)) { |
|
369 | 369 | return []; |
370 | 370 | } |
371 | 371 | |
372 | - $attrTypeId = $this->getProductListTypeItem( 'attribute', $type )->getId(); |
|
373 | - $this->checkReferences( $prodid, 'attribute', $attrTypeId, $attributeIds ); |
|
372 | + $attrTypeId = $this->getProductListTypeItem('attribute', $type)->getId(); |
|
373 | + $this->checkReferences($prodid, 'attribute', $attrTypeId, $attributeIds); |
|
374 | 374 | |
375 | 375 | $list = []; |
376 | 376 | $context = $this->getContext(); |
377 | 377 | |
378 | - $priceManager = \Aimeos\MShop\Factory::createManager( $context, 'price' ); |
|
379 | - $orderProductAttributeManager = \Aimeos\MShop\Factory::createManager( $context, 'order/base/product/attribute' ); |
|
378 | + $priceManager = \Aimeos\MShop\Factory::createManager($context, 'price'); |
|
379 | + $orderProductAttributeManager = \Aimeos\MShop\Factory::createManager($context, 'order/base/product/attribute'); |
|
380 | 380 | |
381 | - foreach( $this->getAttributes( $attributeIds ) as $id => $attrItem ) |
|
381 | + foreach ($this->getAttributes($attributeIds) as $id => $attrItem) |
|
382 | 382 | { |
383 | - $prices = $attrItem->getRefItems( 'price', 'default', 'default' ); |
|
383 | + $prices = $attrItem->getRefItems('price', 'default', 'default'); |
|
384 | 384 | |
385 | - if( !empty( $prices ) ) { |
|
386 | - $price->addItem( $priceManager->getLowestPrice( $prices, $quantity ) ); |
|
385 | + if (!empty($prices)) { |
|
386 | + $price->addItem($priceManager->getLowestPrice($prices, $quantity)); |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | $item = $orderProductAttributeManager->createItem(); |
390 | - $item->copyFrom( $attrItem ); |
|
391 | - $item->setType( $type ); |
|
390 | + $item->copyFrom($attrItem); |
|
391 | + $item->setType($type); |
|
392 | 392 | |
393 | - if( isset( $attributeValues[$id] ) ) { |
|
394 | - $item->setValue( $attributeValues[$id] ); |
|
393 | + if (isset($attributeValues[$id])) { |
|
394 | + $item->setValue($attributeValues[$id]); |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | $list[] = $item; |
@@ -409,31 +409,31 @@ discard block |
||
409 | 409 | * @return array List of items implementing \Aimeos\MShop\Attribute\Item\Iface |
410 | 410 | * @throws \Aimeos\Controller\Frontend\Basket\Exception If the actual attribute number doesn't match the expected one |
411 | 411 | */ |
412 | - protected function getAttributes( array $attributeIds, array $domains = array( 'price', 'text' ) ) |
|
412 | + protected function getAttributes(array $attributeIds, array $domains = array('price', 'text')) |
|
413 | 413 | { |
414 | - if( empty( $attributeIds ) ) { |
|
414 | + if (empty($attributeIds)) { |
|
415 | 415 | return []; |
416 | 416 | } |
417 | 417 | |
418 | - $attributeManager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'attribute' ); |
|
418 | + $attributeManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'attribute'); |
|
419 | 419 | |
420 | - $search = $attributeManager->createSearch( true ); |
|
420 | + $search = $attributeManager->createSearch(true); |
|
421 | 421 | $expr = array( |
422 | - $search->compare( '==', 'attribute.id', $attributeIds ), |
|
422 | + $search->compare('==', 'attribute.id', $attributeIds), |
|
423 | 423 | $search->getConditions(), |
424 | 424 | ); |
425 | - $search->setConditions( $search->combine( '&&', $expr ) ); |
|
426 | - $search->setSlice( 0, 0x7fffffff ); |
|
425 | + $search->setConditions($search->combine('&&', $expr)); |
|
426 | + $search->setSlice(0, 0x7fffffff); |
|
427 | 427 | |
428 | - $attrItems = $attributeManager->searchItems( $search, $domains ); |
|
428 | + $attrItems = $attributeManager->searchItems($search, $domains); |
|
429 | 429 | |
430 | - if( count( $attrItems ) !== count( $attributeIds ) ) |
|
430 | + if (count($attrItems) !== count($attributeIds)) |
|
431 | 431 | { |
432 | - $expected = implode( ',', $attributeIds ); |
|
433 | - $actual = implode( ',', array_keys( $attrItems ) ); |
|
434 | - $msg = sprintf( 'Available attribute IDs "%1$s" do not match the given attribute IDs "%2$s"', $actual, $expected ); |
|
432 | + $expected = implode(',', $attributeIds); |
|
433 | + $actual = implode(',', array_keys($attrItems)); |
|
434 | + $msg = sprintf('Available attribute IDs "%1$s" do not match the given attribute IDs "%2$s"', $actual, $expected); |
|
435 | 435 | |
436 | - throw new \Aimeos\Controller\Frontend\Basket\Exception( $msg ); |
|
436 | + throw new \Aimeos\Controller\Frontend\Basket\Exception($msg); |
|
437 | 437 | } |
438 | 438 | |
439 | 439 | return $attrItems; |
@@ -446,31 +446,31 @@ discard block |
||
446 | 446 | * @param \Aimeos\MShop\Order\Item\Base\Product\Attribute\Item[] $orderAttributes List of order product attribute items |
447 | 447 | * @return \Aimeos\MShop\Attribute\Item\Iface[] Associative list of attribute IDs as key and attribute items as values |
448 | 448 | */ |
449 | - protected function getAttributeItems( array $orderAttributes ) |
|
449 | + protected function getAttributeItems(array $orderAttributes) |
|
450 | 450 | { |
451 | - if( empty( $orderAttributes ) ) { |
|
451 | + if (empty($orderAttributes)) { |
|
452 | 452 | return []; |
453 | 453 | } |
454 | 454 | |
455 | - $attributeManager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'attribute' ); |
|
456 | - $search = $attributeManager->createSearch( true ); |
|
455 | + $attributeManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'attribute'); |
|
456 | + $search = $attributeManager->createSearch(true); |
|
457 | 457 | $expr = []; |
458 | 458 | |
459 | - foreach( $orderAttributes as $item ) |
|
459 | + foreach ($orderAttributes as $item) |
|
460 | 460 | { |
461 | 461 | $tmp = array( |
462 | - $search->compare( '==', 'attribute.domain', 'product' ), |
|
463 | - $search->compare( '==', 'attribute.code', $item->getValue() ), |
|
464 | - $search->compare( '==', 'attribute.type.domain', 'product' ), |
|
465 | - $search->compare( '==', 'attribute.type.code', $item->getCode() ), |
|
466 | - $search->compare( '>', 'attribute.type.status', 0 ), |
|
462 | + $search->compare('==', 'attribute.domain', 'product'), |
|
463 | + $search->compare('==', 'attribute.code', $item->getValue()), |
|
464 | + $search->compare('==', 'attribute.type.domain', 'product'), |
|
465 | + $search->compare('==', 'attribute.type.code', $item->getCode()), |
|
466 | + $search->compare('>', 'attribute.type.status', 0), |
|
467 | 467 | $search->getConditions(), |
468 | 468 | ); |
469 | - $expr[] = $search->combine( '&&', $tmp ); |
|
469 | + $expr[] = $search->combine('&&', $tmp); |
|
470 | 470 | } |
471 | 471 | |
472 | - $search->setConditions( $search->combine( '||', $expr ) ); |
|
473 | - return $attributeManager->searchItems( $search, array( 'price' ) ); |
|
472 | + $search->setConditions($search->combine('||', $expr)); |
|
473 | + return $attributeManager->searchItems($search, array('price')); |
|
474 | 474 | } |
475 | 475 | |
476 | 476 | |
@@ -485,23 +485,23 @@ discard block |
||
485 | 485 | * @throws \Aimeos\Controller\Frontend\Basket\Exception |
486 | 486 | * @deprecated Use getItem() or findItem() instead |
487 | 487 | */ |
488 | - protected function getDomainItem( $domain, $key, $value, array $ref ) |
|
488 | + protected function getDomainItem($domain, $key, $value, array $ref) |
|
489 | 489 | { |
490 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), $domain ); |
|
490 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), $domain); |
|
491 | 491 | |
492 | - $search = $manager->createSearch( true ); |
|
492 | + $search = $manager->createSearch(true); |
|
493 | 493 | $expr = array( |
494 | - $search->compare( '==', $key, $value ), |
|
494 | + $search->compare('==', $key, $value), |
|
495 | 495 | $search->getConditions(), |
496 | 496 | ); |
497 | - $search->setConditions( $search->combine( '&&', $expr ) ); |
|
497 | + $search->setConditions($search->combine('&&', $expr)); |
|
498 | 498 | |
499 | - $result = $manager->searchItems( $search, $ref ); |
|
499 | + $result = $manager->searchItems($search, $ref); |
|
500 | 500 | |
501 | - if( ( $item = reset( $result ) ) === false ) |
|
501 | + if (($item = reset($result)) === false) |
|
502 | 502 | { |
503 | - $msg = sprintf( 'No item for "%1$s" (%2$s) found', $value, $key ); |
|
504 | - throw new \Aimeos\Controller\Frontend\Basket\Exception( $msg ); |
|
503 | + $msg = sprintf('No item for "%1$s" (%2$s) found', $value, $key); |
|
504 | + throw new \Aimeos\Controller\Frontend\Basket\Exception($msg); |
|
505 | 505 | } |
506 | 506 | |
507 | 507 | return $item; |
@@ -516,27 +516,27 @@ discard block |
||
516 | 516 | * @param array $attributeValues Associative list of attribute IDs as keys and their codes as values |
517 | 517 | * @return array List of items implementing \Aimeos\MShop\Order\Item\Product\Attribute\Iface |
518 | 518 | */ |
519 | - protected function getOrderProductAttributes( $type, array $attributeIds, array $attributeValues = [] ) |
|
519 | + protected function getOrderProductAttributes($type, array $attributeIds, array $attributeValues = []) |
|
520 | 520 | { |
521 | - if( empty( $attributeIds ) ) { |
|
521 | + if (empty($attributeIds)) { |
|
522 | 522 | return []; |
523 | 523 | } |
524 | 524 | |
525 | - foreach( $attributeValues as $key => $value ) { |
|
525 | + foreach ($attributeValues as $key => $value) { |
|
526 | 526 | $attributeValues[(string) $key] = $value; // Workaround for PHP bug #74739 |
527 | 527 | } |
528 | 528 | |
529 | 529 | $list = []; |
530 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'order/base/product/attribute' ); |
|
530 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'order/base/product/attribute'); |
|
531 | 531 | |
532 | - foreach( $this->getAttributes( $attributeIds ) as $id => $attrItem ) |
|
532 | + foreach ($this->getAttributes($attributeIds) as $id => $attrItem) |
|
533 | 533 | { |
534 | 534 | $item = $manager->createItem(); |
535 | - $item->copyFrom( $attrItem ); |
|
536 | - $item->setType( $type ); |
|
535 | + $item->copyFrom($attrItem); |
|
536 | + $item->setType($type); |
|
537 | 537 | |
538 | - if( isset( $attributeValues[$id] ) ) { |
|
539 | - $item->setValue( $attributeValues[$id] ); |
|
538 | + if (isset($attributeValues[$id])) { |
|
539 | + $item->setValue($attributeValues[$id]); |
|
540 | 540 | } |
541 | 541 | |
542 | 542 | $list[] = $item; |
@@ -553,21 +553,21 @@ discard block |
||
553 | 553 | * @param string $code Code of the list type |
554 | 554 | * @return \Aimeos\MShop\Common\Item\Type\Iface List type item |
555 | 555 | */ |
556 | - protected function getProductListTypeItem( $domain, $code ) |
|
556 | + protected function getProductListTypeItem($domain, $code) |
|
557 | 557 | { |
558 | - if( empty( $this->listTypeItems ) ) |
|
558 | + if (empty($this->listTypeItems)) |
|
559 | 559 | { |
560 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product/lists/type' ); |
|
560 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product/lists/type'); |
|
561 | 561 | |
562 | - foreach( $manager->searchItems( $manager->createSearch( true ) ) as $item ) { |
|
563 | - $this->listTypeItems[ $item->getDomain() ][ $item->getCode() ] = $item; |
|
562 | + foreach ($manager->searchItems($manager->createSearch(true)) as $item) { |
|
563 | + $this->listTypeItems[$item->getDomain()][$item->getCode()] = $item; |
|
564 | 564 | } |
565 | 565 | } |
566 | 566 | |
567 | - if( !isset( $this->listTypeItems[$domain][$code] ) ) |
|
567 | + if (!isset($this->listTypeItems[$domain][$code])) |
|
568 | 568 | { |
569 | - $msg = sprintf( 'List type for domain "%1$s" and code "%2$s" not found', $domain, $code ); |
|
570 | - throw new \Aimeos\Controller\Frontend\Basket\Exception( $msg ); |
|
569 | + $msg = sprintf('List type for domain "%1$s" and code "%2$s" not found', $domain, $code); |
|
570 | + throw new \Aimeos\Controller\Frontend\Basket\Exception($msg); |
|
571 | 571 | } |
572 | 572 | |
573 | 573 | return $this->listTypeItems[$domain][$code]; |
@@ -582,43 +582,43 @@ discard block |
||
582 | 582 | * @param array $domains Names of the domain items that should be fetched too |
583 | 583 | * @return array List of products matching the given attributes |
584 | 584 | */ |
585 | - protected function getProductVariants( \Aimeos\MShop\Product\Item\Iface $productItem, array $variantAttributeIds, |
|
586 | - array $domains = array( 'attribute', 'media', 'price', 'text' ) ) |
|
585 | + protected function getProductVariants(\Aimeos\MShop\Product\Item\Iface $productItem, array $variantAttributeIds, |
|
586 | + array $domains = array('attribute', 'media', 'price', 'text')) |
|
587 | 587 | { |
588 | 588 | $subProductIds = []; |
589 | - foreach( $productItem->getRefItems( 'product', 'default', 'default' ) as $item ) { |
|
589 | + foreach ($productItem->getRefItems('product', 'default', 'default') as $item) { |
|
590 | 590 | $subProductIds[] = $item->getId(); |
591 | 591 | } |
592 | 592 | |
593 | - if( count( $subProductIds ) === 0 ) { |
|
593 | + if (count($subProductIds) === 0) { |
|
594 | 594 | return []; |
595 | 595 | } |
596 | 596 | |
597 | - $productManager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product' ); |
|
598 | - $search = $productManager->createSearch( true ); |
|
597 | + $productManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product'); |
|
598 | + $search = $productManager->createSearch(true); |
|
599 | 599 | |
600 | 600 | $expr = array( |
601 | - $search->compare( '==', 'product.id', $subProductIds ), |
|
601 | + $search->compare('==', 'product.id', $subProductIds), |
|
602 | 602 | $search->getConditions(), |
603 | 603 | ); |
604 | 604 | |
605 | - if( count( $variantAttributeIds ) > 0 ) |
|
605 | + if (count($variantAttributeIds) > 0) |
|
606 | 606 | { |
607 | - foreach( $variantAttributeIds as $key => $id ) { |
|
607 | + foreach ($variantAttributeIds as $key => $id) { |
|
608 | 608 | $variantAttributeIds[$key] = (string) $id; |
609 | 609 | } |
610 | 610 | |
611 | - $listTypeItem = $this->getProductListTypeItem( 'attribute', 'variant' ); |
|
611 | + $listTypeItem = $this->getProductListTypeItem('attribute', 'variant'); |
|
612 | 612 | |
613 | - $param = array( 'attribute', $listTypeItem->getId(), $variantAttributeIds ); |
|
614 | - $cmpfunc = $search->createFunction( 'product.contains', $param ); |
|
613 | + $param = array('attribute', $listTypeItem->getId(), $variantAttributeIds); |
|
614 | + $cmpfunc = $search->createFunction('product.contains', $param); |
|
615 | 615 | |
616 | - $expr[] = $search->compare( '==', $cmpfunc, count( $variantAttributeIds ) ); |
|
616 | + $expr[] = $search->compare('==', $cmpfunc, count($variantAttributeIds)); |
|
617 | 617 | } |
618 | 618 | |
619 | - $search->setConditions( $search->combine( '&&', $expr ) ); |
|
619 | + $search->setConditions($search->combine('&&', $expr)); |
|
620 | 620 | |
621 | - return $productManager->searchItems( $search, $domains ); |
|
621 | + return $productManager->searchItems($search, $domains); |
|
622 | 622 | } |
623 | 623 | |
624 | 624 | |
@@ -630,9 +630,9 @@ discard block |
||
630 | 630 | * @param mixed $default Default value if no value is available for the given name |
631 | 631 | * @return mixed Value from the array or default value |
632 | 632 | */ |
633 | - protected function getValue( array $values, $name, $default = null ) |
|
633 | + protected function getValue(array $values, $name, $default = null) |
|
634 | 634 | { |
635 | - if( isset( $values[$name] ) ) { |
|
635 | + if (isset($values[$name])) { |
|
636 | 636 | return $values[$name]; |
637 | 637 | } |
638 | 638 |
@@ -21,7 +21,7 @@ |
||
21 | 21 | class Example |
22 | 22 | implements \Aimeos\Controller\Frontend\Common\Decorator\Iface |
23 | 23 | { |
24 | - public function __construct( \Aimeos\Controller\Frontend\Iface $controller, \Aimeos\MShop\Context\Item\Iface $context ) |
|
24 | + public function __construct(\Aimeos\Controller\Frontend\Iface $controller, \Aimeos\MShop\Context\Item\Iface $context) |
|
25 | 25 | { |
26 | 26 | } |
27 | 27 | } |
@@ -104,10 +104,11 @@ discard block |
||
104 | 104 | { |
105 | 105 | $msg = sprintf( 'No unique article found for selected attributes and product ID "%1$s"', $productItem->getId() ); |
106 | 106 | throw new \Aimeos\Controller\Frontend\Basket\Exception( $msg ); |
107 | - } |
|
108 | - else if( ( $result = reset( $productItems ) ) !== false ) // count == 1 |
|
107 | + } else if( ( $result = reset( $productItems ) ) !== false ) { |
|
108 | + // count == 1 |
|
109 | 109 | { |
110 | 110 | $productItem = $result; |
111 | + } |
|
111 | 112 | $orderBaseProductItem->setProductCode( $productItem->getCode() ); |
112 | 113 | |
113 | 114 | $subprices = $productItem->getRefItems( 'price', 'default', 'default' ); |
@@ -133,10 +134,11 @@ discard block |
||
133 | 134 | |
134 | 135 | $attr[] = $orderAttributeItem; |
135 | 136 | } |
136 | - } |
|
137 | - else if( !isset( $options['variant'] ) || $options['variant'] != false ) // count == 0 |
|
137 | + } else if( !isset( $options['variant'] ) || $options['variant'] != false ) { |
|
138 | + // count == 0 |
|
138 | 139 | { |
139 | 140 | $msg = sprintf( 'No article found for selected attributes and product ID "%1$s"', $productItem->getId() ); |
141 | + } |
|
140 | 142 | throw new \Aimeos\Controller\Frontend\Basket\Exception( $msg ); |
141 | 143 | } |
142 | 144 |
@@ -41,15 +41,15 @@ discard block |
||
41 | 41 | * @param string $stocktype Unique code of the stock type to deliver the products from |
42 | 42 | * @throws \Aimeos\Controller\Frontend\Basket\Exception If the product isn't available |
43 | 43 | */ |
44 | - public function addProduct( $prodid, $quantity = 1, array $options = [], array $variantAttributeIds = [], |
|
44 | + public function addProduct($prodid, $quantity = 1, array $options = [], array $variantAttributeIds = [], |
|
45 | 45 | array $configAttributeIds = [], array $hiddenAttributeIds = [], array $customAttributeValues = [], |
46 | - $stocktype = 'default' ) |
|
46 | + $stocktype = 'default') |
|
47 | 47 | { |
48 | 48 | $context = $this->getContext(); |
49 | - $productManager = \Aimeos\MShop\Factory::createManager( $context, 'product' ); |
|
50 | - $productItem = $productManager->getItem( $prodid, [], true ); |
|
49 | + $productManager = \Aimeos\MShop\Factory::createManager($context, 'product'); |
|
50 | + $productItem = $productManager->getItem($prodid, [], true); |
|
51 | 51 | |
52 | - if( $productManager->getItem( $prodid, [], true )->getType() !== 'select' ) |
|
52 | + if ($productManager->getItem($prodid, [], true)->getType() !== 'select') |
|
53 | 53 | { |
54 | 54 | return $this->getController()->addProduct( |
55 | 55 | $prodid, $quantity, $options, $variantAttributeIds, $configAttributeIds, |
@@ -57,29 +57,29 @@ discard block |
||
57 | 57 | ); |
58 | 58 | } |
59 | 59 | |
60 | - $productItem = $productManager->getItem( $prodid, array( 'media', 'supplier', 'price', 'product', 'text' ), true ); |
|
61 | - $prices = $productItem->getRefItems( 'price', 'default', 'default' ); |
|
60 | + $productItem = $productManager->getItem($prodid, array('media', 'supplier', 'price', 'product', 'text'), true); |
|
61 | + $prices = $productItem->getRefItems('price', 'default', 'default'); |
|
62 | 62 | |
63 | - $orderBaseProductItem = \Aimeos\MShop\Factory::createManager( $context, 'order/base/product' )->createItem(); |
|
64 | - $orderBaseProductItem->copyFrom( $productItem )->setQuantity( $quantity )->setStockType( $stocktype ); |
|
63 | + $orderBaseProductItem = \Aimeos\MShop\Factory::createManager($context, 'order/base/product')->createItem(); |
|
64 | + $orderBaseProductItem->copyFrom($productItem)->setQuantity($quantity)->setStockType($stocktype); |
|
65 | 65 | |
66 | - $attr = $this->getVariantDetails( $orderBaseProductItem, $productItem, $prices, $variantAttributeIds, $options ); |
|
66 | + $attr = $this->getVariantDetails($orderBaseProductItem, $productItem, $prices, $variantAttributeIds, $options); |
|
67 | 67 | |
68 | 68 | $attributeMap = [ |
69 | - 'custom' => array_keys( $customAttributeValues ), |
|
69 | + 'custom' => array_keys($customAttributeValues), |
|
70 | 70 | 'config' => $configAttributeIds, |
71 | 71 | 'hidden' => $hiddenAttributeIds, |
72 | 72 | ]; |
73 | - $this->checkListRef( array( $prodid, $productItem->getId() ), 'attribute', $attributeMap ); |
|
73 | + $this->checkListRef(array($prodid, $productItem->getId()), 'attribute', $attributeMap); |
|
74 | 74 | |
75 | - $attr = array_merge( $attr, $this->getOrderProductAttributes( 'custom', array_keys( $customAttributeValues ), $customAttributeValues ) ); |
|
76 | - $attr = array_merge( $attr, $this->getOrderProductAttributes( 'config', $configAttributeIds ) ); |
|
77 | - $attr = array_merge( $attr, $this->getOrderProductAttributes( 'hidden', $hiddenAttributeIds ) ); |
|
75 | + $attr = array_merge($attr, $this->getOrderProductAttributes('custom', array_keys($customAttributeValues), $customAttributeValues)); |
|
76 | + $attr = array_merge($attr, $this->getOrderProductAttributes('config', $configAttributeIds)); |
|
77 | + $attr = array_merge($attr, $this->getOrderProductAttributes('hidden', $hiddenAttributeIds)); |
|
78 | 78 | |
79 | - $orderBaseProductItem->setAttributes( $attr ); |
|
80 | - $orderBaseProductItem->setPrice( $this->calcPrice( $orderBaseProductItem, $prices, $quantity ) ); |
|
79 | + $orderBaseProductItem->setAttributes($attr); |
|
80 | + $orderBaseProductItem->setPrice($this->calcPrice($orderBaseProductItem, $prices, $quantity)); |
|
81 | 81 | |
82 | - $this->getController()->get()->addProduct( $orderBaseProductItem ); |
|
82 | + $this->getController()->get()->addProduct($orderBaseProductItem); |
|
83 | 83 | $this->getController()->save(); |
84 | 84 | } |
85 | 85 | |
@@ -95,50 +95,50 @@ discard block |
||
95 | 95 | * @return \Aimeos\MShop\Order\Item\Base\Product\Attribute\Iface[] List of order product attributes |
96 | 96 | * @throws \Aimeos\Controller\Frontend\Basket\Exception If no product variant is found |
97 | 97 | */ |
98 | - protected function getVariantDetails( \Aimeos\MShop\Order\Item\Base\Product\Iface $orderBaseProductItem, |
|
99 | - \Aimeos\MShop\Product\Item\Iface &$productItem, array &$prices, array $variantAttributeIds, array $options ) |
|
98 | + protected function getVariantDetails(\Aimeos\MShop\Order\Item\Base\Product\Iface $orderBaseProductItem, |
|
99 | + \Aimeos\MShop\Product\Item\Iface & $productItem, array &$prices, array $variantAttributeIds, array $options) |
|
100 | 100 | { |
101 | 101 | $attr = []; |
102 | - $productItems = $this->getProductVariants( $productItem, $variantAttributeIds ); |
|
102 | + $productItems = $this->getProductVariants($productItem, $variantAttributeIds); |
|
103 | 103 | |
104 | - if( count( $productItems ) > 1 ) |
|
104 | + if (count($productItems) > 1) |
|
105 | 105 | { |
106 | - $msg = sprintf( 'No unique article found for selected attributes and product ID "%1$s"', $productItem->getId() ); |
|
107 | - throw new \Aimeos\Controller\Frontend\Basket\Exception( $msg ); |
|
106 | + $msg = sprintf('No unique article found for selected attributes and product ID "%1$s"', $productItem->getId()); |
|
107 | + throw new \Aimeos\Controller\Frontend\Basket\Exception($msg); |
|
108 | 108 | } |
109 | - else if( ( $result = reset( $productItems ) ) !== false ) // count == 1 |
|
109 | + else if (($result = reset($productItems)) !== false) // count == 1 |
|
110 | 110 | { |
111 | 111 | $productItem = $result; |
112 | - $orderBaseProductItem->setProductCode( $productItem->getCode() ); |
|
112 | + $orderBaseProductItem->setProductCode($productItem->getCode()); |
|
113 | 113 | |
114 | - $subprices = $productItem->getRefItems( 'price', 'default', 'default' ); |
|
114 | + $subprices = $productItem->getRefItems('price', 'default', 'default'); |
|
115 | 115 | |
116 | - if( !empty( $subprices ) ) { |
|
116 | + if (!empty($subprices)) { |
|
117 | 117 | $prices = $subprices; |
118 | 118 | } |
119 | 119 | |
120 | - $submedia = $productItem->getRefItems( 'media', 'default', 'default' ); |
|
120 | + $submedia = $productItem->getRefItems('media', 'default', 'default'); |
|
121 | 121 | |
122 | - if( ( $mediaItem = reset( $submedia ) ) !== false ) { |
|
123 | - $orderBaseProductItem->setMediaUrl( $mediaItem->getPreview() ); |
|
122 | + if (($mediaItem = reset($submedia)) !== false) { |
|
123 | + $orderBaseProductItem->setMediaUrl($mediaItem->getPreview()); |
|
124 | 124 | } |
125 | 125 | |
126 | - $orderProductAttrManager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'order/base/product/attribute' ); |
|
127 | - $variantAttributes = $productItem->getRefItems( 'attribute', null, 'variant' ); |
|
126 | + $orderProductAttrManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'order/base/product/attribute'); |
|
127 | + $variantAttributes = $productItem->getRefItems('attribute', null, 'variant'); |
|
128 | 128 | |
129 | - foreach( $this->getAttributes( array_keys( $variantAttributes ), array( 'text' ) ) as $attrItem ) |
|
129 | + foreach ($this->getAttributes(array_keys($variantAttributes), array('text')) as $attrItem) |
|
130 | 130 | { |
131 | 131 | $orderAttributeItem = $orderProductAttrManager->createItem(); |
132 | - $orderAttributeItem->copyFrom( $attrItem ); |
|
133 | - $orderAttributeItem->setType( 'variant' ); |
|
132 | + $orderAttributeItem->copyFrom($attrItem); |
|
133 | + $orderAttributeItem->setType('variant'); |
|
134 | 134 | |
135 | 135 | $attr[] = $orderAttributeItem; |
136 | 136 | } |
137 | 137 | } |
138 | - else if( !isset( $options['variant'] ) || $options['variant'] != false ) // count == 0 |
|
138 | + else if (!isset($options['variant']) || $options['variant'] != false) // count == 0 |
|
139 | 139 | { |
140 | - $msg = sprintf( 'No article found for selected attributes and product ID "%1$s"', $productItem->getId() ); |
|
141 | - throw new \Aimeos\Controller\Frontend\Basket\Exception( $msg ); |
|
140 | + $msg = sprintf('No article found for selected attributes and product ID "%1$s"', $productItem->getId()); |
|
141 | + throw new \Aimeos\Controller\Frontend\Basket\Exception($msg); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | return $attr; |