@@ -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 | |
@@ -131,25 +131,25 @@ discard block |
||
| 131 | 131 | * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Order including product and addresses |
| 132 | 132 | * @return \Aimeos\MShop\Order\Item\Base\Iface Order with delivery service added |
| 133 | 133 | */ |
| 134 | - protected function addDeliveryService( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Order\Item\Base\Iface $basket ) |
|
| 134 | + protected function addDeliveryService(\Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Order\Item\Base\Iface $basket) |
|
| 135 | 135 | { |
| 136 | 136 | $type = \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_DELIVERY; |
| 137 | 137 | |
| 138 | - $serviceManager = \Aimeos\MShop\Factory::createManager( $context, 'service' ); |
|
| 139 | - $orderServiceManager = \Aimeos\MShop\Factory::createManager( $context, 'order/base/service' ); |
|
| 138 | + $serviceManager = \Aimeos\MShop\Factory::createManager($context, 'service'); |
|
| 139 | + $orderServiceManager = \Aimeos\MShop\Factory::createManager($context, 'order/base/service'); |
|
| 140 | 140 | |
| 141 | - $search = $serviceManager->createSearch( true ); |
|
| 142 | - $search->setSortations( [$search->sort( '+', 'service.position' )] ); |
|
| 143 | - $search->setConditions( $search->compare( '==', 'service.type.code', $type ) ); |
|
| 141 | + $search = $serviceManager->createSearch(true); |
|
| 142 | + $search->setSortations([$search->sort('+', 'service.position')]); |
|
| 143 | + $search->setConditions($search->compare('==', 'service.type.code', $type)); |
|
| 144 | 144 | |
| 145 | - foreach( $serviceManager->searchItems( $search, ['media', 'price', 'text'] ) as $item ) |
|
| 145 | + foreach ($serviceManager->searchItems($search, ['media', 'price', 'text']) as $item) |
|
| 146 | 146 | { |
| 147 | - $provider = $serviceManager->getProvider( $item, $item->getType() ); |
|
| 147 | + $provider = $serviceManager->getProvider($item, $item->getType()); |
|
| 148 | 148 | |
| 149 | - if( $provider->isAvailable( $basket ) === true ) |
|
| 149 | + if ($provider->isAvailable($basket) === true) |
|
| 150 | 150 | { |
| 151 | - $orderServiceItem = $orderServiceManager->createItem()->copyFrom( $item ); |
|
| 152 | - $basket->addService( $orderServiceItem, $type ); |
|
| 151 | + $orderServiceItem = $orderServiceManager->createItem()->copyFrom($item); |
|
| 152 | + $basket->addService($orderServiceItem, $type); |
|
| 153 | 153 | |
| 154 | 154 | return $basket; |
| 155 | 155 | } |
@@ -165,30 +165,30 @@ discard block |
||
| 165 | 165 | * @param string $baseId Unique order base ID |
| 166 | 166 | * @return \Aimeos\MShop\Context\Item\Iface New context object |
| 167 | 167 | */ |
| 168 | - protected function createContext( $baseId ) |
|
| 168 | + protected function createContext($baseId) |
|
| 169 | 169 | { |
| 170 | 170 | $context = clone $this->getContext(); |
| 171 | 171 | |
| 172 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'order/base' ); |
|
| 173 | - $baseItem = $manager->getItem( $baseId ); |
|
| 172 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'order/base'); |
|
| 173 | + $baseItem = $manager->getItem($baseId); |
|
| 174 | 174 | |
| 175 | 175 | $locale = $baseItem->getLocale(); |
| 176 | 176 | $level = \Aimeos\MShop\Locale\Manager\Base::SITE_ALL; |
| 177 | 177 | |
| 178 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'locale' ); |
|
| 179 | - $locale = $manager->bootstrap( $baseItem->getSiteCode(), $locale->getLanguageId(), $locale->getCurrencyId(), false, $level ); |
|
| 178 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'locale'); |
|
| 179 | + $locale = $manager->bootstrap($baseItem->getSiteCode(), $locale->getLanguageId(), $locale->getCurrencyId(), false, $level); |
|
| 180 | 180 | |
| 181 | - $context->setLocale( $locale ); |
|
| 181 | + $context->setLocale($locale); |
|
| 182 | 182 | |
| 183 | 183 | try |
| 184 | 184 | { |
| 185 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'customer' ); |
|
| 186 | - $customerItem = $manager->getItem( $baseItem->getCustomerId(), ['customer/group'] ); |
|
| 185 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'customer'); |
|
| 186 | + $customerItem = $manager->getItem($baseItem->getCustomerId(), ['customer/group']); |
|
| 187 | 187 | |
| 188 | - $context->setUserId( $baseItem->getCustomerId() ); |
|
| 189 | - $context->setGroupIds( $customerItem->getGroups() ); |
|
| 188 | + $context->setUserId($baseItem->getCustomerId()); |
|
| 189 | + $context->setGroupIds($customerItem->getGroups()); |
|
| 190 | 190 | } |
| 191 | - catch( \Exception $e ) {} // Subscription without account |
|
| 191 | + catch (\Exception $e) {} // Subscription without account |
|
| 192 | 192 | |
| 193 | 193 | return $context; |
| 194 | 194 | } |
@@ -201,39 +201,39 @@ discard block |
||
| 201 | 201 | * @param \Aimeos\MShop\Subscription\Item\Iface $subscription Subscription item with order base ID and order product ID |
| 202 | 202 | * @return \Aimeos\MShop\Order\Item\Base\Iface Complete order with product, addresses and services saved to the storage |
| 203 | 203 | */ |
| 204 | - protected function createOrderBase( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Subscription\Item\Iface $subscription ) |
|
| 204 | + protected function createOrderBase(\Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Subscription\Item\Iface $subscription) |
|
| 205 | 205 | { |
| 206 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'order/base' ); |
|
| 206 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'order/base'); |
|
| 207 | 207 | |
| 208 | - $basket = $manager->load( $subscription->getOrderBaseId() ); |
|
| 208 | + $basket = $manager->load($subscription->getOrderBaseId()); |
|
| 209 | 209 | |
| 210 | 210 | $newBasket = $manager->createItem(); |
| 211 | - $newBasket->setCustomerId( $basket->getCustomerId() ); |
|
| 211 | + $newBasket->setCustomerId($basket->getCustomerId()); |
|
| 212 | 212 | |
| 213 | - foreach( $basket->getProducts() as $orderProduct ) |
|
| 213 | + foreach ($basket->getProducts() as $orderProduct) |
|
| 214 | 214 | { |
| 215 | - if( $orderProduct->getId() === $subscription->getOrderProductId() ) |
|
| 215 | + if ($orderProduct->getId() === $subscription->getOrderProductId()) |
|
| 216 | 216 | { |
| 217 | - foreach( $orderProduct->getAttributeItems() as $attrItem ) { |
|
| 218 | - $attrItem->setId( null ); |
|
| 217 | + foreach ($orderProduct->getAttributeItems() as $attrItem) { |
|
| 218 | + $attrItem->setId(null); |
|
| 219 | 219 | } |
| 220 | - $newBasket->addProduct( $orderProduct->setId( null ) ); |
|
| 220 | + $newBasket->addProduct($orderProduct->setId(null)); |
|
| 221 | 221 | } |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - foreach( $basket->getAddresses() as $type => $orderAddress ) { |
|
| 225 | - $newBasket->setAddress( $orderAddress, $type ); |
|
| 224 | + foreach ($basket->getAddresses() as $type => $orderAddress) { |
|
| 225 | + $newBasket->setAddress($orderAddress, $type); |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | $type = \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT; |
| 229 | 229 | |
| 230 | - foreach( $basket->getService( $type ) as $orderService ) { |
|
| 231 | - $newBasket->addService( $orderService, $type ); |
|
| 230 | + foreach ($basket->getService($type) as $orderService) { |
|
| 231 | + $newBasket->addService($orderService, $type); |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | - $newBasket = $this->addDeliveryService( $context, $newBasket ); |
|
| 234 | + $newBasket = $this->addDeliveryService($context, $newBasket); |
|
| 235 | 235 | |
| 236 | - return $manager->store( $newBasket ); |
|
| 236 | + return $manager->store($newBasket); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | |
@@ -244,15 +244,15 @@ discard block |
||
| 244 | 244 | * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Complete order with product, addresses and services saved to the storage |
| 245 | 245 | * @return \Aimeos\MShop\Order\Item\Iface New invoice item associated to the order saved to the storage |
| 246 | 246 | */ |
| 247 | - protected function createOrderInvoice( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Order\Item\Base\Iface $basket ) |
|
| 247 | + protected function createOrderInvoice(\Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Order\Item\Base\Iface $basket) |
|
| 248 | 248 | { |
| 249 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'order' ); |
|
| 249 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'order'); |
|
| 250 | 250 | |
| 251 | 251 | $item = $manager->createItem(); |
| 252 | - $item->setBaseId( $basket->getId() ); |
|
| 253 | - $item->setType( 'subscription' ); |
|
| 252 | + $item->setBaseId($basket->getId()); |
|
| 253 | + $item->setType('subscription'); |
|
| 254 | 254 | |
| 255 | - return $manager->saveItem( $item ); |
|
| 255 | + return $manager->saveItem($item); |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | |
@@ -263,17 +263,17 @@ discard block |
||
| 263 | 263 | * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Complete order with product, addresses and services |
| 264 | 264 | * @param \Aimeos\MShop\Order\Item\Iface New invoice item associated to the order |
| 265 | 265 | */ |
| 266 | - protected function createPayment( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Order\Item\Base\Iface $basket, |
|
| 267 | - \Aimeos\MShop\Order\Item\Iface $invoice ) |
|
| 266 | + protected function createPayment(\Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Order\Item\Base\Iface $basket, |
|
| 267 | + \Aimeos\MShop\Order\Item\Iface $invoice) |
|
| 268 | 268 | { |
| 269 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'service' ); |
|
| 269 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'service'); |
|
| 270 | 270 | |
| 271 | - foreach( $basket->getService( \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT ) as $service ) |
|
| 271 | + foreach ($basket->getService(\Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT) as $service) |
|
| 272 | 272 | { |
| 273 | - $item = $manager->getItem( $service->getServiceId() ); |
|
| 274 | - $provider = $manager->getProvider( $item, 'payment' ); |
|
| 273 | + $item = $manager->getItem($service->getServiceId()); |
|
| 274 | + $provider = $manager->getProvider($item, 'payment'); |
|
| 275 | 275 | |
| 276 | - $provider->repay( $invoice ); |
|
| 276 | + $provider->repay($invoice); |
|
| 277 | 277 | } |
| 278 | 278 | } |
| 279 | 279 | } |