@@ -31,52 +31,52 @@ 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( $context, 'product' ); |
|
41 | - $prices = $manager->getItem( $product->getProductId(), array( 'price' ) )->getRefItems( 'price', 'default' ); |
|
40 | + $manager = \Aimeos\MShop\Factory::createManager($context, '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 ) |
|
53 | + if (preg_match('/^[0-9]*(\.[0-9]+)?$/', $amount) !== 1 || ((double) $amount) < 0.01) |
|
54 | 54 | { |
55 | - $msg = $context->getI18n()->dt( 'controller/frontend', 'Invalid price value "%1$s"' ); |
|
56 | - throw new \Aimeos\Controller\Frontend\Basket\Exception( sprintf( $msg, $amount ) ); |
|
55 | + $msg = $context->getI18n()->dt('controller/frontend', 'Invalid price value "%1$s"'); |
|
56 | + throw new \Aimeos\Controller\Frontend\Basket\Exception(sprintf($msg, $amount)); |
|
57 | 57 | } |
58 | 58 | |
59 | - $price->setValue( $amount ); |
|
59 | + $price->setValue($amount); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | $orderAttributes = $product->getAttributes(); |
63 | - $attrItems = $this->getAttributeItems( $orderAttributes ); |
|
63 | + $attrItems = $this->getAttributeItems($orderAttributes); |
|
64 | 64 | |
65 | 65 | // add prices of (optional) attributes |
66 | - foreach( $orderAttributes as $orderAttrItem ) |
|
66 | + foreach ($orderAttributes as $orderAttrItem) |
|
67 | 67 | { |
68 | 68 | $attrId = $orderAttrItem->getAttributeId(); |
69 | 69 | |
70 | - if( isset( $attrItems[$attrId] ) |
|
71 | - && ( $prices = $attrItems[$attrId]->getRefItems( 'price', 'default' ) ) !== [] |
|
70 | + if (isset($attrItems[$attrId]) |
|
71 | + && ($prices = $attrItems[$attrId]->getRefItems('price', 'default')) !== [] |
|
72 | 72 | ) { |
73 | - $attrPrice = $priceManager->getLowestPrice( $prices, $orderAttrItem->getQuantity() ); |
|
74 | - $price->addItem( $attrPrice, $orderAttrItem->getQuantity() ); |
|
73 | + $attrPrice = $priceManager->getLowestPrice($prices, $orderAttrItem->getQuantity()); |
|
74 | + $price->addItem($attrPrice, $orderAttrItem->getQuantity()); |
|
75 | 75 | } |
76 | 76 | } |
77 | 77 | |
78 | 78 | // remove product rebate of original price in favor to rebates granted for the order |
79 | - $price->setRebate( '0.00' ); |
|
79 | + $price->setRebate('0.00'); |
|
80 | 80 | |
81 | 81 | return $price; |
82 | 82 | } |
@@ -90,43 +90,43 @@ discard block |
||
90 | 90 | * @param array $refMap Associative list of list type codes as keys and lists of reference IDs as values |
91 | 91 | * @throws \Aimeos\Controller\Frontend\Basket\Exception If one or more of the IDs are not associated |
92 | 92 | */ |
93 | - protected function checkListRef( $prodId, $domain, array $refMap ) |
|
93 | + protected function checkListRef($prodId, $domain, array $refMap) |
|
94 | 94 | { |
95 | - if( empty( $refMap ) ) { |
|
95 | + if (empty($refMap)) { |
|
96 | 96 | return; |
97 | 97 | } |
98 | 98 | |
99 | 99 | $context = $this->getContext(); |
100 | - $productManager = \Aimeos\MShop\Factory::createManager( $context, 'product' ); |
|
101 | - $search = $productManager->createSearch( true ); |
|
100 | + $productManager = \Aimeos\MShop\Factory::createManager($context, 'product'); |
|
101 | + $search = $productManager->createSearch(true); |
|
102 | 102 | |
103 | 103 | $expr = array( |
104 | - $search->compare( '==', 'product.id', $prodId ), |
|
104 | + $search->compare('==', 'product.id', $prodId), |
|
105 | 105 | $search->getConditions(), |
106 | 106 | ); |
107 | 107 | |
108 | - foreach( $refMap as $listType => $refIds ) |
|
108 | + foreach ($refMap as $listType => $refIds) |
|
109 | 109 | { |
110 | - if( empty( $refIds ) ) { |
|
110 | + if (empty($refIds)) { |
|
111 | 111 | continue; |
112 | 112 | } |
113 | 113 | |
114 | - foreach( $refIds as $key => $refId ) { |
|
114 | + foreach ($refIds as $key => $refId) { |
|
115 | 115 | $refIds[$key] = (string) $refId; |
116 | 116 | } |
117 | 117 | |
118 | - $param = array( $domain, $this->getProductListTypeItem( $domain, $listType )->getId(), $refIds ); |
|
119 | - $cmpfunc = $search->createFunction( 'product.contains', $param ); |
|
118 | + $param = array($domain, $this->getProductListTypeItem($domain, $listType)->getId(), $refIds); |
|
119 | + $cmpfunc = $search->createFunction('product.contains', $param); |
|
120 | 120 | |
121 | - $expr[] = $search->compare( '==', $cmpfunc, count( $refIds ) ); |
|
121 | + $expr[] = $search->compare('==', $cmpfunc, count($refIds)); |
|
122 | 122 | } |
123 | 123 | |
124 | - $search->setConditions( $search->combine( '&&', $expr ) ); |
|
124 | + $search->setConditions($search->combine('&&', $expr)); |
|
125 | 125 | |
126 | - if( count( $productManager->searchItems( $search, [] ) ) === 0 ) |
|
126 | + if (count($productManager->searchItems($search, [])) === 0) |
|
127 | 127 | { |
128 | - $msg = $context->getI18n()->dt( 'controller/frontend', 'Invalid "%1$s" references for product with ID %2$s' ); |
|
129 | - throw new \Aimeos\Controller\Frontend\Basket\Exception( sprintf( $msg, $domain, json_encode( $prodId ) ) ); |
|
128 | + $msg = $context->getI18n()->dt('controller/frontend', 'Invalid "%1$s" references for product with ID %2$s'); |
|
129 | + throw new \Aimeos\Controller\Frontend\Basket\Exception(sprintf($msg, $domain, json_encode($prodId))); |
|
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
@@ -141,35 +141,35 @@ discard block |
||
141 | 141 | * @throws \Aimeos\Controller\Frontend\Basket\Exception If one or more of the IDs are not associated |
142 | 142 | * @deprecated Use checkListRef() instead |
143 | 143 | */ |
144 | - protected function checkReferences( $prodId, $domain, $listTypeId, array $refIds ) |
|
144 | + protected function checkReferences($prodId, $domain, $listTypeId, array $refIds) |
|
145 | 145 | { |
146 | 146 | $context = $this->getContext(); |
147 | - $productManager = \Aimeos\MShop\Factory::createManager( $context, 'product' ); |
|
148 | - $search = $productManager->createSearch( true ); |
|
147 | + $productManager = \Aimeos\MShop\Factory::createManager($context, 'product'); |
|
148 | + $search = $productManager->createSearch(true); |
|
149 | 149 | |
150 | 150 | $expr = array( |
151 | - $search->compare( '==', 'product.id', $prodId ), |
|
151 | + $search->compare('==', 'product.id', $prodId), |
|
152 | 152 | $search->getConditions(), |
153 | 153 | ); |
154 | 154 | |
155 | - if( count( $refIds ) > 0 ) |
|
155 | + if (count($refIds) > 0) |
|
156 | 156 | { |
157 | - foreach( $refIds as $key => $refId ) { |
|
157 | + foreach ($refIds as $key => $refId) { |
|
158 | 158 | $refIds[$key] = (string) $refId; |
159 | 159 | } |
160 | 160 | |
161 | - $param = array( $domain, $listTypeId, $refIds ); |
|
162 | - $cmpfunc = $search->createFunction( 'product.contains', $param ); |
|
161 | + $param = array($domain, $listTypeId, $refIds); |
|
162 | + $cmpfunc = $search->createFunction('product.contains', $param); |
|
163 | 163 | |
164 | - $expr[] = $search->compare( '==', $cmpfunc, count( $refIds ) ); |
|
164 | + $expr[] = $search->compare('==', $cmpfunc, count($refIds)); |
|
165 | 165 | } |
166 | 166 | |
167 | - $search->setConditions( $search->combine( '&&', $expr ) ); |
|
167 | + $search->setConditions($search->combine('&&', $expr)); |
|
168 | 168 | |
169 | - if( count( $productManager->searchItems( $search, [] ) ) === 0 ) |
|
169 | + if (count($productManager->searchItems($search, [])) === 0) |
|
170 | 170 | { |
171 | - $msg = $context->getI18n()->dt( 'controller/frontend', 'Invalid "%1$s" references for product with ID %2$s' ); |
|
172 | - throw new \Aimeos\Controller\Frontend\Basket\Exception( sprintf( $msg, $domain, json_encode( $prodId ) ) ); |
|
171 | + $msg = $context->getI18n()->dt('controller/frontend', 'Invalid "%1$s" references for product with ID %2$s'); |
|
172 | + throw new \Aimeos\Controller\Frontend\Basket\Exception(sprintf($msg, $domain, json_encode($prodId))); |
|
173 | 173 | } |
174 | 174 | } |
175 | 175 | |
@@ -179,41 +179,41 @@ discard block |
||
179 | 179 | * |
180 | 180 | * @param string $type Basket type |
181 | 181 | */ |
182 | - protected function checkLocale( $type ) |
|
182 | + protected function checkLocale($type) |
|
183 | 183 | { |
184 | 184 | $errors = []; |
185 | 185 | $context = $this->getContext(); |
186 | 186 | $session = $context->getSession(); |
187 | 187 | $locale = $this->get()->getLocale(); |
188 | 188 | |
189 | - $localeStr = $session->get( 'aimeos/basket/locale' ); |
|
189 | + $localeStr = $session->get('aimeos/basket/locale'); |
|
190 | 190 | $localeKey = $locale->getSite()->getCode() . '|' . $locale->getLanguageId() . '|' . $locale->getCurrencyId(); |
191 | 191 | |
192 | - if( $localeStr !== null && $localeStr !== $localeKey ) |
|
192 | + if ($localeStr !== null && $localeStr !== $localeKey) |
|
193 | 193 | { |
194 | - $locParts = explode( '|', $localeStr ); |
|
195 | - $locSite = ( isset( $locParts[0] ) ? $locParts[0] : '' ); |
|
196 | - $locLanguage = ( isset( $locParts[1] ) ? $locParts[1] : '' ); |
|
197 | - $locCurrency = ( isset( $locParts[2] ) ? $locParts[2] : '' ); |
|
194 | + $locParts = explode('|', $localeStr); |
|
195 | + $locSite = (isset($locParts[0]) ? $locParts[0] : ''); |
|
196 | + $locLanguage = (isset($locParts[1]) ? $locParts[1] : ''); |
|
197 | + $locCurrency = (isset($locParts[2]) ? $locParts[2] : ''); |
|
198 | 198 | |
199 | - $localeManager = \Aimeos\MShop\Factory::createManager( $context, 'locale' ); |
|
200 | - $locale = $localeManager->bootstrap( $locSite, $locLanguage, $locCurrency, false ); |
|
199 | + $localeManager = \Aimeos\MShop\Factory::createManager($context, 'locale'); |
|
200 | + $locale = $localeManager->bootstrap($locSite, $locLanguage, $locCurrency, false); |
|
201 | 201 | |
202 | 202 | $context = clone $context; |
203 | - $context->setLocale( $locale ); |
|
203 | + $context->setLocale($locale); |
|
204 | 204 | |
205 | - $manager = \Aimeos\MShop\Order\Manager\Factory::createManager( $context )->getSubManager( 'base' ); |
|
206 | - $basket = $manager->getSession( $type ); |
|
205 | + $manager = \Aimeos\MShop\Order\Manager\Factory::createManager($context)->getSubManager('base'); |
|
206 | + $basket = $manager->getSession($type); |
|
207 | 207 | |
208 | - $this->copyAddresses( $basket, $errors, $localeKey ); |
|
209 | - $this->copyServices( $basket, $errors ); |
|
210 | - $this->copyProducts( $basket, $errors, $localeKey ); |
|
211 | - $this->copyCoupons( $basket, $errors, $localeKey ); |
|
208 | + $this->copyAddresses($basket, $errors, $localeKey); |
|
209 | + $this->copyServices($basket, $errors); |
|
210 | + $this->copyProducts($basket, $errors, $localeKey); |
|
211 | + $this->copyCoupons($basket, $errors, $localeKey); |
|
212 | 212 | |
213 | - $manager->setSession( $basket, $type ); |
|
213 | + $manager->setSession($basket, $type); |
|
214 | 214 | } |
215 | 215 | |
216 | - $session->set( 'aimeos/basket/locale', $localeKey ); |
|
216 | + $session->set('aimeos/basket/locale', $localeKey); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | |
@@ -225,22 +225,22 @@ discard block |
||
225 | 225 | * @param string $localeKey Unique identifier of the site, language and currency |
226 | 226 | * @return array Associative list of errors occured |
227 | 227 | */ |
228 | - protected function copyAddresses( \Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors, $localeKey ) |
|
228 | + protected function copyAddresses(\Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors, $localeKey) |
|
229 | 229 | { |
230 | - foreach( $basket->getAddresses() as $type => $item ) |
|
230 | + foreach ($basket->getAddresses() as $type => $item) |
|
231 | 231 | { |
232 | 232 | try |
233 | 233 | { |
234 | - $this->setAddress( $type, $item->toArray() ); |
|
235 | - $basket->deleteAddress( $type ); |
|
234 | + $this->setAddress($type, $item->toArray()); |
|
235 | + $basket->deleteAddress($type); |
|
236 | 236 | } |
237 | - catch( \Exception $e ) |
|
237 | + catch (\Exception $e) |
|
238 | 238 | { |
239 | 239 | $logger = $this->getContext()->getLogger(); |
240 | 240 | $errors['address'][$type] = $e->getMessage(); |
241 | 241 | |
242 | 242 | $str = 'Error migrating address with type "%1$s" in basket to locale "%2$s": %3$s'; |
243 | - $logger->log( sprintf( $str, $type, $localeKey, $e->getMessage() ), \Aimeos\MW\Logger\Base::INFO ); |
|
243 | + $logger->log(sprintf($str, $type, $localeKey, $e->getMessage()), \Aimeos\MW\Logger\Base::INFO); |
|
244 | 244 | } |
245 | 245 | } |
246 | 246 | |
@@ -256,22 +256,22 @@ discard block |
||
256 | 256 | * @param string $localeKey Unique identifier of the site, language and currency |
257 | 257 | * @return array Associative list of errors occured |
258 | 258 | */ |
259 | - protected function copyCoupons( \Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors, $localeKey ) |
|
259 | + protected function copyCoupons(\Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors, $localeKey) |
|
260 | 260 | { |
261 | - foreach( $basket->getCoupons() as $code => $list ) |
|
261 | + foreach ($basket->getCoupons() as $code => $list) |
|
262 | 262 | { |
263 | 263 | try |
264 | 264 | { |
265 | - $this->addCoupon( $code ); |
|
266 | - $basket->deleteCoupon( $code, true ); |
|
265 | + $this->addCoupon($code); |
|
266 | + $basket->deleteCoupon($code, true); |
|
267 | 267 | } |
268 | - catch( \Exception $e ) |
|
268 | + catch (\Exception $e) |
|
269 | 269 | { |
270 | 270 | $logger = $this->getContext()->getLogger(); |
271 | 271 | $errors['coupon'][$code] = $e->getMessage(); |
272 | 272 | |
273 | 273 | $str = 'Error migrating coupon with code "%1$s" in basket to locale "%2$s": %3$s'; |
274 | - $logger->log( sprintf( $str, $code, $localeKey, $e->getMessage() ), \Aimeos\MW\Logger\Base::INFO ); |
|
274 | + $logger->log(sprintf($str, $code, $localeKey, $e->getMessage()), \Aimeos\MW\Logger\Base::INFO); |
|
275 | 275 | } |
276 | 276 | } |
277 | 277 | |
@@ -287,11 +287,11 @@ discard block |
||
287 | 287 | * @param string $localeKey Unique identifier of the site, language and currency |
288 | 288 | * @return array Associative list of errors occured |
289 | 289 | */ |
290 | - protected function copyProducts( \Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors, $localeKey ) |
|
290 | + protected function copyProducts(\Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors, $localeKey) |
|
291 | 291 | { |
292 | - foreach( $basket->getProducts() as $pos => $product ) |
|
292 | + foreach ($basket->getProducts() as $pos => $product) |
|
293 | 293 | { |
294 | - if( $product->getFlags() & \Aimeos\MShop\Order\Item\Base\Product\Base::FLAG_IMMUTABLE ) { |
|
294 | + if ($product->getFlags() & \Aimeos\MShop\Order\Item\Base\Product\Base::FLAG_IMMUTABLE) { |
|
295 | 295 | continue; |
296 | 296 | } |
297 | 297 | |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | { |
300 | 300 | $attrIds = []; |
301 | 301 | |
302 | - foreach( $product->getAttributes() as $attrItem ) { |
|
302 | + foreach ($product->getAttributes() as $attrItem) { |
|
303 | 303 | $attrIds[$attrItem->getType()][] = $attrItem->getAttributeId(); |
304 | 304 | } |
305 | 305 | |
@@ -307,22 +307,22 @@ discard block |
||
307 | 307 | $product->getProductId(), |
308 | 308 | $product->getQuantity(), |
309 | 309 | $product->getStockType(), |
310 | - $this->getValue( $attrIds, 'variant', [] ), |
|
311 | - $this->getValue( $attrIds, 'config', [] ), |
|
312 | - $this->getValue( $attrIds, 'hidden', [] ), |
|
313 | - $this->getValue( $attrIds, 'custom', [] ) |
|
310 | + $this->getValue($attrIds, 'variant', []), |
|
311 | + $this->getValue($attrIds, 'config', []), |
|
312 | + $this->getValue($attrIds, 'hidden', []), |
|
313 | + $this->getValue($attrIds, 'custom', []) |
|
314 | 314 | ); |
315 | 315 | |
316 | - $basket->deleteProduct( $pos ); |
|
316 | + $basket->deleteProduct($pos); |
|
317 | 317 | } |
318 | - catch( \Exception $e ) |
|
318 | + catch (\Exception $e) |
|
319 | 319 | { |
320 | 320 | $code = $product->getProductCode(); |
321 | 321 | $logger = $this->getContext()->getLogger(); |
322 | 322 | $errors['product'][$pos] = $e->getMessage(); |
323 | 323 | |
324 | 324 | $str = 'Error migrating product with code "%1$s" in basket to locale "%2$s": %3$s'; |
325 | - $logger->log( sprintf( $str, $code, $localeKey, $e->getMessage() ), \Aimeos\MW\Logger\Base::INFO ); |
|
325 | + $logger->log(sprintf($str, $code, $localeKey, $e->getMessage()), \Aimeos\MW\Logger\Base::INFO); |
|
326 | 326 | } |
327 | 327 | } |
328 | 328 | |
@@ -337,24 +337,24 @@ discard block |
||
337 | 337 | * @param array $errors Associative list of previous errors |
338 | 338 | * @return array Associative list of errors occured |
339 | 339 | */ |
340 | - protected function copyServices( \Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors ) |
|
340 | + protected function copyServices(\Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors) |
|
341 | 341 | { |
342 | - foreach( $basket->getServices() as $type => $list ) |
|
342 | + foreach ($basket->getServices() as $type => $list) |
|
343 | 343 | { |
344 | - foreach( $list as $item ) |
|
344 | + foreach ($list as $item) |
|
345 | 345 | { |
346 | 346 | try |
347 | 347 | { |
348 | 348 | $attributes = []; |
349 | 349 | |
350 | - foreach( $item->getAttributes() as $attrItem ) { |
|
350 | + foreach ($item->getAttributes() as $attrItem) { |
|
351 | 351 | $attributes[$attrItem->getCode()] = $attrItem->getValue(); |
352 | 352 | } |
353 | 353 | |
354 | - $this->addService( $type, $item->getServiceId(), $attributes ); |
|
355 | - $basket->deleteService( $type ); |
|
354 | + $this->addService($type, $item->getServiceId(), $attributes); |
|
355 | + $basket->deleteService($type); |
|
356 | 356 | } |
357 | - catch( \Exception $e ) { ; } // Don't notify the user as appropriate services can be added automatically |
|
357 | + catch (\Exception $e) {; } // Don't notify the user as appropriate services can be added automatically |
|
358 | 358 | } |
359 | 359 | } |
360 | 360 | |
@@ -374,35 +374,35 @@ discard block |
||
374 | 374 | * @return array List of items implementing \Aimeos\MShop\Order\Item\Product\Attribute\Iface |
375 | 375 | * @deprecated Use getOrderProductAttributes(), checkReferences() and calcPrice() instead |
376 | 376 | */ |
377 | - protected function createOrderProductAttributes( \Aimeos\MShop\Price\Item\Iface $price, $prodid, $quantity, |
|
378 | - array $attributeIds, $type, array $attributeValues = [] ) |
|
377 | + protected function createOrderProductAttributes(\Aimeos\MShop\Price\Item\Iface $price, $prodid, $quantity, |
|
378 | + array $attributeIds, $type, array $attributeValues = []) |
|
379 | 379 | { |
380 | - if( empty( $attributeIds ) ) { |
|
380 | + if (empty($attributeIds)) { |
|
381 | 381 | return []; |
382 | 382 | } |
383 | 383 | |
384 | 384 | $list = []; |
385 | 385 | $context = $this->getContext(); |
386 | - $attrTypeId = $this->getProductListTypeItem( 'attribute', $type )->getId(); |
|
387 | - $this->checkReferences( $prodid, 'attribute', $attrTypeId, $attributeIds ); |
|
386 | + $attrTypeId = $this->getProductListTypeItem('attribute', $type)->getId(); |
|
387 | + $this->checkReferences($prodid, 'attribute', $attrTypeId, $attributeIds); |
|
388 | 388 | |
389 | - $priceManager = \Aimeos\MShop\Factory::createManager( $context, 'price' ); |
|
390 | - $orderProductAttributeManager = \Aimeos\MShop\Factory::createManager( $context, 'order/base/product/attribute' ); |
|
389 | + $priceManager = \Aimeos\MShop\Factory::createManager($context, 'price'); |
|
390 | + $orderProductAttributeManager = \Aimeos\MShop\Factory::createManager($context, 'order/base/product/attribute'); |
|
391 | 391 | |
392 | - foreach( $this->getAttributes( $attributeIds ) as $id => $attrItem ) |
|
392 | + foreach ($this->getAttributes($attributeIds) as $id => $attrItem) |
|
393 | 393 | { |
394 | - $prices = $attrItem->getRefItems( 'price', 'default', 'default' ); |
|
394 | + $prices = $attrItem->getRefItems('price', 'default', 'default'); |
|
395 | 395 | |
396 | - if( !empty( $prices ) ) { |
|
397 | - $price->addItem( $priceManager->getLowestPrice( $prices, $quantity ) ); |
|
396 | + if (!empty($prices)) { |
|
397 | + $price->addItem($priceManager->getLowestPrice($prices, $quantity)); |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | $item = $orderProductAttributeManager->createItem(); |
401 | - $item->copyFrom( $attrItem ); |
|
402 | - $item->setType( $type ); |
|
401 | + $item->copyFrom($attrItem); |
|
402 | + $item->setType($type); |
|
403 | 403 | |
404 | - if( isset( $attributeValues[$id] ) ) { |
|
405 | - $item->setValue( $attributeValues[$id] ); |
|
404 | + if (isset($attributeValues[$id])) { |
|
405 | + $item->setValue($attributeValues[$id]); |
|
406 | 406 | } |
407 | 407 | |
408 | 408 | $list[] = $item; |
@@ -420,32 +420,32 @@ discard block |
||
420 | 420 | * @return array List of items implementing \Aimeos\MShop\Attribute\Item\Iface |
421 | 421 | * @throws \Aimeos\Controller\Frontend\Basket\Exception If the actual attribute number doesn't match the expected one |
422 | 422 | */ |
423 | - protected function getAttributes( array $attributeIds, array $domains = array( 'price', 'text' ) ) |
|
423 | + protected function getAttributes(array $attributeIds, array $domains = array('price', 'text')) |
|
424 | 424 | { |
425 | - if( empty( $attributeIds ) ) { |
|
425 | + if (empty($attributeIds)) { |
|
426 | 426 | return []; |
427 | 427 | } |
428 | 428 | |
429 | - $attributeManager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'attribute' ); |
|
429 | + $attributeManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'attribute'); |
|
430 | 430 | |
431 | - $search = $attributeManager->createSearch( true ); |
|
431 | + $search = $attributeManager->createSearch(true); |
|
432 | 432 | $expr = array( |
433 | - $search->compare( '==', 'attribute.id', $attributeIds ), |
|
433 | + $search->compare('==', 'attribute.id', $attributeIds), |
|
434 | 434 | $search->getConditions(), |
435 | 435 | ); |
436 | - $search->setConditions( $search->combine( '&&', $expr ) ); |
|
437 | - $search->setSlice( 0, 0x7fffffff ); |
|
436 | + $search->setConditions($search->combine('&&', $expr)); |
|
437 | + $search->setSlice(0, 0x7fffffff); |
|
438 | 438 | |
439 | - $attrItems = $attributeManager->searchItems( $search, $domains ); |
|
439 | + $attrItems = $attributeManager->searchItems($search, $domains); |
|
440 | 440 | |
441 | - if( count( $attrItems ) !== count( $attributeIds ) ) |
|
441 | + if (count($attrItems) !== count($attributeIds)) |
|
442 | 442 | { |
443 | 443 | $i18n = $this->getContext()->getI18n(); |
444 | - $expected = implode( ',', $attributeIds ); |
|
445 | - $actual = implode( ',', array_keys( $attrItems ) ); |
|
446 | - $msg = $i18n->dt( 'controller/frontend', 'Available attribute IDs "%1$s" do not match the given attribute IDs "%2$s"' ); |
|
444 | + $expected = implode(',', $attributeIds); |
|
445 | + $actual = implode(',', array_keys($attrItems)); |
|
446 | + $msg = $i18n->dt('controller/frontend', 'Available attribute IDs "%1$s" do not match the given attribute IDs "%2$s"'); |
|
447 | 447 | |
448 | - throw new \Aimeos\Controller\Frontend\Basket\Exception( sprintf( $msg, $actual, $expected ) ); |
|
448 | + throw new \Aimeos\Controller\Frontend\Basket\Exception(sprintf($msg, $actual, $expected)); |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | return $attrItems; |
@@ -458,31 +458,31 @@ discard block |
||
458 | 458 | * @param \Aimeos\MShop\Order\Item\Base\Product\Attribute\Item[] $orderAttributes List of order product attribute items |
459 | 459 | * @return \Aimeos\MShop\Attribute\Item\Iface[] Associative list of attribute IDs as key and attribute items as values |
460 | 460 | */ |
461 | - protected function getAttributeItems( array $orderAttributes ) |
|
461 | + protected function getAttributeItems(array $orderAttributes) |
|
462 | 462 | { |
463 | - if( empty( $orderAttributes ) ) { |
|
463 | + if (empty($orderAttributes)) { |
|
464 | 464 | return []; |
465 | 465 | } |
466 | 466 | |
467 | - $attributeManager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'attribute' ); |
|
468 | - $search = $attributeManager->createSearch( true ); |
|
467 | + $attributeManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'attribute'); |
|
468 | + $search = $attributeManager->createSearch(true); |
|
469 | 469 | $expr = []; |
470 | 470 | |
471 | - foreach( $orderAttributes as $item ) |
|
471 | + foreach ($orderAttributes as $item) |
|
472 | 472 | { |
473 | 473 | $tmp = array( |
474 | - $search->compare( '==', 'attribute.domain', 'product' ), |
|
475 | - $search->compare( '==', 'attribute.code', $item->getValue() ), |
|
476 | - $search->compare( '==', 'attribute.type.domain', 'product' ), |
|
477 | - $search->compare( '==', 'attribute.type.code', $item->getCode() ), |
|
478 | - $search->compare( '>', 'attribute.type.status', 0 ), |
|
474 | + $search->compare('==', 'attribute.domain', 'product'), |
|
475 | + $search->compare('==', 'attribute.code', $item->getValue()), |
|
476 | + $search->compare('==', 'attribute.type.domain', 'product'), |
|
477 | + $search->compare('==', 'attribute.type.code', $item->getCode()), |
|
478 | + $search->compare('>', 'attribute.type.status', 0), |
|
479 | 479 | $search->getConditions(), |
480 | 480 | ); |
481 | - $expr[] = $search->combine( '&&', $tmp ); |
|
481 | + $expr[] = $search->combine('&&', $tmp); |
|
482 | 482 | } |
483 | 483 | |
484 | - $search->setConditions( $search->combine( '||', $expr ) ); |
|
485 | - return $attributeManager->searchItems( $search, array( 'price' ) ); |
|
484 | + $search->setConditions($search->combine('||', $expr)); |
|
485 | + return $attributeManager->searchItems($search, array('price')); |
|
486 | 486 | } |
487 | 487 | |
488 | 488 | |
@@ -497,24 +497,24 @@ discard block |
||
497 | 497 | * @throws \Aimeos\Controller\Frontend\Basket\Exception |
498 | 498 | * @deprecated Use getItem() or findItem() instead |
499 | 499 | */ |
500 | - protected function getDomainItem( $domain, $key, $value, array $ref ) |
|
500 | + protected function getDomainItem($domain, $key, $value, array $ref) |
|
501 | 501 | { |
502 | 502 | $context = $this->getContext(); |
503 | - $manager = \Aimeos\MShop\Factory::createManager( $context, $domain ); |
|
503 | + $manager = \Aimeos\MShop\Factory::createManager($context, $domain); |
|
504 | 504 | |
505 | - $search = $manager->createSearch( true ); |
|
505 | + $search = $manager->createSearch(true); |
|
506 | 506 | $expr = array( |
507 | - $search->compare( '==', $key, $value ), |
|
507 | + $search->compare('==', $key, $value), |
|
508 | 508 | $search->getConditions(), |
509 | 509 | ); |
510 | - $search->setConditions( $search->combine( '&&', $expr ) ); |
|
510 | + $search->setConditions($search->combine('&&', $expr)); |
|
511 | 511 | |
512 | - $result = $manager->searchItems( $search, $ref ); |
|
512 | + $result = $manager->searchItems($search, $ref); |
|
513 | 513 | |
514 | - if( ( $item = reset( $result ) ) === false ) |
|
514 | + if (($item = reset($result)) === false) |
|
515 | 515 | { |
516 | - $msg = $context->getI18n()->dt( 'controller/frontend', 'No item for "%1$s" (%2$s) found' ); |
|
517 | - throw new \Aimeos\Controller\Frontend\Basket\Exception( sprintf( $msg, $value, $key ) ); |
|
516 | + $msg = $context->getI18n()->dt('controller/frontend', 'No item for "%1$s" (%2$s) found'); |
|
517 | + throw new \Aimeos\Controller\Frontend\Basket\Exception(sprintf($msg, $value, $key)); |
|
518 | 518 | } |
519 | 519 | |
520 | 520 | return $item; |
@@ -530,24 +530,24 @@ discard block |
||
530 | 530 | * @param array $quantities Associative list of attribute IDs as keys and their quantities as values |
531 | 531 | * @return array List of items implementing \Aimeos\MShop\Order\Item\Product\Attribute\Iface |
532 | 532 | */ |
533 | - protected function getOrderProductAttributes( $type, array $ids, array $values = [], array $quantities = [] ) |
|
533 | + protected function getOrderProductAttributes($type, array $ids, array $values = [], array $quantities = []) |
|
534 | 534 | { |
535 | - if( empty( $ids ) ) { |
|
535 | + if (empty($ids)) { |
|
536 | 536 | return []; |
537 | 537 | } |
538 | 538 | |
539 | 539 | $list = []; |
540 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'order/base/product/attribute' ); |
|
540 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'order/base/product/attribute'); |
|
541 | 541 | |
542 | - foreach( $this->getAttributes( $ids ) as $id => $attrItem ) |
|
542 | + foreach ($this->getAttributes($ids) as $id => $attrItem) |
|
543 | 543 | { |
544 | 544 | $item = $manager->createItem(); |
545 | - $item->copyFrom( $attrItem ); |
|
546 | - $item->setType( $type ); |
|
547 | - $item->setQuantity( isset( $quantities[$id] ) ? $quantities[$id] : 1 ); |
|
545 | + $item->copyFrom($attrItem); |
|
546 | + $item->setType($type); |
|
547 | + $item->setQuantity(isset($quantities[$id]) ? $quantities[$id] : 1); |
|
548 | 548 | |
549 | - if( isset( $values[$id] ) ) { |
|
550 | - $item->setValue( $values[$id] ); |
|
549 | + if (isset($values[$id])) { |
|
550 | + $item->setValue($values[$id]); |
|
551 | 551 | } |
552 | 552 | |
553 | 553 | $list[] = $item; |
@@ -564,23 +564,23 @@ discard block |
||
564 | 564 | * @param string $code Code of the list type |
565 | 565 | * @return \Aimeos\MShop\Common\Item\Type\Iface List type item |
566 | 566 | */ |
567 | - protected function getProductListTypeItem( $domain, $code ) |
|
567 | + protected function getProductListTypeItem($domain, $code) |
|
568 | 568 | { |
569 | 569 | $context = $this->getContext(); |
570 | 570 | |
571 | - if( empty( $this->listTypeItems ) ) |
|
571 | + if (empty($this->listTypeItems)) |
|
572 | 572 | { |
573 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'product/lists/type' ); |
|
573 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'product/lists/type'); |
|
574 | 574 | |
575 | - foreach( $manager->searchItems( $manager->createSearch( true ) ) as $item ) { |
|
576 | - $this->listTypeItems[ $item->getDomain() ][ $item->getCode() ] = $item; |
|
575 | + foreach ($manager->searchItems($manager->createSearch(true)) as $item) { |
|
576 | + $this->listTypeItems[$item->getDomain()][$item->getCode()] = $item; |
|
577 | 577 | } |
578 | 578 | } |
579 | 579 | |
580 | - if( !isset( $this->listTypeItems[$domain][$code] ) ) |
|
580 | + if (!isset($this->listTypeItems[$domain][$code])) |
|
581 | 581 | { |
582 | - $msg = $context->getI18n()->dt( 'controller/frontend', 'List type for domain "%1$s" and code "%2$s" not found' ); |
|
583 | - throw new \Aimeos\Controller\Frontend\Basket\Exception( sprintf( $msg, $domain, $code ) ); |
|
582 | + $msg = $context->getI18n()->dt('controller/frontend', 'List type for domain "%1$s" and code "%2$s" not found'); |
|
583 | + throw new \Aimeos\Controller\Frontend\Basket\Exception(sprintf($msg, $domain, $code)); |
|
584 | 584 | } |
585 | 585 | |
586 | 586 | return $this->listTypeItems[$domain][$code]; |
@@ -595,43 +595,43 @@ discard block |
||
595 | 595 | * @param array $domains Names of the domain items that should be fetched too |
596 | 596 | * @return array List of products matching the given attributes |
597 | 597 | */ |
598 | - protected function getProductVariants( \Aimeos\MShop\Product\Item\Iface $productItem, array $variantAttributeIds, |
|
599 | - array $domains = array( 'attribute', 'media', 'price', 'text' ) ) |
|
598 | + protected function getProductVariants(\Aimeos\MShop\Product\Item\Iface $productItem, array $variantAttributeIds, |
|
599 | + array $domains = array('attribute', 'media', 'price', 'text')) |
|
600 | 600 | { |
601 | 601 | $subProductIds = []; |
602 | - foreach( $productItem->getRefItems( 'product', 'default', 'default' ) as $item ) { |
|
602 | + foreach ($productItem->getRefItems('product', 'default', 'default') as $item) { |
|
603 | 603 | $subProductIds[] = $item->getId(); |
604 | 604 | } |
605 | 605 | |
606 | - if( count( $subProductIds ) === 0 ) { |
|
606 | + if (count($subProductIds) === 0) { |
|
607 | 607 | return []; |
608 | 608 | } |
609 | 609 | |
610 | - $productManager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product' ); |
|
611 | - $search = $productManager->createSearch( true ); |
|
610 | + $productManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product'); |
|
611 | + $search = $productManager->createSearch(true); |
|
612 | 612 | |
613 | 613 | $expr = array( |
614 | - $search->compare( '==', 'product.id', $subProductIds ), |
|
614 | + $search->compare('==', 'product.id', $subProductIds), |
|
615 | 615 | $search->getConditions(), |
616 | 616 | ); |
617 | 617 | |
618 | - if( count( $variantAttributeIds ) > 0 ) |
|
618 | + if (count($variantAttributeIds) > 0) |
|
619 | 619 | { |
620 | - foreach( $variantAttributeIds as $key => $id ) { |
|
620 | + foreach ($variantAttributeIds as $key => $id) { |
|
621 | 621 | $variantAttributeIds[$key] = (string) $id; |
622 | 622 | } |
623 | 623 | |
624 | - $listTypeItem = $this->getProductListTypeItem( 'attribute', 'variant' ); |
|
624 | + $listTypeItem = $this->getProductListTypeItem('attribute', 'variant'); |
|
625 | 625 | |
626 | - $param = array( 'attribute', $listTypeItem->getId(), $variantAttributeIds ); |
|
627 | - $cmpfunc = $search->createFunction( 'product.contains', $param ); |
|
626 | + $param = array('attribute', $listTypeItem->getId(), $variantAttributeIds); |
|
627 | + $cmpfunc = $search->createFunction('product.contains', $param); |
|
628 | 628 | |
629 | - $expr[] = $search->compare( '==', $cmpfunc, count( $variantAttributeIds ) ); |
|
629 | + $expr[] = $search->compare('==', $cmpfunc, count($variantAttributeIds)); |
|
630 | 630 | } |
631 | 631 | |
632 | - $search->setConditions( $search->combine( '&&', $expr ) ); |
|
632 | + $search->setConditions($search->combine('&&', $expr)); |
|
633 | 633 | |
634 | - return $productManager->searchItems( $search, $domains ); |
|
634 | + return $productManager->searchItems($search, $domains); |
|
635 | 635 | } |
636 | 636 | |
637 | 637 | |
@@ -643,9 +643,9 @@ discard block |
||
643 | 643 | * @param mixed $default Default value if no value is available for the given name |
644 | 644 | * @return mixed Value from the array or default value |
645 | 645 | */ |
646 | - protected function getValue( array $values, $name, $default = null ) |
|
646 | + protected function getValue(array $values, $name, $default = null) |
|
647 | 647 | { |
648 | - if( isset( $values[$name] ) ) { |
|
648 | + if (isset($values[$name])) { |
|
649 | 649 | return $values[$name]; |
650 | 650 | } |
651 | 651 |
@@ -233,8 +233,7 @@ discard block |
||
233 | 233 | { |
234 | 234 | $this->setAddress( $type, $item->toArray() ); |
235 | 235 | $basket->deleteAddress( $type ); |
236 | - } |
|
237 | - catch( \Exception $e ) |
|
236 | + } catch( \Exception $e ) |
|
238 | 237 | { |
239 | 238 | $logger = $this->getContext()->getLogger(); |
240 | 239 | $errors['address'][$type] = $e->getMessage(); |
@@ -264,8 +263,7 @@ discard block |
||
264 | 263 | { |
265 | 264 | $this->addCoupon( $code ); |
266 | 265 | $basket->deleteCoupon( $code, true ); |
267 | - } |
|
268 | - catch( \Exception $e ) |
|
266 | + } catch( \Exception $e ) |
|
269 | 267 | { |
270 | 268 | $logger = $this->getContext()->getLogger(); |
271 | 269 | $errors['coupon'][$code] = $e->getMessage(); |
@@ -314,8 +312,7 @@ discard block |
||
314 | 312 | ); |
315 | 313 | |
316 | 314 | $basket->deleteProduct( $pos ); |
317 | - } |
|
318 | - catch( \Exception $e ) |
|
315 | + } catch( \Exception $e ) |
|
319 | 316 | { |
320 | 317 | $code = $product->getProductCode(); |
321 | 318 | $logger = $this->getContext()->getLogger(); |
@@ -353,8 +350,7 @@ discard block |
||
353 | 350 | |
354 | 351 | $this->addService( $type, $item->getServiceId(), $attributes ); |
355 | 352 | $basket->deleteService( $type ); |
356 | - } |
|
357 | - catch( \Exception $e ) { ; } // Don't notify the user as appropriate services can be added automatically |
|
353 | + } catch( \Exception $e ) { ; } // Don't notify the user as appropriate services can be added automatically |
|
358 | 354 | } |
359 | 355 | } |
360 | 356 |