@@ -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,62 +54,62 @@ 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 | - $this->createPayment( $context, $newOrder, $newInvoice ); |
|
| 90 | + $this->createPayment($context, $newOrder, $newInvoice); |
|
| 91 | 91 | |
| 92 | - foreach( $processors as $processor ) { |
|
| 93 | - $processor->renew( $item, $newInvoice ); |
|
| 92 | + foreach ($processors as $processor) { |
|
| 93 | + $processor->renew($item, $newInvoice); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - $interval = new \DateInterval( $item->getInterval() ); |
|
| 97 | - $item->setDateNext( date_create( $item->getTimeCreated() )->add( $interval )->format( 'Y-m-d' ) ); |
|
| 96 | + $interval = new \DateInterval($item->getInterval()); |
|
| 97 | + $item->setDateNext(date_create($item->getTimeCreated())->add($interval)->format('Y-m-d')); |
|
| 98 | 98 | |
| 99 | - $manager->saveItem( $item ); |
|
| 99 | + $manager->saveItem($item); |
|
| 100 | 100 | } |
| 101 | - catch( \Exception $e ) |
|
| 101 | + catch (\Exception $e) |
|
| 102 | 102 | { |
| 103 | 103 | $msg = 'Unable to process subscription with ID "%1$S": %2$s'; |
| 104 | - $logger->log( sprintf( $msg, $item->getId(), $e->getMessage() ) ); |
|
| 105 | - $logger->log( $e->getTraceAsString() ); |
|
| 104 | + $logger->log(sprintf($msg, $item->getId(), $e->getMessage())); |
|
| 105 | + $logger->log($e->getTraceAsString()); |
|
| 106 | 106 | } |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - $count = count( $items ); |
|
| 109 | + $count = count($items); |
|
| 110 | 110 | $start += $count; |
| 111 | 111 | } |
| 112 | - while( $count === $search->getSliceSize() ); |
|
| 112 | + while ($count === $search->getSliceSize()); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | |
@@ -119,30 +119,30 @@ discard block |
||
| 119 | 119 | * @param string $baseId Unique order base ID |
| 120 | 120 | * @return \Aimeos\MShop\Context\Item\Iface New context object |
| 121 | 121 | */ |
| 122 | - protected function createContext( $baseId ) |
|
| 122 | + protected function createContext($baseId) |
|
| 123 | 123 | { |
| 124 | 124 | $context = clone $this->getContext(); |
| 125 | 125 | |
| 126 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'order/base' ); |
|
| 127 | - $baseItem = $manager->getItem( $baseId ); |
|
| 126 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'order/base'); |
|
| 127 | + $baseItem = $manager->getItem($baseId); |
|
| 128 | 128 | |
| 129 | 129 | $locale = $baseItem->getLocale(); |
| 130 | 130 | $level = \Aimeos\MShop\Locale\Manager\Base::SITE_ALL; |
| 131 | 131 | |
| 132 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'locale' ); |
|
| 133 | - $locale = $manager->bootstrap( $baseItem->getSiteCode(), $locale->getLanguageId(), $locale->getCurrencyId(), false, $level ); |
|
| 132 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'locale'); |
|
| 133 | + $locale = $manager->bootstrap($baseItem->getSiteCode(), $locale->getLanguageId(), $locale->getCurrencyId(), false, $level); |
|
| 134 | 134 | |
| 135 | - $context->setLocale( $locale ); |
|
| 135 | + $context->setLocale($locale); |
|
| 136 | 136 | |
| 137 | 137 | try |
| 138 | 138 | { |
| 139 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'customer' ); |
|
| 140 | - $customerItem = $manager->getItem( $baseItem->getCustomerId(), ['customer/group'] ); |
|
| 139 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'customer'); |
|
| 140 | + $customerItem = $manager->getItem($baseItem->getCustomerId(), ['customer/group']); |
|
| 141 | 141 | |
| 142 | - $context->setUserId( $baseItem->getCustomerId() ); |
|
| 143 | - $context->setGroupIds( $customerItem->getGroups() ); |
|
| 142 | + $context->setUserId($baseItem->getCustomerId()); |
|
| 143 | + $context->setGroupIds($customerItem->getGroups()); |
|
| 144 | 144 | } |
| 145 | - catch( \Exception $e ) {} // Subscription without account |
|
| 145 | + catch (\Exception $e) {} // Subscription without account |
|
| 146 | 146 | |
| 147 | 147 | return $context; |
| 148 | 148 | } |
@@ -155,36 +155,36 @@ discard block |
||
| 155 | 155 | * @param \Aimeos\MShop\Subscription\Item\Iface $subscription Subscription item with order base ID and order product ID |
| 156 | 156 | * @return \Aimeos\MShop\Order\Item\Base\Iface Complete order with product, addresses and services saved to the storage |
| 157 | 157 | */ |
| 158 | - protected function createOrderBase( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Subscription\Item\Iface $subscription ) |
|
| 158 | + protected function createOrderBase(\Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Subscription\Item\Iface $subscription) |
|
| 159 | 159 | { |
| 160 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'order/base' ); |
|
| 160 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'order/base'); |
|
| 161 | 161 | |
| 162 | - $basket = $manager->load( $subscription->getOrderBaseId() ); |
|
| 162 | + $basket = $manager->load($subscription->getOrderBaseId()); |
|
| 163 | 163 | |
| 164 | 164 | $newBasket = $manager->createItem(); |
| 165 | - $newBasket->setCustomerId( $basket->getCustomerId() ); |
|
| 165 | + $newBasket->setCustomerId($basket->getCustomerId()); |
|
| 166 | 166 | |
| 167 | - foreach( $basket->getProducts() as $orderProduct ) |
|
| 167 | + foreach ($basket->getProducts() as $orderProduct) |
|
| 168 | 168 | { |
| 169 | - if( $orderProduct->getId() === $subscription->getOrderProductId() ) |
|
| 169 | + if ($orderProduct->getId() === $subscription->getOrderProductId()) |
|
| 170 | 170 | { |
| 171 | - $orderProduct->setId( null ); |
|
| 172 | - $newBasket->addProduct( $orderProduct ); |
|
| 171 | + $orderProduct->setId(null); |
|
| 172 | + $newBasket->addProduct($orderProduct); |
|
| 173 | 173 | } |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - foreach( $basket->getAddresses() as $type => $orderAddress ) { |
|
| 177 | - $newBasket->setAddress( $orderAddress, $type ); |
|
| 176 | + foreach ($basket->getAddresses() as $type => $orderAddress) { |
|
| 177 | + $newBasket->setAddress($orderAddress, $type); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - foreach( $basket->getServices() as $type => $orderServices ) |
|
| 180 | + foreach ($basket->getServices() as $type => $orderServices) |
|
| 181 | 181 | { |
| 182 | - foreach( $orderServices as $orderService ) { |
|
| 183 | - $newBasket->addService( $orderService, $type ); |
|
| 182 | + foreach ($orderServices as $orderService) { |
|
| 183 | + $newBasket->addService($orderService, $type); |
|
| 184 | 184 | } |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | - return $manager->store( $newBasket ); |
|
| 187 | + return $manager->store($newBasket); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | |
@@ -195,15 +195,15 @@ discard block |
||
| 195 | 195 | * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Complete order with product, addresses and services saved to the storage |
| 196 | 196 | * @return \Aimeos\MShop\Order\Item\Iface New invoice item associated to the order saved to the storage |
| 197 | 197 | */ |
| 198 | - protected function createOrderInvoice( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Order\Item\Base\Iface $basket ) |
|
| 198 | + protected function createOrderInvoice(\Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Order\Item\Base\Iface $basket) |
|
| 199 | 199 | { |
| 200 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'order' ); |
|
| 200 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'order'); |
|
| 201 | 201 | |
| 202 | 202 | $item = $manager->createItem(); |
| 203 | - $item->setBaseId( $basket->getId() ); |
|
| 204 | - $item->setType( 'subscription' ); |
|
| 203 | + $item->setBaseId($basket->getId()); |
|
| 204 | + $item->setType('subscription'); |
|
| 205 | 205 | |
| 206 | - return $manager->saveItem( $item ); |
|
| 206 | + return $manager->saveItem($item); |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | |
@@ -214,17 +214,17 @@ discard block |
||
| 214 | 214 | * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Complete order with product, addresses and services |
| 215 | 215 | * @param \Aimeos\MShop\Order\Item\Iface New invoice item associated to the order |
| 216 | 216 | */ |
| 217 | - protected function createPayment( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Order\Item\Base\Iface $basket, |
|
| 218 | - \Aimeos\MShop\Order\Item\Iface $invoice ) |
|
| 217 | + protected function createPayment(\Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Order\Item\Base\Iface $basket, |
|
| 218 | + \Aimeos\MShop\Order\Item\Iface $invoice) |
|
| 219 | 219 | { |
| 220 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'service' ); |
|
| 220 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'service'); |
|
| 221 | 221 | |
| 222 | - foreach( $basket->getService( \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT ) as $service ) |
|
| 222 | + foreach ($basket->getService(\Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT) as $service) |
|
| 223 | 223 | { |
| 224 | - $item = $manager->getItem( $service->getServiceId() ); |
|
| 225 | - $provider = $manager->getProvider( $item, 'payment' ); |
|
| 224 | + $item = $manager->getItem($service->getServiceId()); |
|
| 225 | + $provider = $manager->getProvider($item, 'payment'); |
|
| 226 | 226 | |
| 227 | - $provider->repay( $invoice ); |
|
| 227 | + $provider->repay($invoice); |
|
| 228 | 228 | } |
| 229 | 229 | } |
| 230 | 230 | } |