@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public function getName() |
30 | 30 | { |
31 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Subscription process renew' ); |
|
31 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Subscription process renew'); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function getDescription() |
41 | 41 | { |
42 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Renews subscriptions at next date' ); |
|
42 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Renews subscriptions at next date'); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | |
@@ -54,73 +54,73 @@ discard block |
||
54 | 54 | $config = $context->getConfig(); |
55 | 55 | $logger = $context->getLogger(); |
56 | 56 | |
57 | - $names = (array) $config->get( 'controller/common/subscription/process/processors', [] ); |
|
57 | + $names = (array) $config->get('controller/common/subscription/process/processors', []); |
|
58 | 58 | |
59 | - $date = date( 'Y-m-d' ); |
|
60 | - $processors = $this->getProcessors( $names ); |
|
61 | - $manager = \Aimeos\MShop::create( $context, 'subscription' ); |
|
59 | + $date = date('Y-m-d'); |
|
60 | + $processors = $this->getProcessors($names); |
|
61 | + $manager = \Aimeos\MShop::create($context, 'subscription'); |
|
62 | 62 | |
63 | - $search = $manager->createSearch( true ); |
|
63 | + $search = $manager->createSearch(true); |
|
64 | 64 | $expr = [ |
65 | - $search->compare( '<=', 'subscription.datenext', $date ), |
|
66 | - $search->combine( '||', [ |
|
67 | - $search->compare( '==', 'subscription.dateend', null ), |
|
68 | - $search->compare( '>', 'subscription.dateend', $date ), |
|
69 | - ] ), |
|
65 | + $search->compare('<=', 'subscription.datenext', $date), |
|
66 | + $search->combine('||', [ |
|
67 | + $search->compare('==', 'subscription.dateend', null), |
|
68 | + $search->compare('>', 'subscription.dateend', $date), |
|
69 | + ]), |
|
70 | 70 | $search->getConditions(), |
71 | 71 | ]; |
72 | - $search->setConditions( $search->combine( '&&', $expr ) ); |
|
73 | - $search->setSortations( [$search->sort( '+', 'subscription.id' )] ); |
|
72 | + $search->setConditions($search->combine('&&', $expr)); |
|
73 | + $search->setSortations([$search->sort('+', 'subscription.id')]); |
|
74 | 74 | |
75 | 75 | $start = 0; |
76 | 76 | |
77 | 77 | do |
78 | 78 | { |
79 | - $search->setSlice( $start, 100 ); |
|
80 | - $items = $manager->searchItems( $search ); |
|
79 | + $search->setSlice($start, 100); |
|
80 | + $items = $manager->searchItems($search); |
|
81 | 81 | |
82 | - foreach( $items as $item ) |
|
82 | + foreach ($items as $item) |
|
83 | 83 | { |
84 | 84 | try |
85 | 85 | { |
86 | - $context = $this->createContext( $item->getOrderBaseId() ); |
|
87 | - $newOrder = $this->createOrderBase( $context, $item ); |
|
88 | - $newInvoice = $this->createOrderInvoice( $context, $newOrder ); |
|
86 | + $context = $this->createContext($item->getOrderBaseId()); |
|
87 | + $newOrder = $this->createOrderBase($context, $item); |
|
88 | + $newInvoice = $this->createOrderInvoice($context, $newOrder); |
|
89 | 89 | |
90 | 90 | try |
91 | 91 | { |
92 | - $this->createPayment( $context, $newOrder, $newInvoice ); |
|
92 | + $this->createPayment($context, $newOrder, $newInvoice); |
|
93 | 93 | |
94 | - $interval = new \DateInterval( $item->getInterval() ); |
|
95 | - $item->setDateNext( date_create()->add( $interval )->format( 'Y-m-d' ) ); |
|
94 | + $interval = new \DateInterval($item->getInterval()); |
|
95 | + $item->setDateNext(date_create()->add($interval)->format('Y-m-d')); |
|
96 | 96 | } |
97 | - catch( \Exception $e ) |
|
97 | + catch (\Exception $e) |
|
98 | 98 | { |
99 | - $item->setReason( \Aimeos\MShop\Subscription\Item\Iface::REASON_PAYMENT ); |
|
100 | - $item->setDateEnd( date_create()->format( 'Y-m-d' ) ); |
|
101 | - $manager->saveItem( $item ); |
|
99 | + $item->setReason(\Aimeos\MShop\Subscription\Item\Iface::REASON_PAYMENT); |
|
100 | + $item->setDateEnd(date_create()->format('Y-m-d')); |
|
101 | + $manager->saveItem($item); |
|
102 | 102 | |
103 | 103 | throw $e; |
104 | 104 | } |
105 | 105 | |
106 | - $manager->saveItem( $item ); |
|
106 | + $manager->saveItem($item); |
|
107 | 107 | |
108 | - foreach( $processors as $processor ) { |
|
109 | - $processor->renew( $item, $newInvoice ); |
|
108 | + foreach ($processors as $processor) { |
|
109 | + $processor->renew($item, $newInvoice); |
|
110 | 110 | } |
111 | 111 | } |
112 | - catch( \Exception $e ) |
|
112 | + catch (\Exception $e) |
|
113 | 113 | { |
114 | 114 | $msg = 'Unable to process subscription with ID "%1$s": %2$s'; |
115 | - $logger->log( sprintf( $msg, $item->getId(), $e->getMessage() ) ); |
|
116 | - $logger->log( $e->getTraceAsString() ); |
|
115 | + $logger->log(sprintf($msg, $item->getId(), $e->getMessage())); |
|
116 | + $logger->log($e->getTraceAsString()); |
|
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
120 | - $count = count( $items ); |
|
120 | + $count = count($items); |
|
121 | 121 | $start += $count; |
122 | 122 | } |
123 | - while( $count === $search->getSliceSize() ); |
|
123 | + while ($count === $search->getSliceSize()); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | |
@@ -132,11 +132,11 @@ discard block |
||
132 | 132 | * @param array $addresses Associative list of type as key and address object implementing \Aimeos\MShop\Order\Item\Base\Address\Iface as value |
133 | 133 | * @return \Aimeos\MShop\Order\Item\Base\Iface Order with addresses added |
134 | 134 | */ |
135 | - protected function addBasketAddresses( \Aimeos\MShop\Context\Item\Iface $context, |
|
136 | - \Aimeos\MShop\Order\Item\Base\Iface $newBasket, array $addresses ) |
|
135 | + protected function addBasketAddresses(\Aimeos\MShop\Context\Item\Iface $context, |
|
136 | + \Aimeos\MShop\Order\Item\Base\Iface $newBasket, array $addresses) |
|
137 | 137 | { |
138 | - foreach( $addresses as $type => $orderAddress ) { |
|
139 | - $newBasket->setAddress( $orderAddress, $type ); |
|
138 | + foreach ($addresses as $type => $orderAddress) { |
|
139 | + $newBasket->setAddress($orderAddress, $type); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | return $newBasket; |
@@ -151,8 +151,8 @@ discard block |
||
151 | 151 | * @param array $codes List of coupon codes that should be added to the given basket |
152 | 152 | * @return \Aimeos\MShop\Order\Item\Base\Iface Basket, maybe with coupons added |
153 | 153 | */ |
154 | - protected function addBasketCoupons( \Aimeos\MShop\Context\Item\Iface $context, |
|
155 | - \Aimeos\MShop\Order\Item\Base\Iface $basket, array $codes ) |
|
154 | + protected function addBasketCoupons(\Aimeos\MShop\Context\Item\Iface $context, |
|
155 | + \Aimeos\MShop\Order\Item\Base\Iface $basket, array $codes) |
|
156 | 156 | { |
157 | 157 | /** controller/jobs/subcription/process/renew/standard/use-coupons |
158 | 158 | * |
@@ -166,34 +166,34 @@ discard block |
||
166 | 166 | * @category User |
167 | 167 | * @since 2018.10 |
168 | 168 | */ |
169 | - if( $context->getConfig()->get( 'controller/jobs/subcription/process/renew/standard/use-coupons', false ) ) |
|
169 | + if ($context->getConfig()->get('controller/jobs/subcription/process/renew/standard/use-coupons', false)) |
|
170 | 170 | { |
171 | - $manager = \Aimeos\MShop::create( $context, 'coupon' ); |
|
172 | - $codeManager = \Aimeos\MShop::create( $context, 'coupon/code' ); |
|
171 | + $manager = \Aimeos\MShop::create($context, 'coupon'); |
|
172 | + $codeManager = \Aimeos\MShop::create($context, 'coupon/code'); |
|
173 | 173 | |
174 | - foreach( $codes as $code ) |
|
174 | + foreach ($codes as $code) |
|
175 | 175 | { |
176 | - $search = $manager->createSearch( true )->setSlice( 0, 1 ); |
|
176 | + $search = $manager->createSearch(true)->setSlice(0, 1); |
|
177 | 177 | $expr = [ |
178 | - $search->compare( '==', 'coupon.code.code', $code ), |
|
179 | - $codeManager->createSearch( true )->getConditions(), |
|
178 | + $search->compare('==', 'coupon.code.code', $code), |
|
179 | + $codeManager->createSearch(true)->getConditions(), |
|
180 | 180 | $search->getConditions(), |
181 | 181 | ]; |
182 | - $search->setConditions( $search->combine( '&&', $expr ) ); |
|
182 | + $search->setConditions($search->combine('&&', $expr)); |
|
183 | 183 | |
184 | - $result = $manager->searchItems( $search ); |
|
184 | + $result = $manager->searchItems($search); |
|
185 | 185 | |
186 | - if( ( $item = reset( $result ) ) === false ) { |
|
186 | + if (($item = reset($result)) === false) { |
|
187 | 187 | continue; |
188 | 188 | } |
189 | 189 | |
190 | - $provider = $manager->getProvider( $item, $code ); |
|
190 | + $provider = $manager->getProvider($item, $code); |
|
191 | 191 | |
192 | - if( $provider->isAvailable( $basket ) !== true ) { |
|
192 | + if ($provider->isAvailable($basket) !== true) { |
|
193 | 193 | continue; |
194 | 194 | } |
195 | 195 | |
196 | - $provider->addCoupon( $basket ); |
|
196 | + $provider->addCoupon($basket); |
|
197 | 197 | } |
198 | 198 | } |
199 | 199 | |
@@ -210,17 +210,17 @@ discard block |
||
210 | 210 | * @param string $orderProductId Unique ID of the ordered subscription product |
211 | 211 | * @return \Aimeos\MShop\Order\Item\Base\Iface Order with products added |
212 | 212 | */ |
213 | - protected function addBasketProducts( \Aimeos\MShop\Context\Item\Iface $context, |
|
214 | - \Aimeos\MShop\Order\Item\Base\Iface $newBasket, array $orderProducts, $orderProductId ) |
|
213 | + protected function addBasketProducts(\Aimeos\MShop\Context\Item\Iface $context, |
|
214 | + \Aimeos\MShop\Order\Item\Base\Iface $newBasket, array $orderProducts, $orderProductId) |
|
215 | 215 | { |
216 | - foreach( $orderProducts as $orderProduct ) |
|
216 | + foreach ($orderProducts as $orderProduct) |
|
217 | 217 | { |
218 | - if( $orderProduct->getId() == $orderProductId ) |
|
218 | + if ($orderProduct->getId() == $orderProductId) |
|
219 | 219 | { |
220 | - foreach( $orderProduct->getAttributeItems() as $attrItem ) { |
|
221 | - $attrItem->setId( null ); |
|
220 | + foreach ($orderProduct->getAttributeItems() as $attrItem) { |
|
221 | + $attrItem->setId(null); |
|
222 | 222 | } |
223 | - $newBasket->addProduct( $orderProduct->setId( null ) ); |
|
223 | + $newBasket->addProduct($orderProduct->setId(null)); |
|
224 | 224 | } |
225 | 225 | } |
226 | 226 | |
@@ -236,35 +236,35 @@ discard block |
||
236 | 236 | * @param array $services Associative list of type as key and list of service objects implementing \Aimeos\MShop\Order\Item\Base\Service\Iface as values |
237 | 237 | * @return \Aimeos\MShop\Order\Item\Base\Iface Order with delivery and payment service added |
238 | 238 | */ |
239 | - protected function addBasketServices( \Aimeos\MShop\Context\Item\Iface $context, |
|
240 | - \Aimeos\MShop\Order\Item\Base\Iface $newBasket, array $services ) |
|
239 | + protected function addBasketServices(\Aimeos\MShop\Context\Item\Iface $context, |
|
240 | + \Aimeos\MShop\Order\Item\Base\Iface $newBasket, array $services) |
|
241 | 241 | { |
242 | 242 | $type = \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT; |
243 | 243 | |
244 | - if( isset( $services[$type] ) ) |
|
244 | + if (isset($services[$type])) |
|
245 | 245 | { |
246 | - foreach( $services[$type] as $orderService ) { |
|
247 | - $newBasket->addService( $orderService, $type ); |
|
246 | + foreach ($services[$type] as $orderService) { |
|
247 | + $newBasket->addService($orderService, $type); |
|
248 | 248 | } |
249 | 249 | } |
250 | 250 | |
251 | 251 | $type = \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_DELIVERY; |
252 | 252 | |
253 | - $serviceManager = \Aimeos\MShop::create( $context, 'service' ); |
|
254 | - $orderServiceManager = \Aimeos\MShop::create( $context, 'order/base/service' ); |
|
253 | + $serviceManager = \Aimeos\MShop::create($context, 'service'); |
|
254 | + $orderServiceManager = \Aimeos\MShop::create($context, 'order/base/service'); |
|
255 | 255 | |
256 | - $search = $serviceManager->createSearch( true ); |
|
257 | - $search->setSortations( [$search->sort( '+', 'service.position' )] ); |
|
258 | - $search->setConditions( $search->compare( '==', 'service.type', $type ) ); |
|
256 | + $search = $serviceManager->createSearch(true); |
|
257 | + $search->setSortations([$search->sort('+', 'service.position')]); |
|
258 | + $search->setConditions($search->compare('==', 'service.type', $type)); |
|
259 | 259 | |
260 | - foreach( $serviceManager->searchItems( $search, ['media', 'price', 'text'] ) as $item ) |
|
260 | + foreach ($serviceManager->searchItems($search, ['media', 'price', 'text']) as $item) |
|
261 | 261 | { |
262 | - $provider = $serviceManager->getProvider( $item, $item->getType() ); |
|
262 | + $provider = $serviceManager->getProvider($item, $item->getType()); |
|
263 | 263 | |
264 | - if( $provider->isAvailable( $newBasket ) === true ) |
|
264 | + if ($provider->isAvailable($newBasket) === true) |
|
265 | 265 | { |
266 | - $orderServiceItem = $orderServiceManager->createItem()->copyFrom( $item ); |
|
267 | - return $newBasket->addService( $orderServiceItem, $type ); |
|
266 | + $orderServiceItem = $orderServiceManager->createItem()->copyFrom($item); |
|
267 | + return $newBasket->addService($orderServiceItem, $type); |
|
268 | 268 | } |
269 | 269 | } |
270 | 270 | |
@@ -278,30 +278,30 @@ discard block |
||
278 | 278 | * @param string $baseId Unique order base ID |
279 | 279 | * @return \Aimeos\MShop\Context\Item\Iface New context object |
280 | 280 | */ |
281 | - protected function createContext( $baseId ) |
|
281 | + protected function createContext($baseId) |
|
282 | 282 | { |
283 | 283 | $context = clone $this->getContext(); |
284 | 284 | |
285 | - $manager = \Aimeos\MShop::create( $context, 'order/base' ); |
|
286 | - $baseItem = $manager->getItem( $baseId ); |
|
285 | + $manager = \Aimeos\MShop::create($context, 'order/base'); |
|
286 | + $baseItem = $manager->getItem($baseId); |
|
287 | 287 | |
288 | 288 | $locale = $baseItem->getLocale(); |
289 | 289 | $level = \Aimeos\MShop\Locale\Manager\Base::SITE_ALL; |
290 | 290 | |
291 | - $manager = \Aimeos\MShop::create( $context, 'locale' ); |
|
292 | - $locale = $manager->bootstrap( $baseItem->getSiteCode(), $locale->getLanguageId(), $locale->getCurrencyId(), false, $level ); |
|
291 | + $manager = \Aimeos\MShop::create($context, 'locale'); |
|
292 | + $locale = $manager->bootstrap($baseItem->getSiteCode(), $locale->getLanguageId(), $locale->getCurrencyId(), false, $level); |
|
293 | 293 | |
294 | - $context->setLocale( $locale ); |
|
294 | + $context->setLocale($locale); |
|
295 | 295 | |
296 | 296 | try |
297 | 297 | { |
298 | - $manager = \Aimeos\MShop::create( $context, 'customer' ); |
|
299 | - $customerItem = $manager->getItem( $baseItem->getCustomerId(), ['customer/group'] ); |
|
298 | + $manager = \Aimeos\MShop::create($context, 'customer'); |
|
299 | + $customerItem = $manager->getItem($baseItem->getCustomerId(), ['customer/group']); |
|
300 | 300 | |
301 | - $context->setUserId( $baseItem->getCustomerId() ); |
|
302 | - $context->setGroupIds( $customerItem->getGroups() ); |
|
301 | + $context->setUserId($baseItem->getCustomerId()); |
|
302 | + $context->setGroupIds($customerItem->getGroups()); |
|
303 | 303 | } |
304 | - catch( \Exception $e ) {} // Subscription without account |
|
304 | + catch (\Exception $e) {} // Subscription without account |
|
305 | 305 | |
306 | 306 | return $context; |
307 | 307 | } |
@@ -314,19 +314,19 @@ discard block |
||
314 | 314 | * @param \Aimeos\MShop\Subscription\Item\Iface $subscription Subscription item with order base ID and order product ID |
315 | 315 | * @return \Aimeos\MShop\Order\Item\Base\Iface Complete order with product, addresses and services saved to the storage |
316 | 316 | */ |
317 | - protected function createOrderBase( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Subscription\Item\Iface $subscription ) |
|
317 | + protected function createOrderBase(\Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Subscription\Item\Iface $subscription) |
|
318 | 318 | { |
319 | - $manager = \Aimeos\MShop::create( $context, 'order/base' ); |
|
319 | + $manager = \Aimeos\MShop::create($context, 'order/base'); |
|
320 | 320 | |
321 | - $basket = $manager->load( $subscription->getOrderBaseId() ); |
|
322 | - $newBasket = $manager->createItem()->setCustomerId( $basket->getCustomerId() ); |
|
321 | + $basket = $manager->load($subscription->getOrderBaseId()); |
|
322 | + $newBasket = $manager->createItem()->setCustomerId($basket->getCustomerId()); |
|
323 | 323 | |
324 | - $newBasket = $this->addBasketProducts( $context, $newBasket, $basket->getProducts(), $subscription->getOrderProductId() ); |
|
325 | - $newBasket = $this->addBasketAddresses( $context, $newBasket, $basket->getAddresses() ); |
|
326 | - $newBasket = $this->addBasketServices( $context, $newBasket, $basket->getServices() ); |
|
327 | - $newBasket = $this->addBasketCoupons( $context, $newBasket, array_keys( $basket->getCoupons() ) ); |
|
324 | + $newBasket = $this->addBasketProducts($context, $newBasket, $basket->getProducts(), $subscription->getOrderProductId()); |
|
325 | + $newBasket = $this->addBasketAddresses($context, $newBasket, $basket->getAddresses()); |
|
326 | + $newBasket = $this->addBasketServices($context, $newBasket, $basket->getServices()); |
|
327 | + $newBasket = $this->addBasketCoupons($context, $newBasket, array_keys($basket->getCoupons())); |
|
328 | 328 | |
329 | - return $manager->store( $newBasket ); |
|
329 | + return $manager->store($newBasket); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | |
@@ -337,15 +337,15 @@ discard block |
||
337 | 337 | * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Complete order with product, addresses and services saved to the storage |
338 | 338 | * @return \Aimeos\MShop\Order\Item\Iface New invoice item associated to the order saved to the storage |
339 | 339 | */ |
340 | - protected function createOrderInvoice( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Order\Item\Base\Iface $basket ) |
|
340 | + protected function createOrderInvoice(\Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Order\Item\Base\Iface $basket) |
|
341 | 341 | { |
342 | - $manager = \Aimeos\MShop::create( $context, 'order' ); |
|
342 | + $manager = \Aimeos\MShop::create($context, 'order'); |
|
343 | 343 | |
344 | 344 | $item = $manager->createItem(); |
345 | - $item->setBaseId( $basket->getId() ); |
|
346 | - $item->setType( 'subscription' ); |
|
345 | + $item->setBaseId($basket->getId()); |
|
346 | + $item->setType('subscription'); |
|
347 | 347 | |
348 | - return $manager->saveItem( $item ); |
|
348 | + return $manager->saveItem($item); |
|
349 | 349 | } |
350 | 350 | |
351 | 351 | |
@@ -356,17 +356,17 @@ discard block |
||
356 | 356 | * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Complete order with product, addresses and services |
357 | 357 | * @param \Aimeos\MShop\Order\Item\Iface New invoice item associated to the order |
358 | 358 | */ |
359 | - protected function createPayment( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Order\Item\Base\Iface $basket, |
|
360 | - \Aimeos\MShop\Order\Item\Iface $invoice ) |
|
359 | + protected function createPayment(\Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Order\Item\Base\Iface $basket, |
|
360 | + \Aimeos\MShop\Order\Item\Iface $invoice) |
|
361 | 361 | { |
362 | - $manager = \Aimeos\MShop::create( $context, 'service' ); |
|
362 | + $manager = \Aimeos\MShop::create($context, 'service'); |
|
363 | 363 | |
364 | - foreach( $basket->getService( \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT ) as $service ) |
|
364 | + foreach ($basket->getService(\Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT) as $service) |
|
365 | 365 | { |
366 | - $item = $manager->getItem( $service->getServiceId() ); |
|
367 | - $provider = $manager->getProvider( $item, 'payment' ); |
|
366 | + $item = $manager->getItem($service->getServiceId()); |
|
367 | + $provider = $manager->getProvider($item, 'payment'); |
|
368 | 368 | |
369 | - $provider->repay( $invoice ); |
|
369 | + $provider->repay($invoice); |
|
370 | 370 | } |
371 | 371 | } |
372 | 372 | } |