@@ -210,6 +210,9 @@ |
||
210 | 210 | } |
211 | 211 | |
212 | 212 | |
213 | + /** |
|
214 | + * @param string $name |
|
215 | + */ |
|
213 | 216 | protected function access( $name ) |
214 | 217 | { |
215 | 218 | $class = new \ReflectionClass( '\Aimeos\Controller\Jobs\Subscription\Process\Renew\Standard' ); |
@@ -21,62 +21,62 @@ discard block |
||
21 | 21 | $this->aimeos = \TestHelperJobs::getAimeos(); |
22 | 22 | $this->context = \TestHelperJobs::getContext(); |
23 | 23 | |
24 | - $this->object = new \Aimeos\Controller\Jobs\Subscription\Process\Renew\Standard( $this->context, $this->aimeos ); |
|
24 | + $this->object = new \Aimeos\Controller\Jobs\Subscription\Process\Renew\Standard($this->context, $this->aimeos); |
|
25 | 25 | |
26 | - \Aimeos\MShop\Factory::setCache( true ); |
|
26 | + \Aimeos\MShop\Factory::setCache(true); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | |
30 | 30 | protected function tearDown() |
31 | 31 | { |
32 | - \Aimeos\MShop\Factory::setCache( false ); |
|
32 | + \Aimeos\MShop\Factory::setCache(false); |
|
33 | 33 | \Aimeos\MShop\Factory::clear(); |
34 | 34 | |
35 | - unset( $this->object, $this->context, $this->aimeos ); |
|
35 | + unset($this->object, $this->context, $this->aimeos); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | |
39 | 39 | public function testGetName() |
40 | 40 | { |
41 | - $this->assertEquals( 'Subscription process renew', $this->object->getName() ); |
|
41 | + $this->assertEquals('Subscription process renew', $this->object->getName()); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | |
45 | 45 | public function testGetDescription() |
46 | 46 | { |
47 | - $this->assertEquals( 'Renews subscriptions at next date', $this->object->getDescription() ); |
|
47 | + $this->assertEquals('Renews subscriptions at next date', $this->object->getDescription()); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | |
51 | 51 | public function testRun() |
52 | 52 | { |
53 | - $this->context->getConfig()->set( 'controller/common/subscription/process/processors', ['cgroup'] ); |
|
53 | + $this->context->getConfig()->set('controller/common/subscription/process/processors', ['cgroup']); |
|
54 | 54 | $item = $this->getSubscription(); |
55 | 55 | |
56 | - $object = $this->getMockBuilder( '\\Aimeos\\Controller\\Jobs\\Subscription\\Process\\Renew\\Standard' ) |
|
57 | - ->setConstructorArgs( [$this->context, $this->aimeos] ) |
|
58 | - ->setMethods( ['createOrderBase', 'createOrderInvoice', 'createPayment'] ) |
|
56 | + $object = $this->getMockBuilder('\\Aimeos\\Controller\\Jobs\\Subscription\\Process\\Renew\\Standard') |
|
57 | + ->setConstructorArgs([$this->context, $this->aimeos]) |
|
58 | + ->setMethods(['createOrderBase', 'createOrderInvoice', 'createPayment']) |
|
59 | 59 | ->getMock(); |
60 | 60 | |
61 | - $managerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Subscription\\Manager\\Standard' ) |
|
62 | - ->setConstructorArgs( [$this->context] ) |
|
63 | - ->setMethods( ['searchItems', 'saveItem'] ) |
|
61 | + $managerStub = $this->getMockBuilder('\\Aimeos\\MShop\\Subscription\\Manager\\Standard') |
|
62 | + ->setConstructorArgs([$this->context]) |
|
63 | + ->setMethods(['searchItems', 'saveItem']) |
|
64 | 64 | ->getMock(); |
65 | 65 | |
66 | - \Aimeos\MShop\Factory::injectManager( $this->context, 'subscription', $managerStub ); |
|
66 | + \Aimeos\MShop\Factory::injectManager($this->context, 'subscription', $managerStub); |
|
67 | 67 | |
68 | - $object->expects( $this->once() )->method( 'createOrderBase' ) |
|
69 | - ->will( $this->returnValue( $this->getOrderBaseItem( $item->getOrderBaseId() ) ) ); |
|
68 | + $object->expects($this->once())->method('createOrderBase') |
|
69 | + ->will($this->returnValue($this->getOrderBaseItem($item->getOrderBaseId()))); |
|
70 | 70 | |
71 | - $object->expects( $this->once() )->method( 'createOrderInvoice' ) |
|
72 | - ->will( $this->returnValue( $this->getOrderItem() ) ); |
|
71 | + $object->expects($this->once())->method('createOrderInvoice') |
|
72 | + ->will($this->returnValue($this->getOrderItem())); |
|
73 | 73 | |
74 | - $object->expects( $this->once() )->method( 'createPayment' ); |
|
74 | + $object->expects($this->once())->method('createPayment'); |
|
75 | 75 | |
76 | - $managerStub->expects( $this->once() )->method( 'searchItems' ) |
|
77 | - ->will( $this->returnValue( [$item] ) ); |
|
76 | + $managerStub->expects($this->once())->method('searchItems') |
|
77 | + ->will($this->returnValue([$item])); |
|
78 | 78 | |
79 | - $managerStub->expects( $this->once() )->method( 'saveItem' ); |
|
79 | + $managerStub->expects($this->once())->method('saveItem'); |
|
80 | 80 | |
81 | 81 | $object->run(); |
82 | 82 | } |
@@ -84,19 +84,19 @@ discard block |
||
84 | 84 | |
85 | 85 | public function testRunException() |
86 | 86 | { |
87 | - $this->context->getConfig()->set( 'controller/common/subscription/process/processors', ['cgroup'] ); |
|
87 | + $this->context->getConfig()->set('controller/common/subscription/process/processors', ['cgroup']); |
|
88 | 88 | |
89 | - $managerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Subscription\\Manager\\Standard' ) |
|
90 | - ->setConstructorArgs( [$this->context] ) |
|
91 | - ->setMethods( ['searchItems', 'saveItem'] ) |
|
89 | + $managerStub = $this->getMockBuilder('\\Aimeos\\MShop\\Subscription\\Manager\\Standard') |
|
90 | + ->setConstructorArgs([$this->context]) |
|
91 | + ->setMethods(['searchItems', 'saveItem']) |
|
92 | 92 | ->getMock(); |
93 | 93 | |
94 | - \Aimeos\MShop\Factory::injectManager( $this->context, 'subscription', $managerStub ); |
|
94 | + \Aimeos\MShop\Factory::injectManager($this->context, 'subscription', $managerStub); |
|
95 | 95 | |
96 | - $managerStub->expects( $this->once() )->method( 'searchItems' ) |
|
97 | - ->will( $this->returnValue( [$managerStub->createItem()] ) ); |
|
96 | + $managerStub->expects($this->once())->method('searchItems') |
|
97 | + ->will($this->returnValue([$managerStub->createItem()])); |
|
98 | 98 | |
99 | - $managerStub->expects( $this->never() )->method( 'saveItem' ); |
|
99 | + $managerStub->expects($this->never())->method('saveItem'); |
|
100 | 100 | |
101 | 101 | $this->object->run(); |
102 | 102 | } |
@@ -104,26 +104,26 @@ discard block |
||
104 | 104 | |
105 | 105 | public function testAddCoupons() |
106 | 106 | { |
107 | - $this->context->getConfig()->set( 'controller/jobs/subcription/process/renew/standard/use-coupons', true ); |
|
107 | + $this->context->getConfig()->set('controller/jobs/subcription/process/renew/standard/use-coupons', true); |
|
108 | 108 | |
109 | - $basket = \Aimeos\MShop\Factory::createManager( $this->context, 'order/base' )->createItem(); |
|
110 | - $product = \Aimeos\MShop\Factory::createManager( $this->context, 'product' )->findItem( 'CNC', ['price'] ); |
|
111 | - $orderProduct = \Aimeos\MShop\Factory::createManager( $this->context, 'order/base/product' )->createItem(); |
|
109 | + $basket = \Aimeos\MShop\Factory::createManager($this->context, 'order/base')->createItem(); |
|
110 | + $product = \Aimeos\MShop\Factory::createManager($this->context, 'product')->findItem('CNC', ['price']); |
|
111 | + $orderProduct = \Aimeos\MShop\Factory::createManager($this->context, 'order/base/product')->createItem(); |
|
112 | 112 | |
113 | - $price = $product->getRefItems( 'price', 'default', 'default' ); |
|
114 | - $basket->addProduct( $orderProduct->copyFrom( $product )->setPrice( reset( $price ) ) ); |
|
113 | + $price = $product->getRefItems('price', 'default', 'default'); |
|
114 | + $basket->addProduct($orderProduct->copyFrom($product)->setPrice(reset($price))); |
|
115 | 115 | |
116 | - $this->assertEquals( '600.00', $basket->getPrice()->getValue() ); |
|
117 | - $this->assertEquals( '30.00', $basket->getPrice()->getCosts() ); |
|
118 | - $this->assertEquals( '0.00', $basket->getPrice()->getRebate() ); |
|
116 | + $this->assertEquals('600.00', $basket->getPrice()->getValue()); |
|
117 | + $this->assertEquals('30.00', $basket->getPrice()->getCosts()); |
|
118 | + $this->assertEquals('0.00', $basket->getPrice()->getRebate()); |
|
119 | 119 | |
120 | - $basket = $this->access( 'addBasketCoupons' )->invokeArgs( $this->object, [$this->context, $basket, ['90AB']] ); |
|
120 | + $basket = $this->access('addBasketCoupons')->invokeArgs($this->object, [$this->context, $basket, ['90AB']]); |
|
121 | 121 | |
122 | - $this->assertEquals( 1, count( $basket->getCoupons() ) ); |
|
123 | - $this->assertEquals( 2, count( $basket->getProducts() ) ); |
|
124 | - $this->assertEquals( '537.00', $basket->getPrice()->getValue() ); |
|
125 | - $this->assertEquals( '30.00', $basket->getPrice()->getCosts() ); |
|
126 | - $this->assertEquals( '63.00', $basket->getPrice()->getRebate() ); |
|
122 | + $this->assertEquals(1, count($basket->getCoupons())); |
|
123 | + $this->assertEquals(2, count($basket->getProducts())); |
|
124 | + $this->assertEquals('537.00', $basket->getPrice()->getValue()); |
|
125 | + $this->assertEquals('30.00', $basket->getPrice()->getCosts()); |
|
126 | + $this->assertEquals('63.00', $basket->getPrice()->getRebate()); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | |
@@ -131,34 +131,34 @@ discard block |
||
131 | 131 | { |
132 | 132 | $item = $this->getSubscription(); |
133 | 133 | |
134 | - $managerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Order\\Manager\\Base\\Standard' ) |
|
135 | - ->setConstructorArgs( [$this->context] ) |
|
136 | - ->setMethods( ['store'] ) |
|
134 | + $managerStub = $this->getMockBuilder('\\Aimeos\\MShop\\Order\\Manager\\Base\\Standard') |
|
135 | + ->setConstructorArgs([$this->context]) |
|
136 | + ->setMethods(['store']) |
|
137 | 137 | ->getMock(); |
138 | 138 | |
139 | - \Aimeos\MShop\Factory::injectManager( $this->context, 'order/base', $managerStub ); |
|
139 | + \Aimeos\MShop\Factory::injectManager($this->context, 'order/base', $managerStub); |
|
140 | 140 | |
141 | - $managerStub->expects( $this->once() )->method( 'store' ); |
|
141 | + $managerStub->expects($this->once())->method('store'); |
|
142 | 142 | |
143 | - $this->access( 'createOrderBase' )->invokeArgs( $this->object, [$this->context, $item] ); |
|
143 | + $this->access('createOrderBase')->invokeArgs($this->object, [$this->context, $item]); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | |
147 | 147 | public function testCreateOrderInvoice() |
148 | 148 | { |
149 | 149 | $item = $this->getSubscription(); |
150 | - $baseItem = $this->getOrderBaseItem( $item->getOrderBaseId() ); |
|
150 | + $baseItem = $this->getOrderBaseItem($item->getOrderBaseId()); |
|
151 | 151 | |
152 | - $managerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Order\\Manager\\Standard' ) |
|
153 | - ->setConstructorArgs( [$this->context] ) |
|
154 | - ->setMethods( ['saveItem'] ) |
|
152 | + $managerStub = $this->getMockBuilder('\\Aimeos\\MShop\\Order\\Manager\\Standard') |
|
153 | + ->setConstructorArgs([$this->context]) |
|
154 | + ->setMethods(['saveItem']) |
|
155 | 155 | ->getMock(); |
156 | 156 | |
157 | - \Aimeos\MShop\Factory::injectManager( $this->context, 'order', $managerStub ); |
|
157 | + \Aimeos\MShop\Factory::injectManager($this->context, 'order', $managerStub); |
|
158 | 158 | |
159 | - $managerStub->expects( $this->once() )->method( 'saveItem' ); |
|
159 | + $managerStub->expects($this->once())->method('saveItem'); |
|
160 | 160 | |
161 | - $this->access( 'createOrderInvoice' )->invokeArgs( $this->object, [$this->context, $baseItem] ); |
|
161 | + $this->access('createOrderInvoice')->invokeArgs($this->object, [$this->context, $baseItem]); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | |
@@ -166,55 +166,55 @@ discard block |
||
166 | 166 | { |
167 | 167 | $item = $this->getSubscription(); |
168 | 168 | $invoice = $this->getOrderItem(); |
169 | - $baseItem = $this->getOrderBaseItem( $item->getOrderBaseId() ); |
|
169 | + $baseItem = $this->getOrderBaseItem($item->getOrderBaseId()); |
|
170 | 170 | |
171 | - $managerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Order\\Manager\\Standard' ) |
|
172 | - ->setConstructorArgs( [$this->context] ) |
|
173 | - ->setMethods( ['saveItem'] ) |
|
171 | + $managerStub = $this->getMockBuilder('\\Aimeos\\MShop\\Order\\Manager\\Standard') |
|
172 | + ->setConstructorArgs([$this->context]) |
|
173 | + ->setMethods(['saveItem']) |
|
174 | 174 | ->getMock(); |
175 | 175 | |
176 | - \Aimeos\MShop\Factory::injectManager( $this->context, 'order', $managerStub ); |
|
176 | + \Aimeos\MShop\Factory::injectManager($this->context, 'order', $managerStub); |
|
177 | 177 | |
178 | - $managerStub->expects( $this->once() )->method( 'saveItem' ); |
|
178 | + $managerStub->expects($this->once())->method('saveItem'); |
|
179 | 179 | |
180 | - $this->access( 'createPayment' )->invokeArgs( $this->object, [$this->context, $baseItem, $invoice] ); |
|
180 | + $this->access('createPayment')->invokeArgs($this->object, [$this->context, $baseItem, $invoice]); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | |
184 | 184 | protected function getOrderItem() |
185 | 185 | { |
186 | - return \Aimeos\MShop\Factory::createManager( $this->context, 'order' )->createItem(); |
|
186 | + return \Aimeos\MShop\Factory::createManager($this->context, 'order')->createItem(); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | |
190 | - protected function getOrderBaseItem( $baseId ) |
|
190 | + protected function getOrderBaseItem($baseId) |
|
191 | 191 | { |
192 | - return \Aimeos\MShop\Factory::createManager( $this->context, 'order/base' )->getItem( $baseId, ['order/base/service'] ); |
|
192 | + return \Aimeos\MShop\Factory::createManager($this->context, 'order/base')->getItem($baseId, ['order/base/service']); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | |
196 | 196 | protected function getSubscription() |
197 | 197 | { |
198 | - $manager = \Aimeos\MShop\Factory::createManager( $this->context, 'subscription' ); |
|
198 | + $manager = \Aimeos\MShop\Factory::createManager($this->context, 'subscription'); |
|
199 | 199 | |
200 | 200 | $search = $manager->createSearch(); |
201 | - $search->setConditions( $search->compare( '==', 'subscription.dateend', '2010-01-01' ) ); |
|
201 | + $search->setConditions($search->compare('==', 'subscription.dateend', '2010-01-01')); |
|
202 | 202 | |
203 | - $items = $manager->searchItems( $search ); |
|
203 | + $items = $manager->searchItems($search); |
|
204 | 204 | |
205 | - if( ( $item = reset( $items ) ) !== false ) { |
|
205 | + if (($item = reset($items)) !== false) { |
|
206 | 206 | return $item; |
207 | 207 | } |
208 | 208 | |
209 | - throw new \Exception( 'No subscription item found' ); |
|
209 | + throw new \Exception('No subscription item found'); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | |
213 | - protected function access( $name ) |
|
213 | + protected function access($name) |
|
214 | 214 | { |
215 | - $class = new \ReflectionClass( '\Aimeos\Controller\Jobs\Subscription\Process\Renew\Standard' ); |
|
216 | - $method = $class->getMethod( $name ); |
|
217 | - $method->setAccessible( true ); |
|
215 | + $class = new \ReflectionClass('\Aimeos\Controller\Jobs\Subscription\Process\Renew\Standard'); |
|
216 | + $method = $class->getMethod($name); |
|
217 | + $method->setAccessible(true); |
|
218 | 218 | |
219 | 219 | return $method; |
220 | 220 | } |
@@ -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 | |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | * @param array $codes List of coupon codes that should be added to the given basket |
133 | 133 | * @return \Aimeos\MShop\Order\Item\Base\Iface Basket, maybe with coupons added |
134 | 134 | */ |
135 | - protected function addBasketCoupons( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Order\Item\Base\Iface $basket, array $codes ) |
|
135 | + protected function addBasketCoupons(\Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Order\Item\Base\Iface $basket, array $codes) |
|
136 | 136 | { |
137 | 137 | /** controller/jobs/subcription/process/renew/standard/use-coupons |
138 | 138 | * |
@@ -146,34 +146,34 @@ discard block |
||
146 | 146 | * @category User |
147 | 147 | * @since 2018.10 |
148 | 148 | */ |
149 | - if( $context->getConfig()->get( 'controller/jobs/subcription/process/renew/standard/use-coupons', false ) ) |
|
149 | + if ($context->getConfig()->get('controller/jobs/subcription/process/renew/standard/use-coupons', false)) |
|
150 | 150 | { |
151 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'coupon' ); |
|
152 | - $codeManager = \Aimeos\MShop\Factory::createManager( $context, 'coupon/code' ); |
|
151 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'coupon'); |
|
152 | + $codeManager = \Aimeos\MShop\Factory::createManager($context, 'coupon/code'); |
|
153 | 153 | |
154 | - foreach( $codes as $code ) |
|
154 | + foreach ($codes as $code) |
|
155 | 155 | { |
156 | - $search = $manager->createSearch( true )->setSlice( 0, 1 ); |
|
156 | + $search = $manager->createSearch(true)->setSlice(0, 1); |
|
157 | 157 | $expr = [ |
158 | - $search->compare( '==', 'coupon.code.code', $code ), |
|
159 | - $codeManager->createSearch( true )->getConditions(), |
|
158 | + $search->compare('==', 'coupon.code.code', $code), |
|
159 | + $codeManager->createSearch(true)->getConditions(), |
|
160 | 160 | $search->getConditions(), |
161 | 161 | ]; |
162 | - $search->setConditions( $search->combine( '&&', $expr ) ); |
|
162 | + $search->setConditions($search->combine('&&', $expr)); |
|
163 | 163 | |
164 | - $result = $manager->searchItems( $search ); |
|
164 | + $result = $manager->searchItems($search); |
|
165 | 165 | |
166 | - if( ( $item = reset( $result ) ) === false ) { |
|
166 | + if (($item = reset($result)) === false) { |
|
167 | 167 | continue; |
168 | 168 | } |
169 | 169 | |
170 | - $provider = $manager->getProvider( $item, $code ); |
|
170 | + $provider = $manager->getProvider($item, $code); |
|
171 | 171 | |
172 | - if( $provider->isAvailable( $basket ) !== true ) { |
|
172 | + if ($provider->isAvailable($basket) !== true) { |
|
173 | 173 | continue; |
174 | 174 | } |
175 | 175 | |
176 | - $provider->addCoupon( $basket ); |
|
176 | + $provider->addCoupon($basket); |
|
177 | 177 | } |
178 | 178 | } |
179 | 179 | |
@@ -188,25 +188,25 @@ discard block |
||
188 | 188 | * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Order including product and addresses |
189 | 189 | * @return \Aimeos\MShop\Order\Item\Base\Iface Order with delivery service added |
190 | 190 | */ |
191 | - protected function addDeliveryService( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Order\Item\Base\Iface $basket ) |
|
191 | + protected function addDeliveryService(\Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Order\Item\Base\Iface $basket) |
|
192 | 192 | { |
193 | 193 | $type = \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_DELIVERY; |
194 | 194 | |
195 | - $serviceManager = \Aimeos\MShop\Factory::createManager( $context, 'service' ); |
|
196 | - $orderServiceManager = \Aimeos\MShop\Factory::createManager( $context, 'order/base/service' ); |
|
195 | + $serviceManager = \Aimeos\MShop\Factory::createManager($context, 'service'); |
|
196 | + $orderServiceManager = \Aimeos\MShop\Factory::createManager($context, 'order/base/service'); |
|
197 | 197 | |
198 | - $search = $serviceManager->createSearch( true ); |
|
199 | - $search->setSortations( [$search->sort( '+', 'service.position' )] ); |
|
200 | - $search->setConditions( $search->compare( '==', 'service.type.code', $type ) ); |
|
198 | + $search = $serviceManager->createSearch(true); |
|
199 | + $search->setSortations([$search->sort('+', 'service.position')]); |
|
200 | + $search->setConditions($search->compare('==', 'service.type.code', $type)); |
|
201 | 201 | |
202 | - foreach( $serviceManager->searchItems( $search, ['media', 'price', 'text'] ) as $item ) |
|
202 | + foreach ($serviceManager->searchItems($search, ['media', 'price', 'text']) as $item) |
|
203 | 203 | { |
204 | - $provider = $serviceManager->getProvider( $item, $item->getType() ); |
|
204 | + $provider = $serviceManager->getProvider($item, $item->getType()); |
|
205 | 205 | |
206 | - if( $provider->isAvailable( $basket ) === true ) |
|
206 | + if ($provider->isAvailable($basket) === true) |
|
207 | 207 | { |
208 | - $orderServiceItem = $orderServiceManager->createItem()->copyFrom( $item ); |
|
209 | - $basket->addService( $orderServiceItem, $type ); |
|
208 | + $orderServiceItem = $orderServiceManager->createItem()->copyFrom($item); |
|
209 | + $basket->addService($orderServiceItem, $type); |
|
210 | 210 | |
211 | 211 | return $basket; |
212 | 212 | } |
@@ -222,30 +222,30 @@ discard block |
||
222 | 222 | * @param string $baseId Unique order base ID |
223 | 223 | * @return \Aimeos\MShop\Context\Item\Iface New context object |
224 | 224 | */ |
225 | - protected function createContext( $baseId ) |
|
225 | + protected function createContext($baseId) |
|
226 | 226 | { |
227 | 227 | $context = clone $this->getContext(); |
228 | 228 | |
229 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'order/base' ); |
|
230 | - $baseItem = $manager->getItem( $baseId ); |
|
229 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'order/base'); |
|
230 | + $baseItem = $manager->getItem($baseId); |
|
231 | 231 | |
232 | 232 | $locale = $baseItem->getLocale(); |
233 | 233 | $level = \Aimeos\MShop\Locale\Manager\Base::SITE_ALL; |
234 | 234 | |
235 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'locale' ); |
|
236 | - $locale = $manager->bootstrap( $baseItem->getSiteCode(), $locale->getLanguageId(), $locale->getCurrencyId(), false, $level ); |
|
235 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'locale'); |
|
236 | + $locale = $manager->bootstrap($baseItem->getSiteCode(), $locale->getLanguageId(), $locale->getCurrencyId(), false, $level); |
|
237 | 237 | |
238 | - $context->setLocale( $locale ); |
|
238 | + $context->setLocale($locale); |
|
239 | 239 | |
240 | 240 | try |
241 | 241 | { |
242 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'customer' ); |
|
243 | - $customerItem = $manager->getItem( $baseItem->getCustomerId(), ['customer/group'] ); |
|
242 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'customer'); |
|
243 | + $customerItem = $manager->getItem($baseItem->getCustomerId(), ['customer/group']); |
|
244 | 244 | |
245 | - $context->setUserId( $baseItem->getCustomerId() ); |
|
246 | - $context->setGroupIds( $customerItem->getGroups() ); |
|
245 | + $context->setUserId($baseItem->getCustomerId()); |
|
246 | + $context->setGroupIds($customerItem->getGroups()); |
|
247 | 247 | } |
248 | - catch( \Exception $e ) {} // Subscription without account |
|
248 | + catch (\Exception $e) {} // Subscription without account |
|
249 | 249 | |
250 | 250 | return $context; |
251 | 251 | } |
@@ -258,39 +258,39 @@ discard block |
||
258 | 258 | * @param \Aimeos\MShop\Subscription\Item\Iface $subscription Subscription item with order base ID and order product ID |
259 | 259 | * @return \Aimeos\MShop\Order\Item\Base\Iface Complete order with product, addresses and services saved to the storage |
260 | 260 | */ |
261 | - protected function createOrderBase( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Subscription\Item\Iface $subscription ) |
|
261 | + protected function createOrderBase(\Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Subscription\Item\Iface $subscription) |
|
262 | 262 | { |
263 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'order/base' ); |
|
264 | - $basket = $manager->load( $subscription->getOrderBaseId() ); |
|
263 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'order/base'); |
|
264 | + $basket = $manager->load($subscription->getOrderBaseId()); |
|
265 | 265 | |
266 | 266 | $newBasket = $manager->createItem(); |
267 | - $newBasket->setCustomerId( $basket->getCustomerId() ); |
|
267 | + $newBasket->setCustomerId($basket->getCustomerId()); |
|
268 | 268 | |
269 | - foreach( $basket->getProducts() as $orderProduct ) |
|
269 | + foreach ($basket->getProducts() as $orderProduct) |
|
270 | 270 | { |
271 | - if( $orderProduct->getId() === $subscription->getOrderProductId() ) |
|
271 | + if ($orderProduct->getId() === $subscription->getOrderProductId()) |
|
272 | 272 | { |
273 | - foreach( $orderProduct->getAttributeItems() as $attrItem ) { |
|
274 | - $attrItem->setId( null ); |
|
273 | + foreach ($orderProduct->getAttributeItems() as $attrItem) { |
|
274 | + $attrItem->setId(null); |
|
275 | 275 | } |
276 | - $newBasket->addProduct( $orderProduct->setId( null ) ); |
|
276 | + $newBasket->addProduct($orderProduct->setId(null)); |
|
277 | 277 | } |
278 | 278 | } |
279 | 279 | |
280 | - foreach( $basket->getAddresses() as $type => $orderAddress ) { |
|
281 | - $newBasket->setAddress( $orderAddress, $type ); |
|
280 | + foreach ($basket->getAddresses() as $type => $orderAddress) { |
|
281 | + $newBasket->setAddress($orderAddress, $type); |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | $type = \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT; |
285 | 285 | |
286 | - foreach( $basket->getService( $type ) as $orderService ) { |
|
287 | - $newBasket->addService( $orderService, $type ); |
|
286 | + foreach ($basket->getService($type) as $orderService) { |
|
287 | + $newBasket->addService($orderService, $type); |
|
288 | 288 | } |
289 | 289 | |
290 | - $newBasket = $this->addDeliveryService( $context, $newBasket ); |
|
291 | - $newBasket = $this->addBasketCoupons( $context, $newBasket, array_keys( $basket->getCoupons() ) ); |
|
290 | + $newBasket = $this->addDeliveryService($context, $newBasket); |
|
291 | + $newBasket = $this->addBasketCoupons($context, $newBasket, array_keys($basket->getCoupons())); |
|
292 | 292 | |
293 | - return $manager->store( $newBasket ); |
|
293 | + return $manager->store($newBasket); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | |
@@ -301,15 +301,15 @@ discard block |
||
301 | 301 | * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Complete order with product, addresses and services saved to the storage |
302 | 302 | * @return \Aimeos\MShop\Order\Item\Iface New invoice item associated to the order saved to the storage |
303 | 303 | */ |
304 | - protected function createOrderInvoice( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Order\Item\Base\Iface $basket ) |
|
304 | + protected function createOrderInvoice(\Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Order\Item\Base\Iface $basket) |
|
305 | 305 | { |
306 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'order' ); |
|
306 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'order'); |
|
307 | 307 | |
308 | 308 | $item = $manager->createItem(); |
309 | - $item->setBaseId( $basket->getId() ); |
|
310 | - $item->setType( 'subscription' ); |
|
309 | + $item->setBaseId($basket->getId()); |
|
310 | + $item->setType('subscription'); |
|
311 | 311 | |
312 | - return $manager->saveItem( $item ); |
|
312 | + return $manager->saveItem($item); |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | |
@@ -320,17 +320,17 @@ discard block |
||
320 | 320 | * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Complete order with product, addresses and services |
321 | 321 | * @param \Aimeos\MShop\Order\Item\Iface New invoice item associated to the order |
322 | 322 | */ |
323 | - protected function createPayment( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Order\Item\Base\Iface $basket, |
|
324 | - \Aimeos\MShop\Order\Item\Iface $invoice ) |
|
323 | + protected function createPayment(\Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Order\Item\Base\Iface $basket, |
|
324 | + \Aimeos\MShop\Order\Item\Iface $invoice) |
|
325 | 325 | { |
326 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'service' ); |
|
326 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'service'); |
|
327 | 327 | |
328 | - foreach( $basket->getService( \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT ) as $service ) |
|
328 | + foreach ($basket->getService(\Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT) as $service) |
|
329 | 329 | { |
330 | - $item = $manager->getItem( $service->getServiceId() ); |
|
331 | - $provider = $manager->getProvider( $item, 'payment' ); |
|
330 | + $item = $manager->getItem($service->getServiceId()); |
|
331 | + $provider = $manager->getProvider($item, 'payment'); |
|
332 | 332 | |
333 | - $provider->repay( $invoice ); |
|
333 | + $provider->repay($invoice); |
|
334 | 334 | } |
335 | 335 | } |
336 | 336 | } |