|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2011 |
|
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2022 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
namespace Aimeos\MShop\Order\Manager; |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
private $context; |
|
16
|
|
|
private $object; |
|
17
|
|
|
private $editor = ''; |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
protected function setUp() : void |
|
21
|
|
|
{ |
|
22
|
|
|
$this->editor = \TestHelper::context()->editor(); |
|
23
|
|
|
$this->context = \TestHelper::context(); |
|
24
|
|
|
$this->object = new \Aimeos\MShop\Order\Manager\Standard( $this->context ); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
protected function tearDown() : void |
|
29
|
|
|
{ |
|
30
|
|
|
unset( $this->object ); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
public function testAggregate() |
|
35
|
|
|
{ |
|
36
|
|
|
$search = $this->object->filter()->add( ['order.editor' => 'core'] ); |
|
37
|
|
|
$result = $this->object->aggregate( $search, 'order.channel' ); |
|
38
|
|
|
|
|
39
|
|
|
$this->assertEquals( 2, count( $result ) ); |
|
40
|
|
|
$this->assertArrayHasKey( 'web', $result ); |
|
41
|
|
|
$this->assertEquals( 3, $result->get( 'web' ) ); |
|
|
|
|
|
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
public function testAggregateMultiple() |
|
46
|
|
|
{ |
|
47
|
|
|
$cols = ['order.channel', 'order.statuspayment']; |
|
48
|
|
|
$search = $this->object->filter()->add( ['order.editor' => 'core'] )->order( $cols ); |
|
49
|
|
|
$result = $this->object->aggregate( $search, $cols ); |
|
50
|
|
|
|
|
51
|
|
|
$this->assertEquals( ['phone' => [6 => 1], 'web' => [5 => 1, 6 => 2]], $result->toArray() ); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
public function testAggregateAvg() |
|
56
|
|
|
{ |
|
57
|
|
|
$search = $this->object->filter()->add( ['order.editor' => 'core'] ); |
|
58
|
|
|
$result = $this->object->aggregate( $search, 'order.cmonth', 'order.price', 'avg' ); |
|
59
|
|
|
|
|
60
|
|
|
$this->assertEquals( 1, count( $result ) ); |
|
61
|
|
|
$this->assertEquals( '784.75', round( $result->first(), 2 ) ); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
public function testAggregateAvgMultiple() |
|
66
|
|
|
{ |
|
67
|
|
|
$cols = ['order.cmonth', 'order.statuspayment']; |
|
68
|
|
|
$search = $this->object->filter()->add( ['order.editor' => 'core'] )->order( $cols ); |
|
69
|
|
|
$result = $this->object->aggregate( $search, $cols, 'order.price', 'avg' ); |
|
70
|
|
|
|
|
71
|
|
|
$this->assertEquals( 1, count( $result ) ); |
|
72
|
|
|
$this->assertArrayHasKey( 5, $result->first() ); |
|
73
|
|
|
$this->assertArrayHasKey( 6, $result->first() ); |
|
74
|
|
|
$this->assertEquals( '13.50', round( $result->first()[5], 2 ) ); |
|
75
|
|
|
$this->assertEquals( '1041.83', round( $result->first()[6], 2 ) ); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
public function testAggregateSum() |
|
80
|
|
|
{ |
|
81
|
|
|
$search = $this->object->filter()->add( ['order.editor' => 'core'] ); |
|
82
|
|
|
$result = $this->object->aggregate( $search, 'order.cmonth', 'order.price', 'sum' ); |
|
83
|
|
|
|
|
84
|
|
|
$this->assertEquals( 1, count( $result ) ); |
|
85
|
|
|
$this->assertEquals( '3139.00', $result->first() ); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
|
|
89
|
|
|
public function testAggregateSumMultiple() |
|
90
|
|
|
{ |
|
91
|
|
|
$cols = ['order.cmonth', 'order.statuspayment']; |
|
92
|
|
|
$search = $this->object->filter()->add( ['order.editor' => 'core'] )->order( $cols ); |
|
93
|
|
|
$result = $this->object->aggregate( $search, $cols, 'order.price', 'sum' ); |
|
94
|
|
|
|
|
95
|
|
|
$this->assertEquals( 1, count( $result ) ); |
|
96
|
|
|
$this->assertArrayHasKey( 5, $result->first() ); |
|
97
|
|
|
$this->assertArrayHasKey( 6, $result->first() ); |
|
98
|
|
|
$this->assertEquals( '13.50', round( $result->first()[5], 2 ) ); |
|
99
|
|
|
$this->assertEquals( '3125.5', round( $result->first()[6], 2 ) ); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
|
|
103
|
|
|
public function testAggregateTimes() |
|
104
|
|
|
{ |
|
105
|
|
|
$search = $this->object->filter()->add( ['order.editor' => 'core'] ); |
|
106
|
|
|
$search->setSortations( array( $search->sort( '-', 'order.cdate' ) ) ); |
|
107
|
|
|
$result = $this->object->aggregate( $search, 'order.cmonth' )->toArray(); |
|
108
|
|
|
|
|
109
|
|
|
$this->assertEquals( 1, count( $result ) ); |
|
110
|
|
|
$this->assertEquals( 4, reset( $result ) ); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
|
|
114
|
|
|
public function testAggregateAddress() |
|
115
|
|
|
{ |
|
116
|
|
|
$search = $this->object->filter()->add( ['order.editor' => 'core'] ); |
|
117
|
|
|
$result = $this->object->aggregate( $search, 'order.address.countryid' )->toArray(); |
|
118
|
|
|
|
|
119
|
|
|
$this->assertEquals( 1, count( $result ) ); |
|
120
|
|
|
$this->assertArrayHasKey( 'DE', $result ); |
|
121
|
|
|
$this->assertEquals( 4, reset( $result ) ); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
|
|
125
|
|
|
public function testAggregateAddressMultiple() |
|
126
|
|
|
{ |
|
127
|
|
|
$cols = ['order.address.countryid', 'order.statuspayment']; |
|
128
|
|
|
$search = $this->object->filter()->add( ['order.editor' => 'core'] )->order( $cols ); |
|
129
|
|
|
$result = $this->object->aggregate( $search, $cols )->toArray(); |
|
130
|
|
|
|
|
131
|
|
|
$this->assertEquals( ['DE' => [5 => 1, 6 => 3]], $result ); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
|
|
135
|
|
|
public function testAggregateMonth() |
|
136
|
|
|
{ |
|
137
|
|
|
$search = $this->object->filter()->add( ['order.editor' => 'core'] ); |
|
138
|
|
|
$result = $this->object->aggregate( $search, 'order.channel' )->toArray(); |
|
139
|
|
|
|
|
140
|
|
|
$this->assertEquals( 2, count( $result ) ); |
|
141
|
|
|
$this->assertArrayHasKey( 'web', $result ); |
|
142
|
|
|
$this->assertEquals( 3, $result['web'] ); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
|
|
146
|
|
|
public function testClear() |
|
147
|
|
|
{ |
|
148
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->clear( [-1] ) ); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
|
|
152
|
|
|
public function testDeleteItems() |
|
153
|
|
|
{ |
|
154
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->delete( [-1] ) ); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
|
|
158
|
|
|
public function testGetResourceType() |
|
159
|
|
|
{ |
|
160
|
|
|
$result = $this->object->getResourceType(); |
|
161
|
|
|
|
|
162
|
|
|
$this->assertContains( 'order', $result ); |
|
163
|
|
|
$this->assertContains( 'order/status', $result ); |
|
164
|
|
|
$this->assertContains( 'order/address', $result ); |
|
165
|
|
|
$this->assertContains( 'order/coupon', $result ); |
|
166
|
|
|
$this->assertContains( 'order/product', $result ); |
|
167
|
|
|
$this->assertContains( 'order/product/attribute', $result ); |
|
168
|
|
|
$this->assertContains( 'order/service', $result ); |
|
169
|
|
|
$this->assertContains( 'order/service/attribute', $result ); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
|
|
173
|
|
|
public function testCreateItem() |
|
174
|
|
|
{ |
|
175
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Iface::class, $this->object->create() ); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
|
|
179
|
|
|
public function testGetItem() |
|
180
|
|
|
{ |
|
181
|
|
|
$search = $this->object->filter()->slice( 0, 1 ) |
|
182
|
|
|
->add( ['order.price' => '672.00', 'order.editor' => $this->editor] ); |
|
183
|
|
|
|
|
184
|
|
|
$item = $this->object->search( $search )->first( new \RuntimeException( 'No order item found' ) ); |
|
185
|
|
|
|
|
186
|
|
|
$actual = $this->object->get( $item->getId() ); |
|
187
|
|
|
|
|
188
|
|
|
$this->assertEquals( $item, $actual ); |
|
189
|
|
|
$this->assertEquals( '32.00', $item->getPrice()->getCosts() ); |
|
190
|
|
|
$this->assertEquals( '5.00', $item->getPrice()->getRebate() ); |
|
191
|
|
|
$this->assertEquals( '112.4034', $item->getPrice()->getTaxValue() ); |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
|
|
195
|
|
|
public function testSaveUpdateDeleteItem() |
|
196
|
|
|
{ |
|
197
|
|
|
$search = $this->object->filter()->slice( 0, 1 ) |
|
198
|
|
|
->add( ['order.channel' => 'phone', 'order.editor' => $this->editor] ); |
|
199
|
|
|
|
|
200
|
|
|
$item = $this->object->search( $search )->first( new \RuntimeException( 'No order item found' ) ); |
|
201
|
|
|
|
|
202
|
|
|
$item->setId( null ); |
|
203
|
|
|
$resultSaved = $this->object->save( $item ); |
|
204
|
|
|
$itemSaved = $this->object->get( $item->getId() ); |
|
205
|
|
|
|
|
206
|
|
|
$itemExp = clone $itemSaved; |
|
207
|
|
|
$itemExp->setChannel( 'web' ); |
|
208
|
|
|
$resultUpd = $this->object->save( $itemExp ); |
|
209
|
|
|
$itemUpd = $this->object->get( $itemExp->getId() ); |
|
210
|
|
|
|
|
211
|
|
|
$this->object->delete( $itemSaved->getId() ); |
|
212
|
|
|
|
|
213
|
|
|
|
|
214
|
|
|
$itemPrice = $item->getPrice(); |
|
215
|
|
|
$itemSavedPrice = $itemSaved->getPrice(); |
|
216
|
|
|
|
|
217
|
|
|
$this->assertTrue( $item->getId() !== null ); |
|
218
|
|
|
$this->assertEquals( $item->getId(), $itemSaved->getId() ); |
|
219
|
|
|
$this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() ); |
|
220
|
|
|
$this->assertEquals( $item->getChannel(), $itemSaved->getChannel() ); |
|
221
|
|
|
$this->assertEquals( $item->getDatePayment(), $itemSaved->getDatePayment() ); |
|
222
|
|
|
$this->assertEquals( $item->getDateDelivery(), $itemSaved->getDateDelivery() ); |
|
223
|
|
|
$this->assertEquals( $item->getStatusPayment(), $itemSaved->getStatusPayment() ); |
|
224
|
|
|
$this->assertEquals( $item->getStatusDelivery(), $itemSaved->getStatusDelivery() ); |
|
225
|
|
|
$this->assertEquals( $item->getInvoiceNumber(), $itemSaved->getInvoiceNumber() ); |
|
226
|
|
|
$this->assertEquals( $item->getRelatedId(), $itemSaved->getRelatedId() ); |
|
227
|
|
|
$this->assertEquals( $item->getCustomerId(), $itemSaved->getCustomerId() ); |
|
228
|
|
|
$this->assertEquals( $item->locale()->getLanguageId(), $itemSaved->locale()->getLanguageId() ); |
|
229
|
|
|
$this->assertEquals( $item->getCustomerReference(), $itemSaved->getCustomerReference() ); |
|
230
|
|
|
$this->assertEquals( $item->getComment(), $itemSaved->getComment() ); |
|
231
|
|
|
$this->assertEquals( $item->getSiteCode(), $itemSaved->getSiteCode() ); |
|
232
|
|
|
$this->assertEquals( $itemPrice->getValue(), $itemSavedPrice->getValue() ); |
|
233
|
|
|
$this->assertEquals( $itemPrice->getCosts(), $itemSavedPrice->getCosts() ); |
|
234
|
|
|
$this->assertEquals( $itemPrice->getRebate(), $itemSavedPrice->getRebate() ); |
|
235
|
|
|
$this->assertEquals( $itemPrice->getTaxValue(), $itemSavedPrice->getTaxValue() ); |
|
236
|
|
|
$this->assertEquals( $itemPrice->getCurrencyId(), $itemSavedPrice->getCurrencyId() ); |
|
237
|
|
|
|
|
238
|
|
|
$this->assertEquals( $this->editor, $itemSaved->editor() ); |
|
239
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() ); |
|
240
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() ); |
|
241
|
|
|
|
|
242
|
|
|
$itemExpPrice = $itemExp->getPrice(); |
|
243
|
|
|
$itemUpdPrice = $itemUpd->getPrice(); |
|
244
|
|
|
|
|
245
|
|
|
$this->assertEquals( $itemExp->getId(), $itemUpd->getId() ); |
|
246
|
|
|
$this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() ); |
|
247
|
|
|
$this->assertEquals( $itemExp->getChannel(), $itemUpd->getChannel() ); |
|
248
|
|
|
$this->assertEquals( $itemExp->getDatePayment(), $itemUpd->getDatePayment() ); |
|
249
|
|
|
$this->assertEquals( $itemExp->getDateDelivery(), $itemUpd->getDateDelivery() ); |
|
250
|
|
|
$this->assertEquals( $itemExp->getStatusPayment(), $itemUpd->getStatusPayment() ); |
|
251
|
|
|
$this->assertEquals( $itemExp->getStatusDelivery(), $itemUpd->getStatusDelivery() ); |
|
252
|
|
|
$this->assertEquals( $itemExp->getInvoiceNumber(), $itemUpd->getInvoiceNumber() ); |
|
253
|
|
|
$this->assertEquals( $itemExp->getRelatedId(), $itemUpd->getRelatedId() ); |
|
254
|
|
|
$this->assertEquals( $itemExp->getCustomerId(), $itemUpd->getCustomerId() ); |
|
255
|
|
|
$this->assertEquals( $itemExp->locale()->getLanguageId(), $itemUpd->locale()->getLanguageId() ); |
|
256
|
|
|
$this->assertEquals( $itemExp->getCustomerReference(), $itemUpd->getCustomerReference() ); |
|
257
|
|
|
$this->assertEquals( $itemExp->getComment(), $itemUpd->getComment() ); |
|
258
|
|
|
$this->assertEquals( $itemExp->getSiteCode(), $itemUpd->getSiteCode() ); |
|
259
|
|
|
$this->assertEquals( $itemExpPrice->getValue(), $itemUpdPrice->getValue() ); |
|
260
|
|
|
$this->assertEquals( $itemExpPrice->getCosts(), $itemUpdPrice->getCosts() ); |
|
261
|
|
|
$this->assertEquals( $itemExpPrice->getRebate(), $itemUpdPrice->getRebate() ); |
|
262
|
|
|
$this->assertEquals( $itemExpPrice->getTaxValue(), $itemUpdPrice->getTaxValue() ); |
|
263
|
|
|
$this->assertEquals( $itemExpPrice->getCurrencyId(), $itemUpdPrice->getCurrencyId() ); |
|
264
|
|
|
|
|
265
|
|
|
$this->assertEquals( $this->editor, $itemUpd->editor() ); |
|
266
|
|
|
$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() ); |
|
267
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() ); |
|
268
|
|
|
|
|
269
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultSaved ); |
|
270
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultUpd ); |
|
271
|
|
|
|
|
272
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
|
273
|
|
|
$this->object->get( $itemSaved->getId() ); |
|
274
|
|
|
} |
|
275
|
|
|
|
|
276
|
|
|
|
|
277
|
|
|
public function testSaveStatusUpdatePayment() |
|
278
|
|
|
{ |
|
279
|
|
|
$statusManager = \Aimeos\MShop::create( $this->context, 'order/status' ); |
|
280
|
|
|
|
|
281
|
|
|
$search = $this->object->filter(); |
|
282
|
|
|
$conditions = array( |
|
283
|
|
|
$search->compare( '==', 'order.channel', 'phone' ), |
|
284
|
|
|
$search->compare( '==', 'order.editor', $this->editor ) |
|
285
|
|
|
); |
|
286
|
|
|
$search->setConditions( $search->and( $conditions ) ); |
|
287
|
|
|
$results = $this->object->search( $search )->toArray(); |
|
288
|
|
|
|
|
289
|
|
|
if( ( $item = reset( $results ) ) === false ) { |
|
290
|
|
|
throw new \RuntimeException( 'No order item found.' ); |
|
291
|
|
|
} |
|
292
|
|
|
|
|
293
|
|
|
$item->setId( null ); |
|
294
|
|
|
$this->object->save( $item ); |
|
295
|
|
|
|
|
296
|
|
|
|
|
297
|
|
|
$search = $statusManager->filter(); |
|
298
|
|
|
$search->setConditions( $search->compare( '==', 'order.status.parentid', $item->getId() ) ); |
|
299
|
|
|
$results = $statusManager->search( $search )->toArray(); |
|
300
|
|
|
|
|
301
|
|
|
$this->object->delete( $item->getId() ); |
|
302
|
|
|
|
|
303
|
|
|
$this->assertEquals( 0, count( $results ) ); |
|
304
|
|
|
|
|
305
|
|
|
|
|
306
|
|
|
$item->setId( null ); |
|
307
|
|
|
$item->setStatusPayment( \Aimeos\MShop\Order\Item\Base::PAY_CANCELED ); |
|
308
|
|
|
$this->object->save( $item ); |
|
309
|
|
|
|
|
310
|
|
|
$search = $statusManager->filter(); |
|
311
|
|
|
$search->setConditions( $search->compare( '==', 'order.status.parentid', $item->getId() ) ); |
|
312
|
|
|
$results = $statusManager->search( $search )->toArray(); |
|
313
|
|
|
|
|
314
|
|
|
$this->object->delete( $item->getId() ); |
|
315
|
|
|
|
|
316
|
|
|
if( ( $statusItem = reset( $results ) ) === false ) { |
|
317
|
|
|
throw new \RuntimeException( 'No status item found' ); |
|
318
|
|
|
} |
|
319
|
|
|
|
|
320
|
|
|
$this->assertEquals( 1, count( $results ) ); |
|
321
|
|
|
$this->assertEquals( \Aimeos\MShop\Order\Item\Status\Base::STATUS_PAYMENT, $statusItem->getType() ); |
|
322
|
|
|
$this->assertEquals( \Aimeos\MShop\Order\Item\Base::PAY_CANCELED, $statusItem->getValue() ); |
|
323
|
|
|
} |
|
324
|
|
|
|
|
325
|
|
|
|
|
326
|
|
|
public function testSaveStatusUpdateDelivery() |
|
327
|
|
|
{ |
|
328
|
|
|
$statusManager = \Aimeos\MShop::create( $this->context, 'order/status' ); |
|
329
|
|
|
|
|
330
|
|
|
$search = $this->object->filter(); |
|
331
|
|
|
$conditions = array( |
|
332
|
|
|
$search->compare( '==', 'order.channel', 'phone' ), |
|
333
|
|
|
$search->compare( '==', 'order.editor', $this->editor ) |
|
334
|
|
|
); |
|
335
|
|
|
$search->setConditions( $search->and( $conditions ) ); |
|
336
|
|
|
$results = $this->object->search( $search )->toArray(); |
|
337
|
|
|
|
|
338
|
|
|
if( ( $item = reset( $results ) ) === false ) { |
|
339
|
|
|
throw new \RuntimeException( 'No order item found.' ); |
|
340
|
|
|
} |
|
341
|
|
|
|
|
342
|
|
|
$item->setId( null ); |
|
343
|
|
|
$this->object->save( $item ); |
|
344
|
|
|
|
|
345
|
|
|
|
|
346
|
|
|
$search = $statusManager->filter(); |
|
347
|
|
|
$search->setConditions( $search->compare( '==', 'order.status.parentid', $item->getId() ) ); |
|
348
|
|
|
$results = $statusManager->search( $search )->toArray(); |
|
349
|
|
|
|
|
350
|
|
|
$this->object->delete( $item->getId() ); |
|
351
|
|
|
|
|
352
|
|
|
$this->assertEquals( 0, count( $results ) ); |
|
353
|
|
|
|
|
354
|
|
|
|
|
355
|
|
|
$item->setId( null ); |
|
356
|
|
|
$item->setStatusDelivery( \Aimeos\MShop\Order\Item\Base::STAT_LOST ); |
|
357
|
|
|
$this->object->save( $item ); |
|
358
|
|
|
|
|
359
|
|
|
$search = $statusManager->filter(); |
|
360
|
|
|
$search->setConditions( $search->compare( '==', 'order.status.parentid', $item->getId() ) ); |
|
361
|
|
|
$results = $statusManager->search( $search )->toArray(); |
|
362
|
|
|
|
|
363
|
|
|
$this->object->delete( $item->getId() ); |
|
364
|
|
|
|
|
365
|
|
|
if( ( $statusItem = reset( $results ) ) === false ) { |
|
366
|
|
|
throw new \RuntimeException( 'No status item found' ); |
|
367
|
|
|
} |
|
368
|
|
|
|
|
369
|
|
|
$this->assertEquals( 1, count( $results ) ); |
|
370
|
|
|
$this->assertEquals( \Aimeos\MShop\Order\Item\Status\Base::STATUS_DELIVERY, $statusItem->getType() ); |
|
371
|
|
|
$this->assertEquals( \Aimeos\MShop\Order\Item\Base::STAT_LOST, $statusItem->getValue() ); |
|
372
|
|
|
} |
|
373
|
|
|
|
|
374
|
|
|
|
|
375
|
|
|
public function testCreateSearch() |
|
376
|
|
|
{ |
|
377
|
|
|
$this->assertInstanceOf( \Aimeos\Base\Criteria\Iface::class, $this->object->filter() ); |
|
378
|
|
|
} |
|
379
|
|
|
|
|
380
|
|
|
|
|
381
|
|
|
public function testCreateSearchDefault() |
|
382
|
|
|
{ |
|
383
|
|
|
$search = $this->object->filter( true ); |
|
384
|
|
|
|
|
385
|
|
|
$this->assertInstanceOf( \Aimeos\Base\Criteria\Iface::class, $search ); |
|
386
|
|
|
$this->assertInstanceOf( \Aimeos\Base\Criteria\Expression\Combine\Iface::class, $search->getConditions() ); |
|
387
|
|
|
|
|
388
|
|
|
$list = $search->getConditions()->getExpressions(); |
|
389
|
|
|
$this->assertArrayHasKey( 0, $list ); |
|
390
|
|
|
$this->assertInstanceOf( \Aimeos\Base\Criteria\Expression\Combine\Iface::class, $list[0] ); |
|
391
|
|
|
} |
|
392
|
|
|
|
|
393
|
|
|
|
|
394
|
|
|
public function testCreateSearchSite() |
|
395
|
|
|
{ |
|
396
|
|
|
$result = $this->object->filter( false, true ); |
|
397
|
|
|
$this->assertInstanceOf( \Aimeos\Base\Criteria\Expression\Combine\Iface::class, $result->getConditions() ); |
|
398
|
|
|
} |
|
399
|
|
|
|
|
400
|
|
|
|
|
401
|
|
|
public function testSearchItems() |
|
402
|
|
|
{ |
|
403
|
|
|
$siteid = $this->context->locale()->getSiteId(); |
|
404
|
|
|
|
|
405
|
|
|
$total = 0; |
|
406
|
|
|
$search = $this->object->filter(); |
|
407
|
|
|
$funcStatus = $search->make( 'order:status', ['typestatus', 'shipped'] ); |
|
408
|
|
|
|
|
409
|
|
|
$expr = []; |
|
410
|
|
|
$expr[] = $search->compare( '!=', 'order.id', null ); |
|
411
|
|
|
$expr[] = $search->compare( '==', 'order.siteid', $siteid ); |
|
412
|
|
|
$expr[] = $search->compare( '==', 'order.channel', 'web' ); |
|
413
|
|
|
$expr[] = $search->compare( '==', 'order.invoiceno', 'UINV-001' ); |
|
414
|
|
|
$expr[] = $search->compare( '==', 'order.datepayment', '2008-02-15 12:34:56' ); |
|
415
|
|
|
$expr[] = $search->compare( '==', 'order.datedelivery', null ); |
|
416
|
|
|
$expr[] = $search->compare( '==', 'order.statuspayment', \Aimeos\MShop\Order\Item\Base::PAY_RECEIVED ); |
|
417
|
|
|
$expr[] = $search->compare( '==', 'order.statusdelivery', 4 ); |
|
418
|
|
|
$expr[] = $search->compare( '==', 'order.relatedid', '' ); |
|
419
|
|
|
$expr[] = $search->compare( '==', 'order.sitecode', 'unittest' ); |
|
420
|
|
|
$expr[] = $search->compare( '>=', 'order.customerid', '' ); |
|
421
|
|
|
$expr[] = $search->compare( '==', 'order.languageid', 'de' ); |
|
422
|
|
|
$expr[] = $search->compare( '==', 'order.currencyid', 'EUR' ); |
|
423
|
|
|
$expr[] = $search->compare( '==', 'order.price', '53.50' ); |
|
424
|
|
|
$expr[] = $search->compare( '==', 'order.costs', '1.50' ); |
|
425
|
|
|
$expr[] = $search->compare( '==', 'order.rebate', '14.50' ); |
|
426
|
|
|
$expr[] = $search->compare( '~=', 'order.comment', 'This is a comment' ); |
|
427
|
|
|
$expr[] = $search->compare( '>=', 'order.mtime', '1970-01-01 00:00:00' ); |
|
428
|
|
|
$expr[] = $search->compare( '>=', 'order.ctime', '1970-01-01 00:00:00' ); |
|
429
|
|
|
$expr[] = $search->compare( '==', 'order.editor', $this->editor ); |
|
430
|
|
|
$expr[] = $search->compare( '==', $funcStatus, 1 ); |
|
431
|
|
|
|
|
432
|
|
|
$expr[] = $search->compare( '!=', 'order.status.id', null ); |
|
433
|
|
|
$expr[] = $search->compare( '==', 'order.status.siteid', $siteid ); |
|
434
|
|
|
$expr[] = $search->compare( '!=', 'order.status.parentid', null ); |
|
435
|
|
|
$expr[] = $search->compare( '>=', 'order.status.type', 'typestatus' ); |
|
436
|
|
|
$expr[] = $search->compare( '==', 'order.status.value', 'shipped' ); |
|
437
|
|
|
$expr[] = $search->compare( '>=', 'order.status.mtime', '1970-01-01 00:00:00' ); |
|
438
|
|
|
$expr[] = $search->compare( '>=', 'order.status.ctime', '1970-01-01 00:00:00' ); |
|
439
|
|
|
$expr[] = $search->compare( '==', 'order.status.editor', $this->editor ); |
|
440
|
|
|
|
|
441
|
|
|
$expr[] = $search->compare( '!=', 'order.address.id', null ); |
|
442
|
|
|
$expr[] = $search->compare( '==', 'order.address.siteid', $siteid ); |
|
443
|
|
|
$expr[] = $search->compare( '!=', 'order.address.parentid', null ); |
|
444
|
|
|
$expr[] = $search->compare( '==', 'order.address.type', 'payment' ); |
|
445
|
|
|
$expr[] = $search->compare( '==', 'order.address.company', 'Example company' ); |
|
446
|
|
|
$expr[] = $search->compare( '==', 'order.address.vatid', 'DE999999999' ); |
|
447
|
|
|
$expr[] = $search->compare( '==', 'order.address.salutation', 'mr' ); |
|
448
|
|
|
$expr[] = $search->compare( '==', 'order.address.title', '' ); |
|
449
|
|
|
$expr[] = $search->compare( '==', 'order.address.firstname', 'Our' ); |
|
450
|
|
|
$expr[] = $search->compare( '==', 'order.address.lastname', 'Unittest' ); |
|
451
|
|
|
$expr[] = $search->compare( '==', 'order.address.address1', 'Durchschnitt' ); |
|
452
|
|
|
$expr[] = $search->compare( '==', 'order.address.address2', '1' ); |
|
453
|
|
|
$expr[] = $search->compare( '==', 'order.address.address3', '' ); |
|
454
|
|
|
$expr[] = $search->compare( '==', 'order.address.postal', '20146' ); |
|
455
|
|
|
$expr[] = $search->compare( '==', 'order.address.city', 'Hamburg' ); |
|
456
|
|
|
$expr[] = $search->compare( '==', 'order.address.state', 'Hamburg' ); |
|
457
|
|
|
$expr[] = $search->compare( '==', 'order.address.countryid', 'DE' ); |
|
458
|
|
|
$expr[] = $search->compare( '==', 'order.address.languageid', 'de' ); |
|
459
|
|
|
$expr[] = $search->compare( '==', 'order.address.telephone', '055544332211' ); |
|
460
|
|
|
$expr[] = $search->compare( '==', 'order.address.email', '[email protected]' ); |
|
461
|
|
|
$expr[] = $search->compare( '==', 'order.address.telefax', '055544332213' ); |
|
462
|
|
|
$expr[] = $search->compare( '==', 'order.address.website', 'www.example.net' ); |
|
463
|
|
|
$expr[] = $search->compare( '>=', 'order.address.mtime', '1970-01-01 00:00:00' ); |
|
464
|
|
|
$expr[] = $search->compare( '>=', 'order.address.ctime', '1970-01-01 00:00:00' ); |
|
465
|
|
|
$expr[] = $search->compare( '==', 'order.address.editor', $this->editor ); |
|
466
|
|
|
|
|
467
|
|
|
$expr[] = $search->compare( '!=', 'order.coupon.id', null ); |
|
468
|
|
|
$expr[] = $search->compare( '==', 'order.coupon.siteid', $siteid ); |
|
469
|
|
|
$expr[] = $search->compare( '!=', 'order.coupon.parentid', null ); |
|
470
|
|
|
$expr[] = $search->compare( '!=', 'order.coupon.productid', null ); |
|
471
|
|
|
$expr[] = $search->compare( '==', 'order.coupon.code', 'OPQR' ); |
|
472
|
|
|
$expr[] = $search->compare( '>=', 'order.coupon.mtime', '1970-01-01 00:00:00' ); |
|
473
|
|
|
$expr[] = $search->compare( '>=', 'order.coupon.ctime', '1970-01-01 00:00:00' ); |
|
474
|
|
|
$expr[] = $search->compare( '>=', 'order.coupon.editor', '' ); |
|
475
|
|
|
|
|
476
|
|
|
$expr[] = $search->compare( '!=', 'order.product.id', null ); |
|
477
|
|
|
$expr[] = $search->compare( '==', 'order.product.siteid', $siteid ); |
|
478
|
|
|
$expr[] = $search->compare( '!=', 'order.product.parentid', null ); |
|
479
|
|
|
$expr[] = $search->compare( '!=', 'order.product.productid', null ); |
|
480
|
|
|
$expr[] = $search->compare( '==', 'order.product.prodcode', 'CNE' ); |
|
481
|
|
|
$expr[] = $search->compare( '==', 'order.product.vendor', 'Test vendor' ); |
|
482
|
|
|
$expr[] = $search->compare( '==', 'order.product.name', 'Cafe Noire Expresso' ); |
|
483
|
|
|
$expr[] = $search->compare( '==', 'order.product.mediaurl', 'somewhere/thump1.jpg' ); |
|
484
|
|
|
$expr[] = $search->compare( '==', 'order.product.quantity', 9 ); |
|
485
|
|
|
$expr[] = $search->compare( '==', 'order.product.price', '4.50' ); |
|
486
|
|
|
$expr[] = $search->compare( '==', 'order.product.costs', '0.00' ); |
|
487
|
|
|
$expr[] = $search->compare( '==', 'order.product.rebate', '0.00' ); |
|
488
|
|
|
$expr[] = $search->compare( '=~', 'order.product.taxrates', '{' ); |
|
489
|
|
|
$expr[] = $search->compare( '==', 'order.product.flags', 0 ); |
|
490
|
|
|
$expr[] = $search->compare( '==', 'order.product.position', 1 ); |
|
491
|
|
|
$expr[] = $search->compare( '==', 'order.product.statuspayment', 5 ); |
|
492
|
|
|
$expr[] = $search->compare( '==', 'order.product.statusdelivery', 1 ); |
|
493
|
|
|
$expr[] = $search->compare( '>=', 'order.product.mtime', '1970-01-01 00:00:00' ); |
|
494
|
|
|
$expr[] = $search->compare( '>=', 'order.product.ctime', '1970-01-01 00:00:00' ); |
|
495
|
|
|
$expr[] = $search->compare( '==', 'order.product.editor', $this->editor ); |
|
496
|
|
|
|
|
497
|
|
|
$expr[] = $search->compare( '!=', 'order.product.attribute.id', null ); |
|
498
|
|
|
$expr[] = $search->compare( '==', 'order.product.attribute.siteid', $siteid ); |
|
499
|
|
|
$expr[] = $search->compare( '!=', 'order.product.attribute.parentid', null ); |
|
500
|
|
|
$expr[] = $search->compare( '==', 'order.product.attribute.code', 'width' ); |
|
501
|
|
|
$expr[] = $search->compare( '==', 'order.product.attribute.value', '33' ); |
|
502
|
|
|
$expr[] = $search->compare( '==', 'order.product.attribute.name', '33' ); |
|
503
|
|
|
$expr[] = $search->compare( '==', 'order.product.attribute.quantity', 1 ); |
|
504
|
|
|
$expr[] = $search->compare( '>=', 'order.product.attribute.mtime', '1970-01-01 00:00:00' ); |
|
505
|
|
|
$expr[] = $search->compare( '>=', 'order.product.attribute.ctime', '1970-01-01 00:00:00' ); |
|
506
|
|
|
$expr[] = $search->compare( '==', 'order.product.attribute.editor', $this->editor ); |
|
507
|
|
|
|
|
508
|
|
|
$expr[] = $search->compare( '!=', 'order.service.id', null ); |
|
509
|
|
|
$expr[] = $search->compare( '==', 'order.service.siteid', $siteid ); |
|
510
|
|
|
$expr[] = $search->compare( '!=', 'order.service.parentid', null ); |
|
511
|
|
|
$expr[] = $search->compare( '==', 'order.service.type', 'payment' ); |
|
512
|
|
|
$expr[] = $search->compare( '==', 'order.service.code', 'unitpaymentcode' ); |
|
513
|
|
|
$expr[] = $search->compare( '==', 'order.service.name', 'unitpaymentcode' ); |
|
514
|
|
|
$expr[] = $search->compare( '==', 'order.service.price', '0.00' ); |
|
515
|
|
|
$expr[] = $search->compare( '==', 'order.service.costs', '0.00' ); |
|
516
|
|
|
$expr[] = $search->compare( '==', 'order.service.rebate', '0.00' ); |
|
517
|
|
|
$expr[] = $search->compare( '=~', 'order.service.taxrates', '{' ); |
|
518
|
|
|
$expr[] = $search->compare( '>=', 'order.service.mtime', '1970-01-01 00:00:00' ); |
|
519
|
|
|
$expr[] = $search->compare( '>=', 'order.service.ctime', '1970-01-01 00:00:00' ); |
|
520
|
|
|
$expr[] = $search->compare( '==', 'order.service.editor', $this->editor ); |
|
521
|
|
|
|
|
522
|
|
|
$expr[] = $search->compare( '!=', 'order.service.attribute.id', null ); |
|
523
|
|
|
$expr[] = $search->compare( '==', 'order.service.attribute.siteid', $siteid ); |
|
524
|
|
|
$expr[] = $search->compare( '!=', 'order.service.attribute.parentid', null ); |
|
525
|
|
|
$expr[] = $search->compare( '==', 'order.service.attribute.code', 'NAME' ); |
|
526
|
|
|
$expr[] = $search->compare( '==', 'order.service.attribute.value', '"CreditCard"' ); |
|
527
|
|
|
$expr[] = $search->compare( '==', 'order.service.attribute.quantity', 1 ); |
|
528
|
|
|
$expr[] = $search->compare( '>=', 'order.service.attribute.mtime', '1970-01-01 00:00:00' ); |
|
529
|
|
|
$expr[] = $search->compare( '>=', 'order.service.attribute.ctime', '1970-01-01 00:00:00' ); |
|
530
|
|
|
$expr[] = $search->compare( '==', 'order.service.attribute.editor', $this->editor ); |
|
531
|
|
|
|
|
532
|
|
|
|
|
533
|
|
|
|
|
534
|
|
|
$search->setConditions( $search->and( $expr ) ); |
|
535
|
|
|
$result = $this->object->search( $search, [], $total )->toArray(); |
|
536
|
|
|
|
|
537
|
|
|
$this->assertEquals( 1, count( $result ) ); |
|
538
|
|
|
$this->assertEquals( 1, $total ); |
|
539
|
|
|
} |
|
540
|
|
|
|
|
541
|
|
|
|
|
542
|
|
|
public function testSearchItemsTotal() |
|
543
|
|
|
{ |
|
544
|
|
|
$total = 0; |
|
545
|
|
|
$search = $this->object->filter()->slice( 0, 1 ); |
|
546
|
|
|
$conditions = array( |
|
547
|
|
|
$search->compare( '==', 'order.statuspayment', \Aimeos\MShop\Order\Item\Base::PAY_RECEIVED ), |
|
548
|
|
|
$search->compare( '==', 'order.editor', $this->editor ) |
|
549
|
|
|
); |
|
550
|
|
|
$search->setConditions( $search->and( $conditions ) ); |
|
551
|
|
|
$items = $this->object->search( $search, [], $total )->toArray(); |
|
552
|
|
|
|
|
553
|
|
|
$this->assertEquals( 1, count( $items ) ); |
|
554
|
|
|
$this->assertEquals( 3, $total ); |
|
555
|
|
|
|
|
556
|
|
|
foreach( $items as $itemId => $item ) { |
|
557
|
|
|
$this->assertEquals( $itemId, $item->getId() ); |
|
558
|
|
|
} |
|
559
|
|
|
} |
|
560
|
|
|
|
|
561
|
|
|
|
|
562
|
|
|
public function testSearchItemsRef() |
|
563
|
|
|
{ |
|
564
|
|
|
$total = 0; |
|
565
|
|
|
$search = $this->object->filter()->slice( 0, 1 ); |
|
566
|
|
|
$conditions = array( |
|
567
|
|
|
$search->compare( '==', 'order.datepayment', '2008-02-15 12:34:56' ), |
|
568
|
|
|
$search->compare( '==', 'order.editor', $this->editor ) |
|
569
|
|
|
); |
|
570
|
|
|
$search->setConditions( $search->and( $conditions ) ); |
|
571
|
|
|
$item = $this->object->search( $search, ['order/product'], $total )->first(); |
|
572
|
|
|
|
|
573
|
|
|
$this->assertEquals( 4, count( $item->getProducts() ) ); |
|
574
|
|
|
} |
|
575
|
|
|
|
|
576
|
|
|
|
|
577
|
|
|
public function testGetSubManager() |
|
578
|
|
|
{ |
|
579
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'address' ) ); |
|
580
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'address', 'Standard' ) ); |
|
581
|
|
|
|
|
582
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'coupon' ) ); |
|
583
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'coupon', 'Standard' ) ); |
|
584
|
|
|
|
|
585
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'product' ) ); |
|
586
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'product', 'Standard' ) ); |
|
587
|
|
|
|
|
588
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'service' ) ); |
|
589
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'service', 'Standard' ) ); |
|
590
|
|
|
|
|
591
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'status' ) ); |
|
592
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'status', 'Standard' ) ); |
|
593
|
|
|
|
|
594
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
|
595
|
|
|
$this->object->getSubManager( 'unknown' ); |
|
596
|
|
|
} |
|
597
|
|
|
|
|
598
|
|
|
|
|
599
|
|
|
public function testGetSubManagerInvalidName() |
|
600
|
|
|
{ |
|
601
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
|
602
|
|
|
$this->object->getSubManager( 'status', 'unknown' ); |
|
603
|
|
|
} |
|
604
|
|
|
|
|
605
|
|
|
|
|
606
|
|
|
public function testLoad() |
|
607
|
|
|
{ |
|
608
|
|
|
$item = $this->getOrderItem(); |
|
609
|
|
|
$order = $this->object->load( $item->getId() ); |
|
610
|
|
|
|
|
611
|
|
|
|
|
612
|
|
|
foreach( $order->getAddresses() as $addresses ) |
|
613
|
|
|
{ |
|
614
|
|
|
foreach( $addresses as $address ) |
|
615
|
|
|
{ |
|
616
|
|
|
$this->assertNotEquals( '', $address->getId() ); |
|
617
|
|
|
$this->assertNotEquals( '', $address->getId() ); |
|
618
|
|
|
$this->assertNotEquals( '', $address->getParentId() ); |
|
619
|
|
|
} |
|
620
|
|
|
} |
|
621
|
|
|
|
|
622
|
|
|
$this->assertEquals( 2, count( $order->getCoupons() ) ); |
|
623
|
|
|
|
|
624
|
|
|
foreach( $order->getCoupons() as $code => $products ) |
|
625
|
|
|
{ |
|
626
|
|
|
$this->assertNotEquals( '', $code ); |
|
627
|
|
|
|
|
628
|
|
|
foreach( $products as $product ) { |
|
629
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Product\Iface::class, $product ); |
|
630
|
|
|
} |
|
631
|
|
|
} |
|
632
|
|
|
|
|
633
|
|
|
foreach( $order->getProducts() as $product ) |
|
634
|
|
|
{ |
|
635
|
|
|
$this->assertNotEquals( '', $product->getId() ); |
|
636
|
|
|
$this->assertNotEquals( '', $product->getId() ); |
|
637
|
|
|
$this->assertNotEquals( '', $product->getParentId() ); |
|
638
|
|
|
$this->assertGreaterThan( 0, $product->getPosition() ); |
|
639
|
|
|
} |
|
640
|
|
|
|
|
641
|
|
|
foreach( $order->getServices() as $list ) |
|
642
|
|
|
{ |
|
643
|
|
|
foreach( $list as $service ) |
|
644
|
|
|
{ |
|
645
|
|
|
$this->assertNotEquals( '', $service->getId() ); |
|
646
|
|
|
$this->assertNotEquals( '', $service->getId() ); |
|
647
|
|
|
$this->assertNotEquals( '', $service->getParentId() ); |
|
648
|
|
|
} |
|
649
|
|
|
} |
|
650
|
|
|
} |
|
651
|
|
|
|
|
652
|
|
|
|
|
653
|
|
|
public function testLoadNone() |
|
654
|
|
|
{ |
|
655
|
|
|
$item = $this->getOrderItem(); |
|
656
|
|
|
$order = $this->object->load( $item->getId(), [] ); |
|
657
|
|
|
|
|
658
|
|
|
$this->assertEquals( [], $order->getProducts()->toArray() ); |
|
659
|
|
|
$this->assertEquals( [], $order->getCoupons()->toArray() ); |
|
660
|
|
|
$this->assertEquals( [], $order->getServices()->toArray() ); |
|
661
|
|
|
$this->assertEquals( [], $order->getAddresses()->toArray() ); |
|
662
|
|
|
} |
|
663
|
|
|
|
|
664
|
|
|
|
|
665
|
|
|
public function testLoadAddress() |
|
666
|
|
|
{ |
|
667
|
|
|
$item = $this->getOrderItem(); |
|
668
|
|
|
$order = $this->object->load( $item->getId(), ['order/address'] ); |
|
669
|
|
|
|
|
670
|
|
|
$this->assertGreaterThan( 0, count( $order->getAddresses() ) ); |
|
671
|
|
|
$this->assertEquals( [], $order->getCoupons()->toArray() ); |
|
672
|
|
|
$this->assertEquals( [], $order->getProducts()->toArray() ); |
|
673
|
|
|
$this->assertEquals( [], $order->getServices()->toArray() ); |
|
674
|
|
|
} |
|
675
|
|
|
|
|
676
|
|
|
|
|
677
|
|
|
public function testLoadProduct() |
|
678
|
|
|
{ |
|
679
|
|
|
$item = $this->getOrderItem(); |
|
680
|
|
|
$order = $this->object->load( $item->getId(), ['order/product'] ); |
|
681
|
|
|
|
|
682
|
|
|
$this->assertGreaterThan( 0, count( $order->getProducts() ) ); |
|
683
|
|
|
$this->assertEquals( [], $order->getCoupons()->toArray() ); |
|
684
|
|
|
$this->assertEquals( [], $order->getServices()->toArray() ); |
|
685
|
|
|
$this->assertEquals( [], $order->getAddresses()->toArray() ); |
|
686
|
|
|
} |
|
687
|
|
|
|
|
688
|
|
|
|
|
689
|
|
|
public function testLoadCoupon() |
|
690
|
|
|
{ |
|
691
|
|
|
$item = $this->getOrderItem(); |
|
692
|
|
|
$order = $this->object->load( $item->getId(), ['order/coupon'] ); |
|
693
|
|
|
|
|
694
|
|
|
$this->assertGreaterThan( 0, count( $order->getProducts() ) ); |
|
695
|
|
|
$this->assertGreaterThan( 0, count( $order->getCoupons() ) ); |
|
696
|
|
|
$this->assertEquals( [], $order->getServices()->toArray() ); |
|
697
|
|
|
$this->assertEquals( [], $order->getAddresses()->toArray() ); |
|
698
|
|
|
} |
|
699
|
|
|
|
|
700
|
|
|
|
|
701
|
|
|
public function testLoadService() |
|
702
|
|
|
{ |
|
703
|
|
|
$item = $this->getOrderItem(); |
|
704
|
|
|
$order = $this->object->load( $item->getId(), ['order/service'] ); |
|
705
|
|
|
|
|
706
|
|
|
$this->assertGreaterThan( 0, count( $order->getServices() ) ); |
|
707
|
|
|
$this->assertEquals( [], $order->getCoupons()->toArray() ); |
|
708
|
|
|
$this->assertEquals( [], $order->getProducts()->toArray() ); |
|
709
|
|
|
$this->assertEquals( [], $order->getAddresses()->toArray() ); |
|
710
|
|
|
} |
|
711
|
|
|
|
|
712
|
|
|
|
|
713
|
|
|
public function testLoadFresh() |
|
714
|
|
|
{ |
|
715
|
|
|
$item = $this->getOrderItem(); |
|
716
|
|
|
$ref = ['order/address', 'order/coupon', 'order/product', 'order/service']; |
|
717
|
|
|
$order = $this->object->load( $item->getId(), $ref, true ); |
|
718
|
|
|
|
|
719
|
|
|
|
|
720
|
|
|
$this->assertEquals( 2, count( $order->getCoupons() ) ); |
|
721
|
|
|
|
|
722
|
|
|
foreach( $order->getAddresses() as $list ) |
|
723
|
|
|
{ |
|
724
|
|
|
foreach( $list as $address ) |
|
725
|
|
|
{ |
|
726
|
|
|
$this->assertEquals( null, $address->getId() ); |
|
727
|
|
|
$this->assertEquals( null, $address->getParentId() ); |
|
728
|
|
|
} |
|
729
|
|
|
} |
|
730
|
|
|
|
|
731
|
|
|
foreach( $order->getProducts() as $product ) |
|
732
|
|
|
{ |
|
733
|
|
|
$this->assertEquals( null, $product->getId() ); |
|
734
|
|
|
$this->assertEquals( null, $product->getParentId() ); |
|
735
|
|
|
$this->assertEquals( null, $product->getPosition() ); |
|
736
|
|
|
} |
|
737
|
|
|
|
|
738
|
|
|
foreach( $order->getServices() as $list ) |
|
739
|
|
|
{ |
|
740
|
|
|
foreach( $list as $service ) |
|
741
|
|
|
{ |
|
742
|
|
|
$this->assertEquals( null, $service->getId() ); |
|
743
|
|
|
$this->assertEquals( null, $service->getParentId() ); |
|
744
|
|
|
} |
|
745
|
|
|
} |
|
746
|
|
|
} |
|
747
|
|
|
|
|
748
|
|
|
|
|
749
|
|
|
public function testLoadFreshNone() |
|
750
|
|
|
{ |
|
751
|
|
|
$item = $this->getOrderItem(); |
|
752
|
|
|
$order = $this->object->load( $item->getId(), [], true ); |
|
753
|
|
|
|
|
754
|
|
|
$this->assertEquals( [], $order->getAddresses()->toArray() ); |
|
755
|
|
|
$this->assertEquals( [], $order->getCoupons()->toArray() ); |
|
756
|
|
|
$this->assertEquals( [], $order->getProducts()->toArray() ); |
|
757
|
|
|
$this->assertEquals( [], $order->getServices()->toArray() ); |
|
758
|
|
|
} |
|
759
|
|
|
|
|
760
|
|
|
|
|
761
|
|
|
public function testLoadFreshAddress() |
|
762
|
|
|
{ |
|
763
|
|
|
$item = $this->getOrderItem(); |
|
764
|
|
|
$order = $this->object->load( $item->getId(), ['order/address'], true ); |
|
765
|
|
|
|
|
766
|
|
|
$this->assertGreaterThan( 0, count( $order->getAddresses() ) ); |
|
767
|
|
|
$this->assertEquals( [], $order->getCoupons()->toArray() ); |
|
768
|
|
|
$this->assertEquals( [], $order->getProducts()->toArray() ); |
|
769
|
|
|
$this->assertEquals( [], $order->getServices()->toArray() ); |
|
770
|
|
|
} |
|
771
|
|
|
|
|
772
|
|
|
|
|
773
|
|
|
public function testLoadFreshProduct() |
|
774
|
|
|
{ |
|
775
|
|
|
$item = $this->getOrderItem(); |
|
776
|
|
|
$order = $this->object->load( $item->getId(), ['order/product'], true ); |
|
777
|
|
|
|
|
778
|
|
|
$this->assertGreaterThan( 0, count( $order->getProducts() ) ); |
|
779
|
|
|
$this->assertEquals( [], $order->getCoupons()->toArray() ); |
|
780
|
|
|
$this->assertEquals( [], $order->getAddresses()->toArray() ); |
|
781
|
|
|
$this->assertEquals( [], $order->getServices()->toArray() ); |
|
782
|
|
|
} |
|
783
|
|
|
|
|
784
|
|
|
|
|
785
|
|
|
public function testLoadFreshCoupon() |
|
786
|
|
|
{ |
|
787
|
|
|
$item = $this->getOrderItem(); |
|
788
|
|
|
$order = $this->object->load( $item->getId(), ['order/coupon'], true ); |
|
789
|
|
|
|
|
790
|
|
|
$this->assertEquals( [], $order->getAddresses()->toArray() ); |
|
791
|
|
|
$this->assertEquals( 2, count( $order->getCoupons() ) ); |
|
792
|
|
|
$this->assertEquals( [], $order->getProducts()->toArray() ); |
|
793
|
|
|
$this->assertEquals( [], $order->getServices()->toArray() ); |
|
794
|
|
|
} |
|
795
|
|
|
|
|
796
|
|
|
|
|
797
|
|
|
public function testLoadFreshService() |
|
798
|
|
|
{ |
|
799
|
|
|
$item = $this->getOrderItem(); |
|
800
|
|
|
$order = $this->object->load( $item->getId(), ['order/service'], true ); |
|
801
|
|
|
|
|
802
|
|
|
$this->assertGreaterThan( 0, count( $order->getServices() ) ); |
|
803
|
|
|
$this->assertEquals( [], $order->getCoupons()->toArray() ); |
|
804
|
|
|
$this->assertEquals( [], $order->getAddresses()->toArray() ); |
|
805
|
|
|
$this->assertEquals( [], $order->getProducts()->toArray() ); |
|
806
|
|
|
} |
|
807
|
|
|
|
|
808
|
|
|
|
|
809
|
|
|
public function testSave() |
|
810
|
|
|
{ |
|
811
|
|
|
$item = $this->getOrderItem(); |
|
812
|
|
|
$ref = ['order/address', 'order/coupon', 'order/product', 'order/service']; |
|
813
|
|
|
|
|
814
|
|
|
$basket = $this->object->load( $item->getId(), $ref, true ); |
|
815
|
|
|
$this->object->save( $basket ); |
|
816
|
|
|
|
|
817
|
|
|
$newBasketId = $basket->getId(); |
|
818
|
|
|
|
|
819
|
|
|
$basket = $this->object->load( $newBasketId ); |
|
820
|
|
|
$this->object->delete( $newBasketId ); |
|
821
|
|
|
|
|
822
|
|
|
|
|
823
|
|
|
$this->assertEquals( $item->getCustomerId(), $basket->getCustomerId() ); |
|
824
|
|
|
$this->assertEquals( $basket->locale()->getSiteId(), $basket->getSiteId() ); |
|
825
|
|
|
|
|
826
|
|
|
$this->assertEquals( 1.50, $basket->getPrice()->getCosts() ); |
|
827
|
|
|
|
|
828
|
|
|
$pos = 1; |
|
829
|
|
|
$products = $basket->getProducts(); |
|
830
|
|
|
$this->assertEquals( 3, count( $products ) ); |
|
831
|
|
|
|
|
832
|
|
|
foreach( $products as $product ) |
|
833
|
|
|
{ |
|
834
|
|
|
if( $product->getProductCode() == 'U:MD' ) { |
|
835
|
|
|
continue; |
|
836
|
|
|
} |
|
837
|
|
|
$this->assertGreaterThanOrEqual( 2, count( $product->getAttributeItems() ) ); |
|
838
|
|
|
$this->assertEquals( $pos++, $product->getPosition() ); |
|
839
|
|
|
} |
|
840
|
|
|
|
|
841
|
|
|
$this->assertEquals( 2, count( $basket->getAddresses() ) ); |
|
842
|
|
|
|
|
843
|
|
|
$services = $basket->getServices(); |
|
844
|
|
|
$this->assertEquals( 2, count( $services ) ); |
|
845
|
|
|
|
|
846
|
|
|
$attributes = []; |
|
847
|
|
|
foreach( $services as $list ) |
|
848
|
|
|
{ |
|
849
|
|
|
foreach( $list as $service ) { |
|
850
|
|
|
$attributes[$service->getCode()] = $service->getAttributeItems(); |
|
851
|
|
|
} |
|
852
|
|
|
} |
|
853
|
|
|
|
|
854
|
|
|
$this->assertEquals( 9, count( $attributes['unitpaymentcode'] ) ); |
|
855
|
|
|
$this->assertEquals( 0, count( $attributes['unitdeliverycode'] ) ); |
|
856
|
|
|
|
|
857
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
|
858
|
|
|
$this->object->get( $newBasketId ); |
|
859
|
|
|
} |
|
860
|
|
|
|
|
861
|
|
|
|
|
862
|
|
|
public function testSaveExisting() |
|
863
|
|
|
{ |
|
864
|
|
|
$item = $this->getOrderItem(); |
|
865
|
|
|
$ref = ['order/address', 'order/coupon', 'order/product', 'order/service']; |
|
866
|
|
|
|
|
867
|
|
|
$basket = $this->object->load( $item->getId(), $ref, true ); |
|
868
|
|
|
$this->object->save( $basket ); |
|
869
|
|
|
$newBasketId = $basket->getId(); |
|
870
|
|
|
$this->object->save( $basket ); |
|
871
|
|
|
$newBasket = $this->object->load( $newBasketId ); |
|
872
|
|
|
|
|
873
|
|
|
$this->object->delete( $newBasketId ); |
|
874
|
|
|
|
|
875
|
|
|
foreach( $basket->getAddresses() as $type => $list ) |
|
876
|
|
|
{ |
|
877
|
|
|
$this->assertTrue( map( $list )->getId()->equals( map( $newBasket->getAddress( $type ) )->getId() ) ); |
|
878
|
|
|
} |
|
879
|
|
|
|
|
880
|
|
|
$this->assertTrue( $basket->getProducts()->getId()->equals( $newBasket->getProducts()->getId() ) ); |
|
881
|
|
|
|
|
882
|
|
|
foreach( $basket->getServices() as $type => $list ) |
|
883
|
|
|
{ |
|
884
|
|
|
$this->assertTrue( map( $list )->getId()->equals( map( $newBasket->getService( $type ) )->getId() ) ); |
|
885
|
|
|
} |
|
886
|
|
|
} |
|
887
|
|
|
|
|
888
|
|
|
|
|
889
|
|
|
public function testSaveBundles() |
|
890
|
|
|
{ |
|
891
|
|
|
$search = $this->object->filter()->add( ['order.sitecode' => 'unittest', 'order.price' => 2400.00] ); |
|
892
|
|
|
$item = $this->object->search( $search )->first( new \RuntimeException( 'No order found' ) ); |
|
893
|
|
|
|
|
894
|
|
|
$ref = ['order/address', 'order/coupon', 'order/product', 'order/service']; |
|
895
|
|
|
$basket = $this->object->load( $item->getId(), $ref, true ); |
|
896
|
|
|
$this->object->save( $basket ); |
|
897
|
|
|
|
|
898
|
|
|
$newBasketId = $basket->getId(); |
|
899
|
|
|
|
|
900
|
|
|
$basket = $this->object->load( $newBasketId ); |
|
901
|
|
|
$this->object->delete( $newBasketId ); |
|
902
|
|
|
|
|
903
|
|
|
$this->assertEquals( $item->getCustomerId(), $basket->getCustomerId() ); |
|
904
|
|
|
$this->assertEquals( $basket->locale()->getSiteId(), $basket->getSiteId() ); |
|
905
|
|
|
|
|
906
|
|
|
$pos = 1; |
|
907
|
|
|
$products = $basket->getProducts(); |
|
908
|
|
|
|
|
909
|
|
|
$this->assertEquals( 2, count( $products ) ); |
|
910
|
|
|
foreach( $products as $product ) |
|
911
|
|
|
{ |
|
912
|
|
|
$this->assertEquals( 2, count( $product->getProducts() ) ); |
|
913
|
|
|
$this->assertEquals( $pos, $product->getPosition() ); |
|
914
|
|
|
$pos += 3; // two sub-products in between |
|
915
|
|
|
} |
|
916
|
|
|
|
|
917
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
|
918
|
|
|
$this->object->get( $newBasketId ); |
|
919
|
|
|
} |
|
920
|
|
|
|
|
921
|
|
|
|
|
922
|
|
|
public function testSaveAddress() |
|
923
|
|
|
{ |
|
924
|
|
|
$item = $this->getOrderItem(); |
|
925
|
|
|
|
|
926
|
|
|
$basket = $this->object->load( $item->getId(), ['order/address'], true ); |
|
927
|
|
|
$this->object->save( $basket ); |
|
928
|
|
|
|
|
929
|
|
|
$newBasketId = $basket->getId(); |
|
930
|
|
|
|
|
931
|
|
|
$ref = ['order/address', 'order/coupon', 'order/product', 'order/service']; |
|
932
|
|
|
$basket = $this->object->load( $newBasketId, $ref ); |
|
933
|
|
|
$this->object->delete( $newBasketId ); |
|
934
|
|
|
|
|
935
|
|
|
$this->assertGreaterThan( 0, count( $basket->getAddresses() ) ); |
|
936
|
|
|
$this->assertEquals( [], $basket->getProducts()->toArray() ); |
|
937
|
|
|
$this->assertEquals( [], $basket->getCoupons()->toArray() ); |
|
938
|
|
|
$this->assertEquals( [], $basket->getServices()->toArray() ); |
|
939
|
|
|
} |
|
940
|
|
|
|
|
941
|
|
|
|
|
942
|
|
|
public function testSaveProduct() |
|
943
|
|
|
{ |
|
944
|
|
|
$item = $this->getOrderItem(); |
|
945
|
|
|
|
|
946
|
|
|
$basket = $this->object->load( $item->getId(), ['order/product'], true ); |
|
947
|
|
|
$this->object->save( $basket ); |
|
948
|
|
|
|
|
949
|
|
|
$newBasketId = $basket->getId(); |
|
950
|
|
|
|
|
951
|
|
|
$ref = ['order/address', 'order/coupon', 'order/product', 'order/service']; |
|
952
|
|
|
$basket = $this->object->load( $newBasketId, $ref ); |
|
953
|
|
|
$this->object->delete( $newBasketId ); |
|
954
|
|
|
|
|
955
|
|
|
$this->assertGreaterThan( 0, count( $basket->getProducts() ) ); |
|
956
|
|
|
$this->assertEquals( [], $basket->getAddresses()->toArray() ); |
|
957
|
|
|
$this->assertEquals( [], $basket->getCoupons()->toArray() ); |
|
958
|
|
|
$this->assertEquals( [], $basket->getServices()->toArray() ); |
|
959
|
|
|
} |
|
960
|
|
|
|
|
961
|
|
|
|
|
962
|
|
|
public function testSaveService() |
|
963
|
|
|
{ |
|
964
|
|
|
$item = $this->getOrderItem(); |
|
965
|
|
|
|
|
966
|
|
|
$basket = $this->object->load( $item->getId(), ['order/service'], true ); |
|
967
|
|
|
$this->object->save( $basket ); |
|
968
|
|
|
|
|
969
|
|
|
$newBasketId = $basket->getId(); |
|
970
|
|
|
|
|
971
|
|
|
$ref = ['order/address', 'order/coupon', 'order/product', 'order/service']; |
|
972
|
|
|
$basket = $this->object->load( $newBasketId, $ref ); |
|
973
|
|
|
$this->object->delete( $newBasketId ); |
|
974
|
|
|
|
|
975
|
|
|
$this->assertGreaterThan( 0, count( $basket->getServices() ) ); |
|
976
|
|
|
$this->assertEquals( [], $basket->getProducts()->toArray() ); |
|
977
|
|
|
$this->assertEquals( [], $basket->getAddresses()->toArray() ); |
|
978
|
|
|
$this->assertEquals( [], $basket->getCoupons()->toArray() ); |
|
979
|
|
|
} |
|
980
|
|
|
|
|
981
|
|
|
|
|
982
|
|
|
public function testLoadSaveCoupons() |
|
983
|
|
|
{ |
|
984
|
|
|
$search = $this->object->filter()->add( ['order.price' => '53.50'] ); |
|
985
|
|
|
$item = $this->object->search( $search )->first( new \RuntimeException( 'No order found' ) ); |
|
986
|
|
|
|
|
987
|
|
|
$basket = $this->object->load( $item->getId(), ['order/product'], true ); |
|
988
|
|
|
|
|
989
|
|
|
$this->assertEquals( '58.50', $basket->getPrice()->getValue() ); |
|
990
|
|
|
$this->assertEquals( '1.50', $basket->getPrice()->getCosts() ); |
|
991
|
|
|
$this->assertEquals( 0, count( $basket->getCoupons() ) ); |
|
992
|
|
|
|
|
993
|
|
|
$ref = ['order/address', 'order/coupon', 'order/product', 'order/service']; |
|
994
|
|
|
$productBasket = $this->object->load( $item->getId(), $ref, true ); |
|
|
|
|
|
|
995
|
|
|
|
|
996
|
|
|
$basket->addCoupon( 'CDEF' ); |
|
997
|
|
|
$basket->addCoupon( '90AB' ); |
|
998
|
|
|
$this->assertEquals( 2, count( $basket->getCoupons() ) ); |
|
999
|
|
|
|
|
1000
|
|
|
$this->object->save( $basket ); |
|
1001
|
|
|
$newBasket = $this->object->load( $basket->getId() ); |
|
1002
|
|
|
$this->object->delete( $newBasket->getId() ); |
|
1003
|
|
|
|
|
1004
|
|
|
$this->assertEquals( '52.50', $newBasket->getPrice()->getValue() ); |
|
1005
|
|
|
$this->assertEquals( '1.50', $newBasket->getPrice()->getCosts() ); |
|
1006
|
|
|
$this->assertEquals( '6.00', $newBasket->getPrice()->getRebate() ); |
|
1007
|
|
|
$this->assertEquals( 2, count( $newBasket->getCoupons() ) ); |
|
1008
|
|
|
} |
|
1009
|
|
|
|
|
1010
|
|
|
|
|
1011
|
|
|
/** |
|
1012
|
|
|
* Returns an order base item |
|
1013
|
|
|
* |
|
1014
|
|
|
* @return \Aimeos\MShop\Order\Item\Iface Order base item |
|
1015
|
|
|
* @throws \Exception If no found |
|
1016
|
|
|
*/ |
|
1017
|
|
|
protected function getOrderItem() |
|
1018
|
|
|
{ |
|
1019
|
|
|
$search = $this->object->filter()->add( [ |
|
1020
|
|
|
'order.sitecode' => 'unittest', |
|
1021
|
|
|
'order.price' => 53.50, |
|
1022
|
|
|
'order.rebate' => 14.50, |
|
1023
|
|
|
'order.editor' => $this->editor |
|
1024
|
|
|
] ); |
|
1025
|
|
|
|
|
1026
|
|
|
return $this->object->search( $search )->first( new \RuntimeException( 'No order found' ) ); |
|
1027
|
|
|
} |
|
1028
|
|
|
} |
|
1029
|
|
|
|