@@ -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 start' ); |
|
31 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Subscription process start'); |
|
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', 'Process subscriptions initially' ); |
|
42 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Process subscriptions initially'); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | |
@@ -65,50 +65,50 @@ discard block |
||
65 | 65 | * @since 2018.04 |
66 | 66 | * @category Developer |
67 | 67 | */ |
68 | - $names = (array) $config->get( 'controller/common/subscription/process/processors', [] ); |
|
68 | + $names = (array) $config->get('controller/common/subscription/process/processors', []); |
|
69 | 69 | |
70 | - $processors = $this->getProcessors( $names ); |
|
71 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'subscription' ); |
|
70 | + $processors = $this->getProcessors($names); |
|
71 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'subscription'); |
|
72 | 72 | |
73 | - $search = $manager->createSearch( true ); |
|
73 | + $search = $manager->createSearch(true); |
|
74 | 74 | $expr = [ |
75 | - $search->compare( '==', 'subscription.datenext', null ), |
|
75 | + $search->compare('==', 'subscription.datenext', null), |
|
76 | 76 | $search->getConditions(), |
77 | 77 | ]; |
78 | - $search->setConditions( $search->combine( '&&', $expr ) ); |
|
79 | - $search->setSortations( [$search->sort( '+', 'subscription.id' )] ); |
|
78 | + $search->setConditions($search->combine('&&', $expr)); |
|
79 | + $search->setSortations([$search->sort('+', 'subscription.id')]); |
|
80 | 80 | |
81 | 81 | $start = 0; |
82 | 82 | |
83 | 83 | do |
84 | 84 | { |
85 | - $search->setSlice( $start, 100 ); |
|
86 | - $items = $manager->searchItems( $search ); |
|
85 | + $search->setSlice($start, 100); |
|
86 | + $items = $manager->searchItems($search); |
|
87 | 87 | |
88 | - foreach( $items as $item ) |
|
88 | + foreach ($items as $item) |
|
89 | 89 | { |
90 | 90 | try |
91 | 91 | { |
92 | - foreach( $processors as $processor ) { |
|
93 | - $processor->begin( $item ); |
|
92 | + foreach ($processors as $processor) { |
|
93 | + $processor->begin($item); |
|
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 | } |
@@ -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 | } |
@@ -106,34 +106,34 @@ discard block |
||
106 | 106 | { |
107 | 107 | $item = $this->getSubscription(); |
108 | 108 | |
109 | - $managerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Order\\Manager\\Base\\Standard' ) |
|
110 | - ->setConstructorArgs( [$this->context] ) |
|
111 | - ->setMethods( ['store'] ) |
|
109 | + $managerStub = $this->getMockBuilder('\\Aimeos\\MShop\\Order\\Manager\\Base\\Standard') |
|
110 | + ->setConstructorArgs([$this->context]) |
|
111 | + ->setMethods(['store']) |
|
112 | 112 | ->getMock(); |
113 | 113 | |
114 | - \Aimeos\MShop\Factory::injectManager( $this->context, 'order/base', $managerStub ); |
|
114 | + \Aimeos\MShop\Factory::injectManager($this->context, 'order/base', $managerStub); |
|
115 | 115 | |
116 | - $managerStub->expects( $this->once() )->method( 'store' ); |
|
116 | + $managerStub->expects($this->once())->method('store'); |
|
117 | 117 | |
118 | - $this->access( 'createOrderBase' )->invokeArgs( $this->object, [$this->context, $item] ); |
|
118 | + $this->access('createOrderBase')->invokeArgs($this->object, [$this->context, $item]); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | |
122 | 122 | public function testCreateOrderInvoice() |
123 | 123 | { |
124 | 124 | $item = $this->getSubscription(); |
125 | - $baseItem = $this->getOrderBaseItem( $item->getOrderBaseId() ); |
|
125 | + $baseItem = $this->getOrderBaseItem($item->getOrderBaseId()); |
|
126 | 126 | |
127 | - $managerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Order\\Manager\\Standard' ) |
|
128 | - ->setConstructorArgs( [$this->context] ) |
|
129 | - ->setMethods( ['saveItem'] ) |
|
127 | + $managerStub = $this->getMockBuilder('\\Aimeos\\MShop\\Order\\Manager\\Standard') |
|
128 | + ->setConstructorArgs([$this->context]) |
|
129 | + ->setMethods(['saveItem']) |
|
130 | 130 | ->getMock(); |
131 | 131 | |
132 | - \Aimeos\MShop\Factory::injectManager( $this->context, 'order', $managerStub ); |
|
132 | + \Aimeos\MShop\Factory::injectManager($this->context, 'order', $managerStub); |
|
133 | 133 | |
134 | - $managerStub->expects( $this->once() )->method( 'saveItem' ); |
|
134 | + $managerStub->expects($this->once())->method('saveItem'); |
|
135 | 135 | |
136 | - $this->access( 'createOrderInvoice' )->invokeArgs( $this->object, [$this->context, $baseItem] ); |
|
136 | + $this->access('createOrderInvoice')->invokeArgs($this->object, [$this->context, $baseItem]); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | |
@@ -141,55 +141,55 @@ discard block |
||
141 | 141 | { |
142 | 142 | $item = $this->getSubscription(); |
143 | 143 | $invoice = $this->getOrderItem(); |
144 | - $baseItem = $this->getOrderBaseItem( $item->getOrderBaseId() ); |
|
144 | + $baseItem = $this->getOrderBaseItem($item->getOrderBaseId()); |
|
145 | 145 | |
146 | - $managerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Order\\Manager\\Standard' ) |
|
147 | - ->setConstructorArgs( [$this->context] ) |
|
148 | - ->setMethods( ['saveItem'] ) |
|
146 | + $managerStub = $this->getMockBuilder('\\Aimeos\\MShop\\Order\\Manager\\Standard') |
|
147 | + ->setConstructorArgs([$this->context]) |
|
148 | + ->setMethods(['saveItem']) |
|
149 | 149 | ->getMock(); |
150 | 150 | |
151 | - \Aimeos\MShop\Factory::injectManager( $this->context, 'order', $managerStub ); |
|
151 | + \Aimeos\MShop\Factory::injectManager($this->context, 'order', $managerStub); |
|
152 | 152 | |
153 | - $managerStub->expects( $this->once() )->method( 'saveItem' ); |
|
153 | + $managerStub->expects($this->once())->method('saveItem'); |
|
154 | 154 | |
155 | - $this->access( 'createPayment' )->invokeArgs( $this->object, [$this->context, $baseItem, $invoice] ); |
|
155 | + $this->access('createPayment')->invokeArgs($this->object, [$this->context, $baseItem, $invoice]); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | |
159 | 159 | protected function getOrderItem() |
160 | 160 | { |
161 | - return \Aimeos\MShop\Factory::createManager( $this->context, 'order' )->createItem(); |
|
161 | + return \Aimeos\MShop\Factory::createManager($this->context, 'order')->createItem(); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | |
165 | - protected function getOrderBaseItem( $baseId ) |
|
165 | + protected function getOrderBaseItem($baseId) |
|
166 | 166 | { |
167 | - return \Aimeos\MShop\Factory::createManager( $this->context, 'order/base' )->getItem( $baseId, ['order/base/service'] ); |
|
167 | + return \Aimeos\MShop\Factory::createManager($this->context, 'order/base')->getItem($baseId, ['order/base/service']); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | |
171 | 171 | protected function getSubscription() |
172 | 172 | { |
173 | - $manager = \Aimeos\MShop\Factory::createManager( $this->context, 'subscription' ); |
|
173 | + $manager = \Aimeos\MShop\Factory::createManager($this->context, 'subscription'); |
|
174 | 174 | |
175 | 175 | $search = $manager->createSearch(); |
176 | - $search->setConditions( $search->compare( '==', 'subscription.dateend', '2010-01-01' ) ); |
|
176 | + $search->setConditions($search->compare('==', 'subscription.dateend', '2010-01-01')); |
|
177 | 177 | |
178 | - $items = $manager->searchItems( $search ); |
|
178 | + $items = $manager->searchItems($search); |
|
179 | 179 | |
180 | - if( ( $item = reset( $items ) ) !== false ) { |
|
180 | + if (($item = reset($items)) !== false) { |
|
181 | 181 | return $item; |
182 | 182 | } |
183 | 183 | |
184 | - throw new \Exception( 'No subscription item found' ); |
|
184 | + throw new \Exception('No subscription item found'); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | |
188 | - protected function access( $name ) |
|
188 | + protected function access($name) |
|
189 | 189 | { |
190 | - $class = new \ReflectionClass( '\Aimeos\Controller\Jobs\Subscription\Process\Renew\Standard' ); |
|
191 | - $method = $class->getMethod( $name ); |
|
192 | - $method->setAccessible( true ); |
|
190 | + $class = new \ReflectionClass('\Aimeos\Controller\Jobs\Subscription\Process\Renew\Standard'); |
|
191 | + $method = $class->getMethod($name); |
|
192 | + $method->setAccessible(true); |
|
193 | 193 | |
194 | 194 | return $method; |
195 | 195 | } |
@@ -35,51 +35,51 @@ |
||
35 | 35 | ); |
36 | 36 | |
37 | 37 | |
38 | - $object = new \Aimeos\Controller\Common\Order\Export\Csv\Processor\Product\Standard( $context, $mapping ); |
|
39 | - |
|
40 | - $invoice = $this->getInvoice( $context ); |
|
41 | - $order = \Aimeos\MShop\Factory::createManager( $context, 'order/base' )->load( $invoice->getBaseId() ); |
|
42 | - |
|
43 | - $data = $object->process( $invoice, $order ); |
|
44 | - |
|
45 | - |
|
46 | - $this->assertEquals( 4, count( $data ) ); |
|
47 | - |
|
48 | - $this->assertEquals( 18, count( $data[0] ) ); |
|
49 | - $this->assertEquals( 'default', $data[0][0] ); |
|
50 | - $this->assertEquals( 'unit_type1', $data[0][1] ); |
|
51 | - $this->assertEquals( 'unitsupplier', $data[0][2] ); |
|
52 | - $this->assertEquals( 'CNE', $data[0][3] ); |
|
53 | - $this->assertGreaterThan( 0, $data[0][4] ); |
|
54 | - $this->assertEquals( '9', $data[0][5] ); |
|
55 | - $this->assertEquals( 'Cafe Noire Expresso', $data[0][6] ); |
|
56 | - $this->assertEquals( 'somewhere/thump1.jpg', $data[0][7] ); |
|
57 | - $this->assertEquals( '4.50', $data[0][8] ); |
|
58 | - $this->assertEquals( '0.00', $data[0][9] ); |
|
59 | - $this->assertEquals( '0.00', $data[0][10] ); |
|
60 | - $this->assertEquals( '0.0000', $data[0][11] ); |
|
61 | - $this->assertEquals( '1', $data[0][12] ); |
|
62 | - $this->assertEquals( '1', $data[0][13] ); |
|
63 | - $this->assertEquals( "default\ndefault\nconfig", $data[0][14] ); |
|
64 | - $this->assertEquals( "width\nlength\ninterval", $data[0][15] ); |
|
65 | - $this->assertEquals( "33\n36\nP0Y1M0W0D", $data[0][16] ); |
|
66 | - $this->assertEquals( "33\n36\nP0Y1M0W0D", $data[0][17] ); |
|
38 | + $object = new \Aimeos\Controller\Common\Order\Export\Csv\Processor\Product\Standard($context, $mapping); |
|
39 | + |
|
40 | + $invoice = $this->getInvoice($context); |
|
41 | + $order = \Aimeos\MShop\Factory::createManager($context, 'order/base')->load($invoice->getBaseId()); |
|
42 | + |
|
43 | + $data = $object->process($invoice, $order); |
|
44 | + |
|
45 | + |
|
46 | + $this->assertEquals(4, count($data)); |
|
47 | + |
|
48 | + $this->assertEquals(18, count($data[0])); |
|
49 | + $this->assertEquals('default', $data[0][0]); |
|
50 | + $this->assertEquals('unit_type1', $data[0][1]); |
|
51 | + $this->assertEquals('unitsupplier', $data[0][2]); |
|
52 | + $this->assertEquals('CNE', $data[0][3]); |
|
53 | + $this->assertGreaterThan(0, $data[0][4]); |
|
54 | + $this->assertEquals('9', $data[0][5]); |
|
55 | + $this->assertEquals('Cafe Noire Expresso', $data[0][6]); |
|
56 | + $this->assertEquals('somewhere/thump1.jpg', $data[0][7]); |
|
57 | + $this->assertEquals('4.50', $data[0][8]); |
|
58 | + $this->assertEquals('0.00', $data[0][9]); |
|
59 | + $this->assertEquals('0.00', $data[0][10]); |
|
60 | + $this->assertEquals('0.0000', $data[0][11]); |
|
61 | + $this->assertEquals('1', $data[0][12]); |
|
62 | + $this->assertEquals('1', $data[0][13]); |
|
63 | + $this->assertEquals("default\ndefault\nconfig", $data[0][14]); |
|
64 | + $this->assertEquals("width\nlength\ninterval", $data[0][15]); |
|
65 | + $this->assertEquals("33\n36\nP0Y1M0W0D", $data[0][16]); |
|
66 | + $this->assertEquals("33\n36\nP0Y1M0W0D", $data[0][17]); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | |
70 | - protected function getInvoice( $context ) |
|
70 | + protected function getInvoice($context) |
|
71 | 71 | { |
72 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'order' ); |
|
72 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'order'); |
|
73 | 73 | |
74 | 74 | $search = $manager->createSearch(); |
75 | - $search->setConditions( $search->compare( '==', 'order.datepayment', '2008-02-15 12:34:56' ) ); |
|
75 | + $search->setConditions($search->compare('==', 'order.datepayment', '2008-02-15 12:34:56')); |
|
76 | 76 | |
77 | - $items = $manager->searchItems( $search ); |
|
77 | + $items = $manager->searchItems($search); |
|
78 | 78 | |
79 | - if( ( $item = reset( $items ) ) !== false ) { |
|
79 | + if (($item = reset($items)) !== false) { |
|
80 | 80 | return $item; |
81 | 81 | } |
82 | 82 | |
83 | - throw new \Exception( 'No order item found' ); |
|
83 | + throw new \Exception('No order item found'); |
|
84 | 84 | } |
85 | 85 | } |
@@ -35,51 +35,51 @@ |
||
35 | 35 | ); |
36 | 36 | |
37 | 37 | |
38 | - $object = new \Aimeos\Controller\Common\Subscription\Export\Csv\Processor\Product\Standard( $context, $mapping ); |
|
39 | - |
|
40 | - $subscription = $this->getSubscription( $context ); |
|
41 | - $order = \Aimeos\MShop\Factory::createManager( $context, 'order/base' )->load( $subscription->getOrderBaseId() ); |
|
42 | - |
|
43 | - $data = $object->process( $subscription, $order ); |
|
44 | - |
|
45 | - |
|
46 | - $this->assertEquals( 1, count( $data ) ); |
|
47 | - |
|
48 | - $this->assertEquals( 18, count( $data[0] ) ); |
|
49 | - $this->assertEquals( 'default', $data[0][0] ); |
|
50 | - $this->assertEquals( 'unit_type1', $data[0][1] ); |
|
51 | - $this->assertEquals( 'unitsupplier', $data[0][2] ); |
|
52 | - $this->assertEquals( 'CNE', $data[0][3] ); |
|
53 | - $this->assertGreaterThan( 0, $data[0][4] ); |
|
54 | - $this->assertEquals( '9', $data[0][5] ); |
|
55 | - $this->assertEquals( 'Cafe Noire Expresso', $data[0][6] ); |
|
56 | - $this->assertEquals( 'somewhere/thump1.jpg', $data[0][7] ); |
|
57 | - $this->assertEquals( '4.50', $data[0][8] ); |
|
58 | - $this->assertEquals( '0.00', $data[0][9] ); |
|
59 | - $this->assertEquals( '0.00', $data[0][10] ); |
|
60 | - $this->assertEquals( '0.0000', $data[0][11] ); |
|
61 | - $this->assertEquals( '1', $data[0][12] ); |
|
62 | - $this->assertEquals( '1', $data[0][13] ); |
|
63 | - $this->assertEquals( "default\ndefault\nconfig", $data[0][14] ); |
|
64 | - $this->assertEquals( "width\nlength\ninterval", $data[0][15] ); |
|
65 | - $this->assertEquals( "33\n36\nP0Y1M0W0D", $data[0][16] ); |
|
66 | - $this->assertEquals( "33\n36\nP0Y1M0W0D", $data[0][17] ); |
|
38 | + $object = new \Aimeos\Controller\Common\Subscription\Export\Csv\Processor\Product\Standard($context, $mapping); |
|
39 | + |
|
40 | + $subscription = $this->getSubscription($context); |
|
41 | + $order = \Aimeos\MShop\Factory::createManager($context, 'order/base')->load($subscription->getOrderBaseId()); |
|
42 | + |
|
43 | + $data = $object->process($subscription, $order); |
|
44 | + |
|
45 | + |
|
46 | + $this->assertEquals(1, count($data)); |
|
47 | + |
|
48 | + $this->assertEquals(18, count($data[0])); |
|
49 | + $this->assertEquals('default', $data[0][0]); |
|
50 | + $this->assertEquals('unit_type1', $data[0][1]); |
|
51 | + $this->assertEquals('unitsupplier', $data[0][2]); |
|
52 | + $this->assertEquals('CNE', $data[0][3]); |
|
53 | + $this->assertGreaterThan(0, $data[0][4]); |
|
54 | + $this->assertEquals('9', $data[0][5]); |
|
55 | + $this->assertEquals('Cafe Noire Expresso', $data[0][6]); |
|
56 | + $this->assertEquals('somewhere/thump1.jpg', $data[0][7]); |
|
57 | + $this->assertEquals('4.50', $data[0][8]); |
|
58 | + $this->assertEquals('0.00', $data[0][9]); |
|
59 | + $this->assertEquals('0.00', $data[0][10]); |
|
60 | + $this->assertEquals('0.0000', $data[0][11]); |
|
61 | + $this->assertEquals('1', $data[0][12]); |
|
62 | + $this->assertEquals('1', $data[0][13]); |
|
63 | + $this->assertEquals("default\ndefault\nconfig", $data[0][14]); |
|
64 | + $this->assertEquals("width\nlength\ninterval", $data[0][15]); |
|
65 | + $this->assertEquals("33\n36\nP0Y1M0W0D", $data[0][16]); |
|
66 | + $this->assertEquals("33\n36\nP0Y1M0W0D", $data[0][17]); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | |
70 | - protected function getSubscription( $context ) |
|
70 | + protected function getSubscription($context) |
|
71 | 71 | { |
72 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'subscription' ); |
|
72 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'subscription'); |
|
73 | 73 | |
74 | 74 | $search = $manager->createSearch(); |
75 | - $search->setConditions( $search->compare( '==', 'subscription.dateend', '2010-01-01' ) ); |
|
75 | + $search->setConditions($search->compare('==', 'subscription.dateend', '2010-01-01')); |
|
76 | 76 | |
77 | - $items = $manager->searchItems( $search ); |
|
77 | + $items = $manager->searchItems($search); |
|
78 | 78 | |
79 | - if( ( $item = reset( $items ) ) !== false ) { |
|
79 | + if (($item = reset($items)) !== false) { |
|
80 | 80 | return $item; |
81 | 81 | } |
82 | 82 | |
83 | - throw new \Exception( 'No subscription item found' ); |
|
83 | + throw new \Exception('No subscription item found'); |
|
84 | 84 | } |
85 | 85 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public function getName() |
30 | 30 | { |
31 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Rescale product images' ); |
|
31 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Rescale product images'); |
|
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', 'Rescales product images to the new sizes' ); |
|
42 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Rescales product images to the new sizes'); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | |
@@ -51,41 +51,41 @@ discard block |
||
51 | 51 | public function run() |
52 | 52 | { |
53 | 53 | $context = $this->getContext(); |
54 | - $cntl = \Aimeos\Controller\Common\Media\Factory::createController( $context ); |
|
55 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'media' ); |
|
54 | + $cntl = \Aimeos\Controller\Common\Media\Factory::createController($context); |
|
55 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'media'); |
|
56 | 56 | |
57 | 57 | $search = $manager->createSearch(); |
58 | 58 | $expr = array( |
59 | - $search->compare( '==', 'media.domain', 'product' ), |
|
60 | - $search->compare( '=~', 'media.mimetype', 'image/' ), |
|
59 | + $search->compare('==', 'media.domain', 'product'), |
|
60 | + $search->compare('=~', 'media.mimetype', 'image/'), |
|
61 | 61 | ); |
62 | - $search->setConditions( $search->combine( '&&', $expr ) ); |
|
63 | - $search->setSortations( array( $search->sort( '+', 'media.id' ) ) ); |
|
62 | + $search->setConditions($search->combine('&&', $expr)); |
|
63 | + $search->setSortations(array($search->sort('+', 'media.id'))); |
|
64 | 64 | |
65 | 65 | $start = 0; |
66 | 66 | |
67 | 67 | do |
68 | 68 | { |
69 | - $search->setSlice( $start ); |
|
70 | - $items = $manager->searchItems( $search ); |
|
69 | + $search->setSlice($start); |
|
70 | + $items = $manager->searchItems($search); |
|
71 | 71 | |
72 | - foreach( $items as $item ) |
|
72 | + foreach ($items as $item) |
|
73 | 73 | { |
74 | 74 | try |
75 | 75 | { |
76 | - $cntl->scale( $item, 'fs-media' ); |
|
77 | - $manager->saveItem( $item ); |
|
76 | + $cntl->scale($item, 'fs-media'); |
|
77 | + $manager->saveItem($item); |
|
78 | 78 | } |
79 | - catch( \Exception $e ) |
|
79 | + catch (\Exception $e) |
|
80 | 80 | { |
81 | - $msg = sprintf( 'Scaling media item "%1$s" failed: %2$s', $item->getId(), $e->getMessage() ); |
|
82 | - $context->getLogger()->log( $msg ); |
|
81 | + $msg = sprintf('Scaling media item "%1$s" failed: %2$s', $item->getId(), $e->getMessage()); |
|
82 | + $context->getLogger()->log($msg); |
|
83 | 83 | } |
84 | 84 | } |
85 | 85 | |
86 | - $count = count( $items ); |
|
86 | + $count = count($items); |
|
87 | 87 | $start += $count; |
88 | 88 | } |
89 | - while( $count === $search->getSliceSize() ); |
|
89 | + while ($count === $search->getSliceSize()); |
|
90 | 90 | } |
91 | 91 | } |
@@ -42,10 +42,10 @@ discard block |
||
42 | 42 | * @param array $mapping Associative list of field position in CSV as key and domain item key as value |
43 | 43 | * @param \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Iface $object Decorated processor |
44 | 44 | */ |
45 | - public function __construct( \Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
46 | - \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Iface $object = null ) |
|
45 | + public function __construct(\Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
46 | + \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Iface $object = null) |
|
47 | 47 | { |
48 | - parent::__construct( $context, $mapping, $object ); |
|
48 | + parent::__construct($context, $mapping, $object); |
|
49 | 49 | |
50 | 50 | /** controller/common/catalog/import/csv/processor/media/listtypes |
51 | 51 | * Names of the catalog list types for media that are updated or removed |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @see controller/common/catalog/import/csv/processor/price/listtypes |
67 | 67 | * @see controller/common/catalog/import/csv/processor/text/listtypes |
68 | 68 | */ |
69 | - $this->listTypes = $context->getConfig()->get( 'controller/common/catalog/import/csv/processor/media/listtypes' ); |
|
69 | + $this->listTypes = $context->getConfig()->get('controller/common/catalog/import/csv/processor/media/listtypes'); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | |
@@ -77,45 +77,45 @@ discard block |
||
77 | 77 | * @param array $data List of CSV fields with position as key and data as value |
78 | 78 | * @return array List of data which hasn't been imported |
79 | 79 | */ |
80 | - public function process( \Aimeos\MShop\Catalog\Item\Iface $catalog, array $data ) |
|
80 | + public function process(\Aimeos\MShop\Catalog\Item\Iface $catalog, array $data) |
|
81 | 81 | { |
82 | 82 | $context = $this->getContext(); |
83 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'media' ); |
|
84 | - $listManager = \Aimeos\MShop\Factory::createManager( $context, 'catalog/lists' ); |
|
85 | - $separator = $context->getConfig()->get( 'controller/common/catalog/import/csv/separator', "\n" ); |
|
83 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'media'); |
|
84 | + $listManager = \Aimeos\MShop\Factory::createManager($context, 'catalog/lists'); |
|
85 | + $separator = $context->getConfig()->get('controller/common/catalog/import/csv/separator', "\n"); |
|
86 | 86 | |
87 | 87 | $manager->begin(); |
88 | 88 | |
89 | 89 | try |
90 | 90 | { |
91 | 91 | $delete = $listMap = []; |
92 | - $map = $this->getMappedChunk( $data, $this->getMapping() ); |
|
93 | - $listItems = $catalog->getListItems( 'media', $this->listTypes ); |
|
92 | + $map = $this->getMappedChunk($data, $this->getMapping()); |
|
93 | + $listItems = $catalog->getListItems('media', $this->listTypes); |
|
94 | 94 | |
95 | - foreach( $listItems as $listItem ) |
|
95 | + foreach ($listItems as $listItem) |
|
96 | 96 | { |
97 | - if( ( $refItem = $listItem->getRefItem() ) !== null ) { |
|
98 | - $listMap[ $refItem->getUrl() ][ $refItem->getType() ][ $listItem->getType() ] = $listItem; |
|
97 | + if (($refItem = $listItem->getRefItem()) !== null) { |
|
98 | + $listMap[$refItem->getUrl()][$refItem->getType()][$listItem->getType()] = $listItem; |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
102 | - foreach( $map as $pos => $list ) |
|
102 | + foreach ($map as $pos => $list) |
|
103 | 103 | { |
104 | - if( $this->checkEntry( $list ) === false ) { |
|
104 | + if ($this->checkEntry($list) === false) { |
|
105 | 105 | continue; |
106 | 106 | } |
107 | 107 | |
108 | - $urls = explode( $separator, trim( $list['media.url'] ) ); |
|
109 | - $type = trim( $this->getValue( $list, 'media.type', 'default' ) ); |
|
110 | - $typecode = trim( $this->getValue( $list, 'catalog.lists.type', 'default' ) ); |
|
108 | + $urls = explode($separator, trim($list['media.url'])); |
|
109 | + $type = trim($this->getValue($list, 'media.type', 'default')); |
|
110 | + $typecode = trim($this->getValue($list, 'catalog.lists.type', 'default')); |
|
111 | 111 | |
112 | - foreach( $urls as $url ) |
|
112 | + foreach ($urls as $url) |
|
113 | 113 | { |
114 | - if( isset( $listMap[$url][$type][$typecode] ) ) |
|
114 | + if (isset($listMap[$url][$type][$typecode])) |
|
115 | 115 | { |
116 | 116 | $listItem = $listMap[$url][$type][$typecode]; |
117 | 117 | $refItem = $listItem->getRefItem(); |
118 | - unset( $listItems[ $listItem->getId() ] ); |
|
118 | + unset($listItems[$listItem->getId()]); |
|
119 | 119 | } |
120 | 120 | else |
121 | 121 | { |
@@ -123,35 +123,35 @@ discard block |
||
123 | 123 | $refItem = $manager->createItem(); |
124 | 124 | } |
125 | 125 | |
126 | - $list['media.typeid'] = $this->getTypeId( 'media/type', 'catalog', $type ); |
|
126 | + $list['media.typeid'] = $this->getTypeId('media/type', 'catalog', $type); |
|
127 | 127 | $list['media.domain'] = 'catalog'; |
128 | 128 | $list['media.url'] = $url; |
129 | 129 | |
130 | - $refItem->fromArray( $this->addItemDefaults( $list ) ); |
|
131 | - $refItem = $manager->saveItem( $refItem ); |
|
130 | + $refItem->fromArray($this->addItemDefaults($list)); |
|
131 | + $refItem = $manager->saveItem($refItem); |
|
132 | 132 | |
133 | - $list['catalog.lists.typeid'] = $this->getTypeId( 'catalog/lists/type', 'media', $typecode ); |
|
133 | + $list['catalog.lists.typeid'] = $this->getTypeId('catalog/lists/type', 'media', $typecode); |
|
134 | 134 | $list['catalog.lists.parentid'] = $catalog->getId(); |
135 | 135 | $list['catalog.lists.refid'] = $refItem->getId(); |
136 | 136 | $list['catalog.lists.domain'] = 'media'; |
137 | 137 | |
138 | - $listItem->fromArray( $this->addListItemDefaults( $list, $pos++ ) ); |
|
139 | - $listManager->saveItem( $listItem, false ); |
|
138 | + $listItem->fromArray($this->addListItemDefaults($list, $pos++)); |
|
139 | + $listManager->saveItem($listItem, false); |
|
140 | 140 | } |
141 | 141 | } |
142 | 142 | |
143 | - foreach( $listItems as $listItem ) { |
|
143 | + foreach ($listItems as $listItem) { |
|
144 | 144 | $delete[] = $listItem->getRefId(); |
145 | 145 | } |
146 | 146 | |
147 | - $manager->deleteItems( $delete ); |
|
148 | - $listManager->deleteItems( array_keys( $listItems ) ); |
|
147 | + $manager->deleteItems($delete); |
|
148 | + $listManager->deleteItems(array_keys($listItems)); |
|
149 | 149 | |
150 | - $data = $this->getObject()->process( $catalog, $data ); |
|
150 | + $data = $this->getObject()->process($catalog, $data); |
|
151 | 151 | |
152 | 152 | $manager->commit(); |
153 | 153 | } |
154 | - catch( \Exception $e ) |
|
154 | + catch (\Exception $e) |
|
155 | 155 | { |
156 | 156 | $manager->rollback(); |
157 | 157 | throw $e; |
@@ -167,17 +167,17 @@ discard block |
||
167 | 167 | * @param array $list Associative list of domain item keys and their values, e.g. "media.status" => 1 |
168 | 168 | * @return array Given associative list enriched by default values if they were not already set |
169 | 169 | */ |
170 | - protected function addItemDefaults( array $list ) |
|
170 | + protected function addItemDefaults(array $list) |
|
171 | 171 | { |
172 | - if( !isset( $list['media.label'] ) ) { |
|
172 | + if (!isset($list['media.label'])) { |
|
173 | 173 | $list['media.label'] = $list['media.url']; |
174 | 174 | } |
175 | 175 | |
176 | - if( !isset( $list['media.preview'] ) ) { |
|
176 | + if (!isset($list['media.preview'])) { |
|
177 | 177 | $list['media.preview'] = $list['media.url']; |
178 | 178 | } |
179 | 179 | |
180 | - if( !isset( $list['media.status'] ) ) { |
|
180 | + if (!isset($list['media.status'])) { |
|
181 | 181 | $list['media.status'] = 1; |
182 | 182 | } |
183 | 183 | |
@@ -191,10 +191,10 @@ discard block |
||
191 | 191 | * @param array $list Associative list of key/value pairs from the mapping |
192 | 192 | * @return boolean True if valid, false if not |
193 | 193 | */ |
194 | - protected function checkEntry( array $list ) |
|
194 | + protected function checkEntry(array $list) |
|
195 | 195 | { |
196 | - if( !isset( $list['media.url'] ) || trim( $list['media.url'] ) === '' || isset( $list['catalog.lists.type'] ) |
|
197 | - && $this->listTypes !== null && !in_array( trim( $list['catalog.lists.type'] ), (array) $this->listTypes ) |
|
196 | + if (!isset($list['media.url']) || trim($list['media.url']) === '' || isset($list['catalog.lists.type']) |
|
197 | + && $this->listTypes !== null && !in_array(trim($list['catalog.lists.type']), (array) $this->listTypes) |
|
198 | 198 | ) { |
199 | 199 | return false; |
200 | 200 | } |
@@ -43,10 +43,10 @@ discard block |
||
43 | 43 | * @param array $mapping Associative list of field position in CSV as key and domain item key as value |
44 | 44 | * @param \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object Decorated processor |
45 | 45 | */ |
46 | - public function __construct( \Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
47 | - \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null ) |
|
46 | + public function __construct(\Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
47 | + \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null) |
|
48 | 48 | { |
49 | - parent::__construct( $context, $mapping, $object ); |
|
49 | + parent::__construct($context, $mapping, $object); |
|
50 | 50 | |
51 | 51 | /** controller/common/product/import/csv/processor/catalog/listtypes |
52 | 52 | * Names of the catalog list types that are updated or removed |
@@ -67,9 +67,9 @@ discard block |
||
67 | 67 | * @see controller/common/product/import/csv/processor/product/listtypes |
68 | 68 | * @see controller/common/product/import/csv/processor/text/listtypes |
69 | 69 | */ |
70 | - $this->listTypes = $context->getConfig()->get( 'controller/common/product/import/csv/processor/catalog/listtypes' ); |
|
70 | + $this->listTypes = $context->getConfig()->get('controller/common/product/import/csv/processor/catalog/listtypes'); |
|
71 | 71 | |
72 | - $this->cache = $this->getCache( 'catalog' ); |
|
72 | + $this->cache = $this->getCache('catalog'); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | |
@@ -80,11 +80,11 @@ discard block |
||
80 | 80 | * @param array $data List of CSV fields with position as key and data as value |
81 | 81 | * @return array List of data which hasn't been imported |
82 | 82 | */ |
83 | - public function process( \Aimeos\MShop\Product\Item\Iface $product, array $data ) |
|
83 | + public function process(\Aimeos\MShop\Product\Item\Iface $product, array $data) |
|
84 | 84 | { |
85 | 85 | $context = $this->getContext(); |
86 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'catalog' ); |
|
87 | - $listManager = \Aimeos\MShop\Factory::createManager( $context, 'catalog/lists' ); |
|
86 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'catalog'); |
|
87 | + $listManager = \Aimeos\MShop\Factory::createManager($context, 'catalog/lists'); |
|
88 | 88 | |
89 | 89 | /** controller/common/product/import/csv/separator |
90 | 90 | * Single separator character for multiple entries in one field of the import file |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | * @category Developer |
105 | 105 | * @see controller/common/product/import/csv/domains |
106 | 106 | */ |
107 | - $separator = $context->getConfig()->get( 'controller/common/product/import/csv/separator', "\n" ); |
|
107 | + $separator = $context->getConfig()->get('controller/common/product/import/csv/separator', "\n"); |
|
108 | 108 | |
109 | 109 | $manager->begin(); |
110 | 110 | |
@@ -112,58 +112,58 @@ discard block |
||
112 | 112 | { |
113 | 113 | $listMap = []; |
114 | 114 | $prodid = $product->getId(); |
115 | - $map = $this->getMappedChunk( $data, $this->getMapping() ); |
|
116 | - $listItems = $this->getListItems( $prodid, $this->listTypes ); |
|
115 | + $map = $this->getMappedChunk($data, $this->getMapping()); |
|
116 | + $listItems = $this->getListItems($prodid, $this->listTypes); |
|
117 | 117 | |
118 | - foreach( $listItems as $listItem ) { |
|
119 | - $listMap[ $listItem->getParentId() ][ $listItem->getType() ] = $listItem; |
|
118 | + foreach ($listItems as $listItem) { |
|
119 | + $listMap[$listItem->getParentId()][$listItem->getType()] = $listItem; |
|
120 | 120 | } |
121 | 121 | |
122 | - foreach( $map as $pos => $list ) |
|
122 | + foreach ($map as $pos => $list) |
|
123 | 123 | { |
124 | - if( $this->checkEntry( $list ) === false ) { |
|
124 | + if ($this->checkEntry($list) === false) { |
|
125 | 125 | continue; |
126 | 126 | } |
127 | 127 | |
128 | - $codes = explode( $separator, trim( $list['catalog.code'] ) ); |
|
129 | - $type = trim( isset( $list['catalog.lists.type'] ) ? $list['catalog.lists.type'] : 'default' ); |
|
128 | + $codes = explode($separator, trim($list['catalog.code'])); |
|
129 | + $type = trim(isset($list['catalog.lists.type']) ? $list['catalog.lists.type'] : 'default'); |
|
130 | 130 | |
131 | - foreach( $codes as $code ) |
|
131 | + foreach ($codes as $code) |
|
132 | 132 | { |
133 | - $code = trim( $code ); |
|
133 | + $code = trim($code); |
|
134 | 134 | |
135 | - if( ( $catid = $this->cache->get( $code ) ) === null ) |
|
135 | + if (($catid = $this->cache->get($code)) === null) |
|
136 | 136 | { |
137 | 137 | $msg = 'No category for code "%1$s" available when importing product with code "%2$s"'; |
138 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( $msg, $code, $product->getCode() ) ); |
|
138 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf($msg, $code, $product->getCode())); |
|
139 | 139 | } |
140 | 140 | |
141 | - $list['catalog.lists.typeid'] = $this->getTypeId( 'catalog/lists/type', 'product', $type ); |
|
141 | + $list['catalog.lists.typeid'] = $this->getTypeId('catalog/lists/type', 'product', $type); |
|
142 | 142 | $list['catalog.lists.parentid'] = $catid; |
143 | 143 | $list['catalog.lists.refid'] = $prodid; |
144 | 144 | $list['catalog.lists.domain'] = 'product'; |
145 | 145 | |
146 | - if( isset( $listMap[$catid][$type] ) ) |
|
146 | + if (isset($listMap[$catid][$type])) |
|
147 | 147 | { |
148 | 148 | $listItem = $listMap[$catid][$type]; |
149 | - unset( $listItems[ $listItem->getId() ] ); |
|
149 | + unset($listItems[$listItem->getId()]); |
|
150 | 150 | } |
151 | 151 | else |
152 | 152 | { |
153 | 153 | $listItem = $listManager->createItem(); |
154 | 154 | } |
155 | 155 | |
156 | - $listItem->fromArray( $this->addListItemDefaults( $list, $pos++ ) ); |
|
157 | - $listManager->saveItem( $listItem, false ); |
|
156 | + $listItem->fromArray($this->addListItemDefaults($list, $pos++)); |
|
157 | + $listManager->saveItem($listItem, false); |
|
158 | 158 | } |
159 | 159 | } |
160 | 160 | |
161 | - $listManager->deleteItems( array_keys( $listItems ) ); |
|
162 | - $data = $this->getObject()->process( $product, $data ); |
|
161 | + $listManager->deleteItems(array_keys($listItems)); |
|
162 | + $data = $this->getObject()->process($product, $data); |
|
163 | 163 | |
164 | 164 | $manager->commit(); |
165 | 165 | } |
166 | - catch( \Exception $e ) |
|
166 | + catch (\Exception $e) |
|
167 | 167 | { |
168 | 168 | $manager->rollback(); |
169 | 169 | throw $e; |
@@ -180,13 +180,13 @@ discard block |
||
180 | 180 | * @param integer $pos Computed position of the list item in the associated list of items |
181 | 181 | * @return array Given associative list enriched by default values if they were not already set |
182 | 182 | */ |
183 | - protected function addListItemDefaults( array $list, $pos ) |
|
183 | + protected function addListItemDefaults(array $list, $pos) |
|
184 | 184 | { |
185 | - if( !isset( $list['catalog.lists.position'] ) ) { |
|
185 | + if (!isset($list['catalog.lists.position'])) { |
|
186 | 186 | $list['catalog.lists.position'] = $pos; |
187 | 187 | } |
188 | 188 | |
189 | - if( !isset( $list['catalog.lists.status'] ) ) { |
|
189 | + if (!isset($list['catalog.lists.status'])) { |
|
190 | 190 | $list['catalog.lists.status'] = 1; |
191 | 191 | } |
192 | 192 | |
@@ -200,10 +200,10 @@ discard block |
||
200 | 200 | * @param array $list Associative list of key/value pairs from the mapped data |
201 | 201 | * @return boolean True if the entry is valid, false if not |
202 | 202 | */ |
203 | - protected function checkEntry( array $list ) |
|
203 | + protected function checkEntry(array $list) |
|
204 | 204 | { |
205 | - if( !isset( $list['catalog.code'] ) || trim( $list['catalog.code'] ) === '' || isset( $list['catalog.lists.type'] ) |
|
206 | - && $this->listTypes !== null && !in_array( trim( $list['catalog.lists.type'] ), (array) $this->listTypes ) |
|
205 | + if (!isset($list['catalog.code']) || trim($list['catalog.code']) === '' || isset($list['catalog.lists.type']) |
|
206 | + && $this->listTypes !== null && !in_array(trim($list['catalog.lists.type']), (array) $this->listTypes) |
|
207 | 207 | ) { |
208 | 208 | return false; |
209 | 209 | } |
@@ -219,24 +219,24 @@ discard block |
||
219 | 219 | * @param array|null $types List of catalog list types |
220 | 220 | * @return array List of catalog list items |
221 | 221 | */ |
222 | - protected function getListItems( $prodid, $types ) |
|
222 | + protected function getListItems($prodid, $types) |
|
223 | 223 | { |
224 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'catalog/lists' ); |
|
224 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'catalog/lists'); |
|
225 | 225 | $search = $manager->createSearch(); |
226 | 226 | |
227 | 227 | $expr = array( |
228 | - $search->compare( '==', 'catalog.lists.domain', 'product' ), |
|
229 | - $search->compare( '==', 'catalog.lists.refid', $prodid ), |
|
228 | + $search->compare('==', 'catalog.lists.domain', 'product'), |
|
229 | + $search->compare('==', 'catalog.lists.refid', $prodid), |
|
230 | 230 | ); |
231 | 231 | |
232 | - if( $types !== null ) { |
|
233 | - $expr[] = $search->compare( '==', 'catalog.lists.type.code', $types ); |
|
232 | + if ($types !== null) { |
|
233 | + $expr[] = $search->compare('==', 'catalog.lists.type.code', $types); |
|
234 | 234 | } |
235 | 235 | |
236 | - $search->setConditions( $search->combine( '&&', $expr ) ); |
|
237 | - $search->setSortations( array( $search->sort( '+', 'catalog.lists.position' ) ) ); |
|
238 | - $search->setSlice( 0, 0x7FFFFFFF ); |
|
236 | + $search->setConditions($search->combine('&&', $expr)); |
|
237 | + $search->setSortations(array($search->sort('+', 'catalog.lists.position'))); |
|
238 | + $search->setSlice(0, 0x7FFFFFFF); |
|
239 | 239 | |
240 | - return $manager->searchItems( $search ); |
|
240 | + return $manager->searchItems($search); |
|
241 | 241 | } |
242 | 242 | } |
@@ -42,12 +42,12 @@ discard block |
||
42 | 42 | * @param array $mapping Associative list of field position in CSV as key and domain item key as value |
43 | 43 | * @param \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object Decorated processor |
44 | 44 | */ |
45 | - public function __construct( \Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
46 | - \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null ) |
|
45 | + public function __construct(\Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
46 | + \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null) |
|
47 | 47 | { |
48 | - parent::__construct( $context, $mapping, $object ); |
|
48 | + parent::__construct($context, $mapping, $object); |
|
49 | 49 | |
50 | - $this->cache = $this->getCache( 'stocktype' ); |
|
50 | + $this->cache = $this->getCache('stocktype'); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | |
@@ -58,53 +58,53 @@ discard block |
||
58 | 58 | * @param array $data List of CSV fields with position as key and data as value |
59 | 59 | * @return array List of data which hasn't been imported |
60 | 60 | */ |
61 | - public function process( \Aimeos\MShop\Product\Item\Iface $product, array $data ) |
|
61 | + public function process(\Aimeos\MShop\Product\Item\Iface $product, array $data) |
|
62 | 62 | { |
63 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'stock' ); |
|
63 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'stock'); |
|
64 | 64 | $manager->begin(); |
65 | 65 | |
66 | 66 | try |
67 | 67 | { |
68 | - $map = $this->getMappedChunk( $data, $this->getMapping() ); |
|
69 | - $items = $this->getStockItems( $product->getCode() ); |
|
68 | + $map = $this->getMappedChunk($data, $this->getMapping()); |
|
69 | + $items = $this->getStockItems($product->getCode()); |
|
70 | 70 | |
71 | - foreach( $map as $pos => $list ) |
|
71 | + foreach ($map as $pos => $list) |
|
72 | 72 | { |
73 | - if( !array_key_exists( 'stock.stocklevel', $list ) ) { |
|
73 | + if (!array_key_exists('stock.stocklevel', $list)) { |
|
74 | 74 | continue; |
75 | 75 | } |
76 | 76 | |
77 | - $stockType = trim( isset( $list['stock.type'] ) ? $list['stock.type'] : 'default' ); |
|
77 | + $stockType = trim(isset($list['stock.type']) ? $list['stock.type'] : 'default'); |
|
78 | 78 | |
79 | - if( !isset( $list['stock.typeid'] ) ) { |
|
80 | - $list['stock.typeid'] = $this->cache->get( $stockType ); |
|
79 | + if (!isset($list['stock.typeid'])) { |
|
80 | + $list['stock.typeid'] = $this->cache->get($stockType); |
|
81 | 81 | } |
82 | 82 | |
83 | - if( isset( $list['stock.dateback'] ) && trim( $list['stock.dateback'] ) === '' ) { |
|
83 | + if (isset($list['stock.dateback']) && trim($list['stock.dateback']) === '') { |
|
84 | 84 | $list['stock.dateback'] = null; |
85 | 85 | } |
86 | 86 | |
87 | - if( trim( $list['stock.stocklevel'] ) === '' ) { |
|
87 | + if (trim($list['stock.stocklevel']) === '') { |
|
88 | 88 | $list['stock.stocklevel'] = null; |
89 | 89 | } |
90 | 90 | |
91 | 91 | $list['stock.productcode'] = $product->getCode(); |
92 | 92 | |
93 | - if( ( $item = array_pop( $items ) ) === null ) { |
|
93 | + if (($item = array_pop($items)) === null) { |
|
94 | 94 | $item = $manager->createItem(); |
95 | 95 | } |
96 | 96 | |
97 | - $item->fromArray( $list ); |
|
98 | - $manager->saveItem( $item, false ); |
|
97 | + $item->fromArray($list); |
|
98 | + $manager->saveItem($item, false); |
|
99 | 99 | } |
100 | 100 | |
101 | - $manager->deleteItems( array_keys( $items ) ); |
|
101 | + $manager->deleteItems(array_keys($items)); |
|
102 | 102 | |
103 | - $data = $this->getObject()->process( $product, $data ); |
|
103 | + $data = $this->getObject()->process($product, $data); |
|
104 | 104 | |
105 | 105 | $manager->commit(); |
106 | 106 | } |
107 | - catch( \Exception $e ) |
|
107 | + catch (\Exception $e) |
|
108 | 108 | { |
109 | 109 | $manager->rollback(); |
110 | 110 | throw $e; |
@@ -120,13 +120,13 @@ discard block |
||
120 | 120 | * @param string $code Unique product code |
121 | 121 | * @return \Aimeos\MShop\Stock\Item\Iface[] Associative list of stock items |
122 | 122 | */ |
123 | - protected function getStockItems( $code ) |
|
123 | + protected function getStockItems($code) |
|
124 | 124 | { |
125 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'stock' ); |
|
125 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'stock'); |
|
126 | 126 | |
127 | 127 | $search = $manager->createSearch(); |
128 | - $search->setConditions( $search->compare( '==', 'stock.productcode', $code ) ); |
|
128 | + $search->setConditions($search->compare('==', 'stock.productcode', $code)); |
|
129 | 129 | |
130 | - return $manager->searchItems( $search ); |
|
130 | + return $manager->searchItems($search); |
|
131 | 131 | } |
132 | 132 | } |
@@ -43,10 +43,10 @@ discard block |
||
43 | 43 | * @param array $mapping Associative list of field position in CSV as key and domain item key as value |
44 | 44 | * @param \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object Decorated processor |
45 | 45 | */ |
46 | - public function __construct( \Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
47 | - \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null ) |
|
46 | + public function __construct(\Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
47 | + \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null) |
|
48 | 48 | { |
49 | - parent::__construct( $context, $mapping, $object ); |
|
49 | + parent::__construct($context, $mapping, $object); |
|
50 | 50 | |
51 | 51 | /** controller/common/product/import/csv/processor/product/listtypes |
52 | 52 | * Names of the product list types that are updated or removed |
@@ -73,11 +73,11 @@ discard block |
||
73 | 73 | * @see controller/common/product/import/csv/processor/price/listtypes |
74 | 74 | * @see controller/common/product/import/csv/processor/text/listtypes |
75 | 75 | */ |
76 | - $default = array( 'default', 'suggestion' ); |
|
76 | + $default = array('default', 'suggestion'); |
|
77 | 77 | $key = 'controller/common/product/import/csv/processor/product/listtypes'; |
78 | - $this->listTypes = $context->getConfig()->get( $key, $default ); |
|
78 | + $this->listTypes = $context->getConfig()->get($key, $default); |
|
79 | 79 | |
80 | - $this->cache = $this->getCache( 'product' ); |
|
80 | + $this->cache = $this->getCache('product'); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | |
@@ -88,13 +88,13 @@ discard block |
||
88 | 88 | * @param array $data List of CSV fields with position as key and data as value |
89 | 89 | * @return array List of data which hasn't been imported |
90 | 90 | */ |
91 | - public function process( \Aimeos\MShop\Product\Item\Iface $product, array $data ) |
|
91 | + public function process(\Aimeos\MShop\Product\Item\Iface $product, array $data) |
|
92 | 92 | { |
93 | 93 | $context = $this->getContext(); |
94 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'product' ); |
|
95 | - $separator = $context->getConfig()->get( 'controller/common/product/import/csv/separator', "\n" ); |
|
94 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'product'); |
|
95 | + $separator = $context->getConfig()->get('controller/common/product/import/csv/separator', "\n"); |
|
96 | 96 | |
97 | - $this->cache->set( $product ); |
|
97 | + $this->cache->set($product); |
|
98 | 98 | |
99 | 99 | $manager->begin(); |
100 | 100 | |
@@ -102,39 +102,39 @@ discard block |
||
102 | 102 | { |
103 | 103 | $types = []; |
104 | 104 | |
105 | - foreach( $this->getMappedChunk( $data, $this->getMapping() ) as $list ) |
|
105 | + foreach ($this->getMappedChunk($data, $this->getMapping()) as $list) |
|
106 | 106 | { |
107 | - if( $this->checkEntry( $list ) === false ) { |
|
107 | + if ($this->checkEntry($list) === false) { |
|
108 | 108 | continue; |
109 | 109 | } |
110 | 110 | |
111 | 111 | $listMap = []; |
112 | - $type = trim( isset( $list['product.lists.type'] ) ? $list['product.lists.type'] : 'default' ); |
|
112 | + $type = trim(isset($list['product.lists.type']) ? $list['product.lists.type'] : 'default'); |
|
113 | 113 | $types[] = $type; |
114 | 114 | |
115 | - foreach( explode( $separator, trim( $list['product.code'] ) ) as $code ) |
|
115 | + foreach (explode($separator, trim($list['product.code'])) as $code) |
|
116 | 116 | { |
117 | - $code = trim( $code ); |
|
117 | + $code = trim($code); |
|
118 | 118 | |
119 | - if( ( $prodid = $this->cache->get( $code ) ) === null ) |
|
119 | + if (($prodid = $this->cache->get($code)) === null) |
|
120 | 120 | { |
121 | 121 | $msg = 'No product for code "%1$s" available when importing product with code "%2$s"'; |
122 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( $msg, $code, $product->getCode() ) ); |
|
122 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf($msg, $code, $product->getCode())); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | $listMap[$prodid] = $list; |
126 | 126 | } |
127 | 127 | |
128 | - $manager->updateListItems( $product, $listMap, 'product', $type ); |
|
128 | + $manager->updateListItems($product, $listMap, 'product', $type); |
|
129 | 129 | } |
130 | 130 | |
131 | - $this->deleteListItems( $product->getId(), $types ); |
|
131 | + $this->deleteListItems($product->getId(), $types); |
|
132 | 132 | |
133 | - $data = $this->getObject()->process( $product, $data ); |
|
133 | + $data = $this->getObject()->process($product, $data); |
|
134 | 134 | |
135 | 135 | $manager->commit(); |
136 | 136 | } |
137 | - catch( \Exception $e ) |
|
137 | + catch (\Exception $e) |
|
138 | 138 | { |
139 | 139 | $manager->rollback(); |
140 | 140 | throw $e; |
@@ -150,10 +150,10 @@ discard block |
||
150 | 150 | * @param array $list Associative list of key/value pairs from the mapping |
151 | 151 | * @return boolean True if valid, false if not |
152 | 152 | */ |
153 | - protected function checkEntry( array $list ) |
|
153 | + protected function checkEntry(array $list) |
|
154 | 154 | { |
155 | - if( !isset( $list['product.code'] ) || trim( $list['product.code'] ) === '' || isset( $list['product.lists.type'] ) |
|
156 | - && $this->listTypes !== null && !in_array( trim( $list['product.lists.type'] ), (array) $this->listTypes ) |
|
155 | + if (!isset($list['product.code']) || trim($list['product.code']) === '' || isset($list['product.lists.type']) |
|
156 | + && $this->listTypes !== null && !in_array(trim($list['product.lists.type']), (array) $this->listTypes) |
|
157 | 157 | ) { |
158 | 158 | return false; |
159 | 159 | } |
@@ -168,19 +168,19 @@ discard block |
||
168 | 168 | * @param string $prodId Unique product ID |
169 | 169 | * @param array $types List of types that have been updated |
170 | 170 | */ |
171 | - protected function deleteListItems( $prodId, array $types ) |
|
171 | + protected function deleteListItems($prodId, array $types) |
|
172 | 172 | { |
173 | - $codes = array_diff( $this->listTypes, $types ); |
|
174 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product/lists' ); |
|
173 | + $codes = array_diff($this->listTypes, $types); |
|
174 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product/lists'); |
|
175 | 175 | |
176 | 176 | $search = $manager->createSearch(); |
177 | 177 | $expr = array( |
178 | - $search->compare( '==', 'product.lists.parentid', $prodId ), |
|
179 | - $search->compare( '==', 'product.lists.domain', 'product' ), |
|
180 | - $search->compare( '==', 'product.lists.type.code', $codes ), |
|
178 | + $search->compare('==', 'product.lists.parentid', $prodId), |
|
179 | + $search->compare('==', 'product.lists.domain', 'product'), |
|
180 | + $search->compare('==', 'product.lists.type.code', $codes), |
|
181 | 181 | ); |
182 | - $search->setConditions( $search->combine( '&&', $expr ) ); |
|
182 | + $search->setConditions($search->combine('&&', $expr)); |
|
183 | 183 | |
184 | - $manager->deleteItems( array_keys( $manager->searchItems( $search ) ) ); |
|
184 | + $manager->deleteItems(array_keys($manager->searchItems($search))); |
|
185 | 185 | } |
186 | 186 | } |