| @@ -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,38 +166,38 @@ 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 | -				foreach( $orderProduct->getAttributeItems() as $attrItem ) { | |
| 183 | - $attrItem->setId( null ); | |
| 182 | +				foreach ($orderProduct->getAttributeItems() as $attrItem) { | |
| 183 | + $attrItem->setId(null); | |
| 184 | 184 | } | 
| 185 | - $newBasket->addProduct( $orderProduct->setId( null ) ); | |
| 185 | + $newBasket->addProduct($orderProduct->setId(null)); | |
| 186 | 186 | } | 
| 187 | 187 | } | 
| 188 | 188 | |
| 189 | -		foreach( $basket->getAddresses() as $type => $orderAddress ) { | |
| 190 | - $newBasket->setAddress( $orderAddress, $type ); | |
| 189 | +		foreach ($basket->getAddresses() as $type => $orderAddress) { | |
| 190 | + $newBasket->setAddress($orderAddress, $type); | |
| 191 | 191 | } | 
| 192 | 192 | |
| 193 | - foreach( $basket->getServices() as $type => $orderServices ) | |
| 193 | + foreach ($basket->getServices() as $type => $orderServices) | |
| 194 | 194 |  		{ | 
| 195 | -			foreach( $orderServices as $orderService ) { | |
| 196 | - $newBasket->addService( $orderService, $type ); | |
| 195 | +			foreach ($orderServices as $orderService) { | |
| 196 | + $newBasket->addService($orderService, $type); | |
| 197 | 197 | } | 
| 198 | 198 | } | 
| 199 | 199 | |
| 200 | - return $manager->store( $newBasket ); | |
| 200 | + return $manager->store($newBasket); | |
| 201 | 201 | } | 
| 202 | 202 | |
| 203 | 203 | |
| @@ -208,15 +208,15 @@ discard block | ||
| 208 | 208 | * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Complete order with product, addresses and services saved to the storage | 
| 209 | 209 | * @return \Aimeos\MShop\Order\Item\Iface New invoice item associated to the order saved to the storage | 
| 210 | 210 | */ | 
| 211 | - protected function createOrderInvoice( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Order\Item\Base\Iface $basket ) | |
| 211 | + protected function createOrderInvoice(\Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Order\Item\Base\Iface $basket) | |
| 212 | 212 |  	{ | 
| 213 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'order' ); | |
| 213 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'order'); | |
| 214 | 214 | |
| 215 | 215 | $item = $manager->createItem(); | 
| 216 | - $item->setBaseId( $basket->getId() ); | |
| 217 | - $item->setType( 'subscription' ); | |
| 216 | + $item->setBaseId($basket->getId()); | |
| 217 | +		$item->setType('subscription'); | |
| 218 | 218 | |
| 219 | - return $manager->saveItem( $item ); | |
| 219 | + return $manager->saveItem($item); | |
| 220 | 220 | } | 
| 221 | 221 | |
| 222 | 222 | |
| @@ -227,17 +227,17 @@ discard block | ||
| 227 | 227 | * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Complete order with product, addresses and services | 
| 228 | 228 | * @param \Aimeos\MShop\Order\Item\Iface New invoice item associated to the order | 
| 229 | 229 | */ | 
| 230 | - protected function createPayment( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Order\Item\Base\Iface $basket, | |
| 231 | - \Aimeos\MShop\Order\Item\Iface $invoice ) | |
| 230 | + protected function createPayment(\Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Order\Item\Base\Iface $basket, | |
| 231 | + \Aimeos\MShop\Order\Item\Iface $invoice) | |
| 232 | 232 |  	{ | 
| 233 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'service' ); | |
| 233 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'service'); | |
| 234 | 234 | |
| 235 | - foreach( $basket->getService( \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT ) as $service ) | |
| 235 | + foreach ($basket->getService(\Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT) as $service) | |
| 236 | 236 |  		{ | 
| 237 | - $item = $manager->getItem( $service->getServiceId() ); | |
| 238 | - $provider = $manager->getProvider( $item, 'payment' ); | |
| 237 | + $item = $manager->getItem($service->getServiceId()); | |
| 238 | + $provider = $manager->getProvider($item, 'payment'); | |
| 239 | 239 | |
| 240 | - $provider->repay( $invoice ); | |
| 240 | + $provider->repay($invoice); | |
| 241 | 241 | } | 
| 242 | 242 | } | 
| 243 | 243 | } |