@@ -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\Factory::createManager( $context, 'subscription' ); |
|
59 | + $date = date('Y-m-d'); |
|
60 | + $processors = $this->getProcessors($names); |
|
61 | + $manager = \Aimeos\MShop\Factory::createManager($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 | |
@@ -130,30 +130,30 @@ discard block |
||
130 | 130 | * @param string $baseId Unique order base ID |
131 | 131 | * @return \Aimeos\MShop\Context\Item\Iface New context object |
132 | 132 | */ |
133 | - protected function createContext( $baseId ) |
|
133 | + protected function createContext($baseId) |
|
134 | 134 | { |
135 | 135 | $context = clone $this->getContext(); |
136 | 136 | |
137 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'order/base' ); |
|
138 | - $baseItem = $manager->getItem( $baseId ); |
|
137 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'order/base'); |
|
138 | + $baseItem = $manager->getItem($baseId); |
|
139 | 139 | |
140 | 140 | $locale = $baseItem->getLocale(); |
141 | 141 | $level = \Aimeos\MShop\Locale\Manager\Base::SITE_ALL; |
142 | 142 | |
143 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'locale' ); |
|
144 | - $locale = $manager->bootstrap( $baseItem->getSiteCode(), $locale->getLanguageId(), $locale->getCurrencyId(), false, $level ); |
|
143 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'locale'); |
|
144 | + $locale = $manager->bootstrap($baseItem->getSiteCode(), $locale->getLanguageId(), $locale->getCurrencyId(), false, $level); |
|
145 | 145 | |
146 | - $context->setLocale( $locale ); |
|
146 | + $context->setLocale($locale); |
|
147 | 147 | |
148 | 148 | try |
149 | 149 | { |
150 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'customer' ); |
|
151 | - $customerItem = $manager->getItem( $baseItem->getCustomerId(), ['customer/group'] ); |
|
150 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'customer'); |
|
151 | + $customerItem = $manager->getItem($baseItem->getCustomerId(), ['customer/group']); |
|
152 | 152 | |
153 | - $context->setUserId( $baseItem->getCustomerId() ); |
|
154 | - $context->setGroupIds( $customerItem->getGroups() ); |
|
153 | + $context->setUserId($baseItem->getCustomerId()); |
|
154 | + $context->setGroupIds($customerItem->getGroups()); |
|
155 | 155 | } |
156 | - catch( \Exception $e ) {} // Subscription without account |
|
156 | + catch (\Exception $e) {} // Subscription without account |
|
157 | 157 | |
158 | 158 | return $context; |
159 | 159 | } |
@@ -166,36 +166,36 @@ discard block |
||
166 | 166 | * @param \Aimeos\MShop\Subscription\Item\Iface $subscription Subscription item with order base ID and order product ID |
167 | 167 | * @return \Aimeos\MShop\Order\Item\Base\Iface Complete order with product, addresses and services saved to the storage |
168 | 168 | */ |
169 | - protected function createOrderBase( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Subscription\Item\Iface $subscription ) |
|
169 | + protected function createOrderBase(\Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Subscription\Item\Iface $subscription) |
|
170 | 170 | { |
171 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'order/base' ); |
|
171 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'order/base'); |
|
172 | 172 | |
173 | - $basket = $manager->load( $subscription->getOrderBaseId() ); |
|
173 | + $basket = $manager->load($subscription->getOrderBaseId()); |
|
174 | 174 | |
175 | 175 | $newBasket = $manager->createItem(); |
176 | - $newBasket->setCustomerId( $basket->getCustomerId() ); |
|
176 | + $newBasket->setCustomerId($basket->getCustomerId()); |
|
177 | 177 | |
178 | - foreach( $basket->getProducts() as $orderProduct ) |
|
178 | + foreach ($basket->getProducts() as $orderProduct) |
|
179 | 179 | { |
180 | - if( $orderProduct->getId() === $subscription->getOrderProductId() ) |
|
180 | + if ($orderProduct->getId() === $subscription->getOrderProductId()) |
|
181 | 181 | { |
182 | - $orderProduct->setId( null ); |
|
183 | - $newBasket->addProduct( $orderProduct ); |
|
182 | + $orderProduct->setId(null); |
|
183 | + $newBasket->addProduct($orderProduct); |
|
184 | 184 | } |
185 | 185 | } |
186 | 186 | |
187 | - foreach( $basket->getAddresses() as $type => $orderAddress ) { |
|
188 | - $newBasket->setAddress( $orderAddress, $type ); |
|
187 | + foreach ($basket->getAddresses() as $type => $orderAddress) { |
|
188 | + $newBasket->setAddress($orderAddress, $type); |
|
189 | 189 | } |
190 | 190 | |
191 | - foreach( $basket->getServices() as $type => $orderServices ) |
|
191 | + foreach ($basket->getServices() as $type => $orderServices) |
|
192 | 192 | { |
193 | - foreach( $orderServices as $orderService ) { |
|
194 | - $newBasket->addService( $orderService, $type ); |
|
193 | + foreach ($orderServices as $orderService) { |
|
194 | + $newBasket->addService($orderService, $type); |
|
195 | 195 | } |
196 | 196 | } |
197 | 197 | |
198 | - return $manager->store( $newBasket ); |
|
198 | + return $manager->store($newBasket); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | |
@@ -206,15 +206,15 @@ discard block |
||
206 | 206 | * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Complete order with product, addresses and services saved to the storage |
207 | 207 | * @return \Aimeos\MShop\Order\Item\Iface New invoice item associated to the order saved to the storage |
208 | 208 | */ |
209 | - protected function createOrderInvoice( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Order\Item\Base\Iface $basket ) |
|
209 | + protected function createOrderInvoice(\Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Order\Item\Base\Iface $basket) |
|
210 | 210 | { |
211 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'order' ); |
|
211 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'order'); |
|
212 | 212 | |
213 | 213 | $item = $manager->createItem(); |
214 | - $item->setBaseId( $basket->getId() ); |
|
215 | - $item->setType( 'subscription' ); |
|
214 | + $item->setBaseId($basket->getId()); |
|
215 | + $item->setType('subscription'); |
|
216 | 216 | |
217 | - return $manager->saveItem( $item ); |
|
217 | + return $manager->saveItem($item); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | |
@@ -225,17 +225,17 @@ discard block |
||
225 | 225 | * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Complete order with product, addresses and services |
226 | 226 | * @param \Aimeos\MShop\Order\Item\Iface New invoice item associated to the order |
227 | 227 | */ |
228 | - protected function createPayment( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Order\Item\Base\Iface $basket, |
|
229 | - \Aimeos\MShop\Order\Item\Iface $invoice ) |
|
228 | + protected function createPayment(\Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Order\Item\Base\Iface $basket, |
|
229 | + \Aimeos\MShop\Order\Item\Iface $invoice) |
|
230 | 230 | { |
231 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'service' ); |
|
231 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'service'); |
|
232 | 232 | |
233 | - foreach( $basket->getService( \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT ) as $service ) |
|
233 | + foreach ($basket->getService(\Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT) as $service) |
|
234 | 234 | { |
235 | - $item = $manager->getItem( $service->getServiceId() ); |
|
236 | - $provider = $manager->getProvider( $item, 'payment' ); |
|
235 | + $item = $manager->getItem($service->getServiceId()); |
|
236 | + $provider = $manager->getProvider($item, 'payment'); |
|
237 | 237 | |
238 | - $provider->repay( $invoice ); |
|
238 | + $provider->repay($invoice); |
|
239 | 239 | } |
240 | 240 | } |
241 | 241 | } |
@@ -93,8 +93,7 @@ discard block |
||
93 | 93 | |
94 | 94 | $interval = new \DateInterval( $item->getInterval() ); |
95 | 95 | $item->setDateNext( date_create()->add( $interval )->format( 'Y-m-d' ) ); |
96 | - } |
|
97 | - catch( \Exception $e ) |
|
96 | + } catch( \Exception $e ) |
|
98 | 97 | { |
99 | 98 | $item->setReason( \Aimeos\MShop\Subscription\Item\Iface::REASON_PAYMENT ); |
100 | 99 | $item->setDateEnd( date_create()->format( 'Y-m-d' ) ); |
@@ -108,8 +107,7 @@ discard block |
||
108 | 107 | foreach( $processors as $processor ) { |
109 | 108 | $processor->renew( $item, $newInvoice ); |
110 | 109 | } |
111 | - } |
|
112 | - catch( \Exception $e ) |
|
110 | + } catch( \Exception $e ) |
|
113 | 111 | { |
114 | 112 | $msg = 'Unable to process subscription with ID "%1$S": %2$s'; |
115 | 113 | $logger->log( sprintf( $msg, $item->getId(), $e->getMessage() ) ); |
@@ -152,8 +150,7 @@ discard block |
||
152 | 150 | |
153 | 151 | $context->setUserId( $baseItem->getCustomerId() ); |
154 | 152 | $context->setGroupIds( $customerItem->getGroups() ); |
155 | - } |
|
156 | - catch( \Exception $e ) {} // Subscription without account |
|
153 | + } catch( \Exception $e ) {} // Subscription without account |
|
157 | 154 | |
158 | 155 | return $context; |
159 | 156 | } |