1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2011 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2017 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
namespace Aimeos\MShop\Order\Manager\Base; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
14
|
|
|
{ |
15
|
|
|
private $object; |
16
|
|
|
private $context; |
17
|
|
|
private $editor = ''; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
protected function setUp() |
21
|
|
|
{ |
22
|
|
|
$this->context = \TestHelperMShop::getContext(); |
23
|
|
|
$this->editor = $this->context->getEditor(); |
24
|
|
|
|
25
|
|
|
$this->object = new \Aimeos\MShop\Order\Manager\Base\Standard( $this->context ); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
protected function tearDown() |
30
|
|
|
{ |
31
|
|
|
unset( $this->object ); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
public function testAggregate() |
36
|
|
|
{ |
37
|
|
|
$search = $this->object->createSearch(); |
38
|
|
|
$search->setConditions( $search->compare( '==', 'order.base.editor', 'core:unittest' ) ); |
39
|
|
|
$result = $this->object->aggregate( $search, 'order.base.rebate' ); |
40
|
|
|
|
41
|
|
|
$this->assertEquals( 3, count( $result ) ); |
42
|
|
|
$this->assertArrayHasKey( '5.00', $result ); |
43
|
|
|
$this->assertEquals( 2, $result['5.00'] ); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
public function testAggregateAvg() |
48
|
|
|
{ |
49
|
|
|
$search = $this->object->createSearch(); |
50
|
|
|
$search->setConditions( $search->compare( '==', 'order.base.editor', 'core:unittest' ) ); |
51
|
|
|
$result = $this->object->aggregate( $search, 'order.base.address.email', 'order.base.price', 'avg' ); |
52
|
|
|
|
53
|
|
|
$this->assertEquals( 1, count( $result ) ); |
54
|
|
|
$this->assertArrayHasKey( '[email protected]', $result ); |
55
|
|
|
$this->assertEquals( '1384.750000', $result['[email protected]'] ); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
public function testAggregateSum() |
60
|
|
|
{ |
61
|
|
|
$search = $this->object->createSearch(); |
62
|
|
|
$search->setConditions( $search->compare( '==', 'order.base.editor', 'core:unittest' ) ); |
63
|
|
|
$result = $this->object->aggregate( $search, 'order.base.address.email', 'order.base.price', 'sum' ); |
64
|
|
|
|
65
|
|
|
$this->assertEquals( 1, count( $result ) ); |
66
|
|
|
$this->assertArrayHasKey( '[email protected]', $result ); |
67
|
|
|
$this->assertEquals( '5539.00', $result['[email protected]'] ); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
public function testCleanup() |
72
|
|
|
{ |
73
|
|
|
$this->object->cleanup( array( -1 ) ); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
public function testGetResourceType() |
78
|
|
|
{ |
79
|
|
|
$result = $this->object->getResourceType(); |
80
|
|
|
|
81
|
|
|
$this->assertContains( 'order/base', $result ); |
82
|
|
|
$this->assertContains( 'order/base/address', $result ); |
83
|
|
|
$this->assertContains( 'order/base/coupon', $result ); |
84
|
|
|
$this->assertContains( 'order/base/product', $result ); |
85
|
|
|
$this->assertContains( 'order/base/product/attribute', $result ); |
86
|
|
|
$this->assertContains( 'order/base/service', $result ); |
87
|
|
|
$this->assertContains( 'order/base/service/attribute', $result ); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
public function testCreateItem() |
92
|
|
|
{ |
93
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Order\\Item\\Base\\Iface', $this->object->createItem() ); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
public function testGetItem() |
98
|
|
|
{ |
99
|
|
|
$search = $this->object->createSearch(); |
100
|
|
|
$search->setConditions( $search->compare( '==', 'order.base.costs', '1.50' ) ); |
101
|
|
|
$results = $this->object->searchItems( $search ); |
102
|
|
|
|
103
|
|
|
if( ( $expected = reset( $results ) ) === false ) { |
104
|
|
|
throw new \Aimeos\MShop\Order\Exception( 'No order base item found' ); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
$this->assertEquals( $expected, $this->object->getItem( $expected->getId() ) ); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
public function testSaveInvalid() |
112
|
|
|
{ |
113
|
|
|
$this->setExpectedException( '\Aimeos\MShop\Order\Exception' ); |
114
|
|
|
$this->object->saveItem( new \Aimeos\MShop\Locale\Item\Standard() ); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
|
118
|
|
|
public function testSaveUpdateDeleteItem() |
119
|
|
|
{ |
120
|
|
|
$search = $this->object->createSearch(); |
121
|
|
|
$conditions = array( |
122
|
|
|
$search->compare( '==', 'order.base.costs', '1.50' ), |
123
|
|
|
$search->compare( '==', 'order.base.editor', $this->editor ) |
124
|
|
|
); |
125
|
|
|
$search->setConditions( $search->combine( '&&', $conditions ) ); |
126
|
|
|
$results = $this->object->searchItems( $search ); |
127
|
|
|
|
128
|
|
|
if( ( $item = reset( $results ) ) === false ) { |
129
|
|
|
throw new \RuntimeException( 'No order base item found.' ); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
$item->setId( null ); |
133
|
|
|
$item->setComment( 'Unittest1' ); |
134
|
|
|
$resultSaved = $this->object->saveItem( $item ); |
135
|
|
|
$itemSaved = $this->object->getItem( $item->getId() ); |
136
|
|
|
$itemPrice = $item->getPrice(); |
137
|
|
|
$itemSavedPrice = $item->getPrice(); |
138
|
|
|
|
139
|
|
|
$itemExp = clone $itemSaved; |
140
|
|
|
$itemExp->setComment( 'Unittest2' ); |
141
|
|
|
$itemExp->setCustomerId( 'unittest2' ); |
142
|
|
|
$resultUpd = $this->object->saveItem( $itemExp ); |
143
|
|
|
$itemUpd = $this->object->getItem( $itemExp->getId() ); |
144
|
|
|
$itemExpPrice = $itemExp->getPrice(); |
145
|
|
|
$itemUpdPrice = $itemUpd->getPrice(); |
146
|
|
|
|
147
|
|
|
|
148
|
|
|
$this->object->deleteItem( $itemSaved->getId() ); |
149
|
|
|
|
150
|
|
|
|
151
|
|
|
$this->assertTrue( $item->getId() !== null ); |
152
|
|
|
$this->assertEquals( $item->getId(), $itemSaved->getId() ); |
153
|
|
|
$this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() ); |
154
|
|
|
$this->assertEquals( $item->getCustomerId(), $itemSaved->getCustomerId() ); |
155
|
|
|
$this->assertEquals( $item->getLocale()->getLanguageId(), $itemSaved->getLocale()->getLanguageId() ); |
156
|
|
|
$this->assertEquals( $item->getSiteCode(), $itemSaved->getSiteCode() ); |
157
|
|
|
$this->assertEquals( $itemPrice->getValue(), $itemSavedPrice->getValue() ); |
158
|
|
|
$this->assertEquals( $itemPrice->getCosts(), $itemSavedPrice->getCosts() ); |
159
|
|
|
$this->assertEquals( $itemPrice->getRebate(), $itemSavedPrice->getRebate() ); |
160
|
|
|
$this->assertEquals( $itemPrice->getCurrencyId(), $itemSavedPrice->getCurrencyId() ); |
161
|
|
|
$this->assertEquals( $item->getProducts(), $itemSaved->getProducts() ); |
162
|
|
|
$this->assertEquals( $item->getAddresses(), $itemSaved->getAddresses() ); |
163
|
|
|
$this->assertEquals( $item->getCoupons(), $itemSaved->getCoupons() ); |
164
|
|
|
$this->assertEquals( $item->getServices(), $itemSaved->getServices() ); |
165
|
|
|
$this->assertEquals( $item->getComment(), $itemSaved->getComment() ); |
166
|
|
|
$this->assertEquals( $item->getStatus(), $itemSaved->getStatus() ); |
167
|
|
|
$this->assertEquals( $item->getSiteCode(), $itemSaved->getSiteCode() ); |
168
|
|
|
|
169
|
|
|
$this->assertEquals( $this->editor, $itemSaved->getEditor() ); |
170
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() ); |
171
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() ); |
172
|
|
|
|
173
|
|
|
$this->assertEquals( $itemExp->getId(), $itemUpd->getId() ); |
174
|
|
|
$this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() ); |
175
|
|
|
$this->assertEquals( $itemExp->getCustomerId(), $itemUpd->getCustomerId() ); |
176
|
|
|
$this->assertEquals( $itemExp->getLocale()->getLanguageId(), $itemUpd->getLocale()->getLanguageId() ); |
177
|
|
|
$this->assertEquals( $itemExp->getSiteCode(), $itemUpd->getSiteCode() ); |
178
|
|
|
$this->assertEquals( $itemExpPrice->getValue(), $itemUpdPrice->getValue() ); |
179
|
|
|
$this->assertEquals( $itemExpPrice->getCosts(), $itemUpdPrice->getCosts() ); |
180
|
|
|
$this->assertEquals( $itemExpPrice->getRebate(), $itemUpdPrice->getRebate() ); |
181
|
|
|
$this->assertEquals( $itemExpPrice->getCurrencyId(), $itemUpdPrice->getCurrencyId() ); |
182
|
|
|
$this->assertEquals( $itemExp->getProducts(), $itemUpd->getProducts() ); |
183
|
|
|
$this->assertEquals( $itemExp->getAddresses(), $itemUpd->getAddresses() ); |
184
|
|
|
$this->assertEquals( $itemExp->getCoupons(), $itemUpd->getCoupons() ); |
185
|
|
|
$this->assertEquals( $itemExp->getServices(), $itemUpd->getServices() ); |
186
|
|
|
$this->assertEquals( $itemExp->getComment(), $itemUpd->getComment() ); |
187
|
|
|
$this->assertEquals( $itemExp->getStatus(), $itemUpd->getStatus() ); |
188
|
|
|
$this->assertEquals( $itemExp->getSiteCode(), $itemUpd->getSiteCode() ); |
189
|
|
|
|
190
|
|
|
$this->assertEquals( $this->editor, $itemUpd->getEditor() ); |
191
|
|
|
$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() ); |
192
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() ); |
193
|
|
|
|
194
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Iface', $resultSaved ); |
195
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Iface', $resultUpd ); |
196
|
|
|
|
197
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
198
|
|
|
$this->object->getItem( $itemSaved->getId() ); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
|
202
|
|
|
public function testCreateSearch() |
203
|
|
|
{ |
204
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $this->object->createSearch() ); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
|
208
|
|
|
public function testCreateSearchDefault() |
209
|
|
|
{ |
210
|
|
|
$search = $this->object->createSearch( true ); |
211
|
|
|
|
212
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $search ); |
213
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Expression\\Combine\\Iface', $search->getConditions() ); |
214
|
|
|
|
215
|
|
|
$list = $search->getConditions()->getExpressions(); |
216
|
|
|
$this->assertArrayHasKey( 0, $list ); |
217
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Expression\\Compare\\Iface', $list[0] ); |
218
|
|
|
$this->assertEquals( 'order.base.customerid', $list[0]->getName() ); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
|
222
|
|
|
public function testSearchItems() |
223
|
|
|
{ |
224
|
|
|
$siteid = $this->context->getLocale()->getSiteId(); |
225
|
|
|
|
226
|
|
|
$total = 0; |
227
|
|
|
$search = $this->object->createSearch(); |
228
|
|
|
|
229
|
|
|
$expr = []; |
230
|
|
|
$expr[] = $search->compare( '!=', 'order.base.id', null ); |
231
|
|
|
$expr[] = $search->compare( '==', 'order.base.siteid', $siteid ); |
232
|
|
|
$expr[] = $search->compare( '==', 'order.base.sitecode', 'unittest' ); |
233
|
|
|
$expr[] = $search->compare( '>=', 'order.base.customerid', '' ); |
234
|
|
|
$expr[] = $search->compare( '==', 'order.base.languageid', 'de' ); |
235
|
|
|
$expr[] = $search->compare( '==', 'order.base.currencyid', 'EUR' ); |
236
|
|
|
$expr[] = $search->compare( '==', 'order.base.price', '53.50' ); |
237
|
|
|
$expr[] = $search->compare( '==', 'order.base.costs', '1.50' ); |
238
|
|
|
$expr[] = $search->compare( '==', 'order.base.rebate', '14.50' ); |
239
|
|
|
$expr[] = $search->compare( '~=', 'order.base.comment', 'This is a comment' ); |
240
|
|
|
$expr[] = $search->compare( '>=', 'order.base.mtime', '1970-01-01 00:00:00' ); |
241
|
|
|
$expr[] = $search->compare( '>=', 'order.base.ctime', '1970-01-01 00:00:00' ); |
242
|
|
|
$expr[] = $search->compare( '==', 'order.base.editor', $this->editor ); |
243
|
|
|
|
244
|
|
|
$expr[] = $search->compare( '!=', 'order.base.address.id', null ); |
245
|
|
|
$expr[] = $search->compare( '==', 'order.base.address.siteid', $siteid ); |
246
|
|
|
$expr[] = $search->compare( '!=', 'order.base.address.baseid', null ); |
247
|
|
|
$expr[] = $search->compare( '==', 'order.base.address.type', 'payment' ); |
248
|
|
|
$expr[] = $search->compare( '==', 'order.base.address.company', '' ); |
249
|
|
|
$expr[] = $search->compare( '==', 'order.base.address.vatid', '' ); |
250
|
|
|
$expr[] = $search->compare( '==', 'order.base.address.salutation', 'mr' ); |
251
|
|
|
$expr[] = $search->compare( '==', 'order.base.address.title', '' ); |
252
|
|
|
$expr[] = $search->compare( '==', 'order.base.address.firstname', 'Our' ); |
253
|
|
|
$expr[] = $search->compare( '==', 'order.base.address.lastname', 'Unittest' ); |
254
|
|
|
$expr[] = $search->compare( '==', 'order.base.address.address1', 'Durchschnitt' ); |
255
|
|
|
$expr[] = $search->compare( '==', 'order.base.address.address2', '1' ); |
256
|
|
|
$expr[] = $search->compare( '==', 'order.base.address.address3', '' ); |
257
|
|
|
$expr[] = $search->compare( '==', 'order.base.address.postal', '20146' ); |
258
|
|
|
$expr[] = $search->compare( '==', 'order.base.address.city', 'Hamburg' ); |
259
|
|
|
$expr[] = $search->compare( '==', 'order.base.address.state', 'Hamburg' ); |
260
|
|
|
$expr[] = $search->compare( '==', 'order.base.address.countryid', 'DE' ); |
261
|
|
|
$expr[] = $search->compare( '==', 'order.base.address.languageid', 'de' ); |
262
|
|
|
$expr[] = $search->compare( '==', 'order.base.address.telephone', '055544332211' ); |
263
|
|
|
$expr[] = $search->compare( '==', 'order.base.address.email', '[email protected]' ); |
264
|
|
|
$expr[] = $search->compare( '==', 'order.base.address.telefax', '055544332213' ); |
265
|
|
|
$expr[] = $search->compare( '==', 'order.base.address.website', 'www.metaways.net' ); |
266
|
|
|
$expr[] = $search->compare( '>=', 'order.base.address.mtime', '1970-01-01 00:00:00' ); |
267
|
|
|
$expr[] = $search->compare( '>=', 'order.base.address.ctime', '1970-01-01 00:00:00' ); |
268
|
|
|
$expr[] = $search->compare( '==', 'order.base.address.editor', $this->editor ); |
269
|
|
|
|
270
|
|
|
$expr[] = $search->compare( '!=', 'order.base.coupon.id', null ); |
271
|
|
|
$expr[] = $search->compare( '==', 'order.base.coupon.siteid', $siteid ); |
272
|
|
|
$expr[] = $search->compare( '!=', 'order.base.coupon.baseid', null ); |
273
|
|
|
$expr[] = $search->compare( '!=', 'order.base.coupon.productid', null ); |
274
|
|
|
$expr[] = $search->compare( '==', 'order.base.coupon.code', 'OPQR' ); |
275
|
|
|
$expr[] = $search->compare( '>=', 'order.base.coupon.mtime', '1970-01-01 00:00:00' ); |
276
|
|
|
$expr[] = $search->compare( '>=', 'order.base.coupon.ctime', '1970-01-01 00:00:00' ); |
277
|
|
|
$expr[] = $search->compare( '>=', 'order.base.coupon.editor', '' ); |
278
|
|
|
|
279
|
|
|
$expr[] = $search->compare( '!=', 'order.base.product.id', null ); |
280
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.siteid', $siteid ); |
281
|
|
|
$expr[] = $search->compare( '!=', 'order.base.product.baseid', null ); |
282
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.orderproductid', null ); |
283
|
|
|
$expr[] = $search->compare( '>=', 'order.base.product.type', '' ); |
284
|
|
|
$expr[] = $search->compare( '!=', 'order.base.product.productid', null ); |
285
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.prodcode', 'CNE' ); |
286
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.suppliercode', 'unitsupplier' ); |
287
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.name', 'Cafe Noire Expresso' ); |
288
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.mediaurl', 'somewhere/thump1.jpg' ); |
289
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.quantity', 9 ); |
290
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.price', '4.50' ); |
291
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.costs', '0.00' ); |
292
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.rebate', '0.00' ); |
293
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.taxrate', '0.00' ); |
294
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.flags', 0 ); |
295
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.position', 1 ); |
296
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.status', 1 ); |
297
|
|
|
$expr[] = $search->compare( '>=', 'order.base.product.mtime', '1970-01-01 00:00:00' ); |
298
|
|
|
$expr[] = $search->compare( '>=', 'order.base.product.ctime', '1970-01-01 00:00:00' ); |
299
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.editor', $this->editor ); |
300
|
|
|
|
301
|
|
|
$expr[] = $search->compare( '!=', 'order.base.product.attribute.id', null ); |
302
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.attribute.siteid', $siteid ); |
303
|
|
|
$expr[] = $search->compare( '!=', 'order.base.product.attribute.parentid', null ); |
304
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.attribute.code', 'width' ); |
305
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.attribute.value', '33' ); |
306
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.attribute.name', '33' ); |
307
|
|
|
$expr[] = $search->compare( '>=', 'order.base.product.attribute.mtime', '1970-01-01 00:00:00' ); |
308
|
|
|
$expr[] = $search->compare( '>=', 'order.base.product.attribute.ctime', '1970-01-01 00:00:00' ); |
309
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.attribute.editor', $this->editor ); |
310
|
|
|
|
311
|
|
|
$expr[] = $search->compare( '!=', 'order.base.service.id', null ); |
312
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.siteid', $siteid ); |
313
|
|
|
$expr[] = $search->compare( '!=', 'order.base.service.baseid', null ); |
314
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.type', 'payment' ); |
315
|
|
|
$expr[] = $search->compare( '!=', 'order.base.service.serviceid', null ); |
316
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.code', 'OGONE' ); |
317
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.name', 'ogone' ); |
318
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.price', '0.00' ); |
319
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.costs', '0.00' ); |
320
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.rebate', '0.00' ); |
321
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.taxrate', '0.00' ); |
322
|
|
|
$expr[] = $search->compare( '>=', 'order.base.service.mtime', '1970-01-01 00:00:00' ); |
323
|
|
|
$expr[] = $search->compare( '>=', 'order.base.service.ctime', '1970-01-01 00:00:00' ); |
324
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.editor', $this->editor ); |
325
|
|
|
|
326
|
|
|
$expr[] = $search->compare( '!=', 'order.base.service.attribute.id', null ); |
327
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.attribute.siteid', $siteid ); |
328
|
|
|
$expr[] = $search->compare( '!=', 'order.base.service.attribute.parentid', null ); |
329
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.attribute.code', 'NAME' ); |
330
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.attribute.value', '"CreditCard"' ); |
331
|
|
|
$expr[] = $search->compare( '>=', 'order.base.service.attribute.mtime', '1970-01-01 00:00:00' ); |
332
|
|
|
$expr[] = $search->compare( '>=', 'order.base.service.attribute.ctime', '1970-01-01 00:00:00' ); |
333
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.attribute.editor', $this->editor ); |
334
|
|
|
|
335
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
336
|
|
|
$ref = ['order/base/address', 'order/base/coupon', 'order/base/product', 'order/base/service']; |
337
|
|
|
$result = $this->object->searchItems( $search, $ref, $total ); |
338
|
|
|
|
339
|
|
|
$this->assertEquals( 1, $total ); |
340
|
|
|
$this->assertEquals( 1, count( $result ) ); |
341
|
|
|
|
342
|
|
|
$item = reset( $result ); |
343
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Order\Item\Base\Iface', $item ); |
344
|
|
|
$this->assertEquals( 2, count( $item->getAddresses() ) ); |
345
|
|
|
$this->assertEquals( 2, count( $item->getCoupons() ) ); |
346
|
|
|
$this->assertEquals( 4, count( $item->getProducts() ) ); |
347
|
|
|
$this->assertEquals( 2, count( $item->getServices() ) ); |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
|
351
|
|
|
public function testSearchItemsTotal() |
352
|
|
|
{ |
353
|
|
|
$search = $this->object->createSearch(); |
354
|
|
|
$conditions = array( |
355
|
|
|
$search->compare( '>=', 'order.base.customerid', '' ), |
356
|
|
|
$search->compare( '==', 'order.base.editor', $this->editor ) |
357
|
|
|
); |
358
|
|
|
$search->setConditions( $search->combine( '&&', $conditions ) ); |
359
|
|
|
$search->setSlice( 0, 1 ); |
360
|
|
|
$total = 0; |
361
|
|
|
$items = $this->object->searchItems( $search, [], $total ); |
362
|
|
|
$this->assertEquals( 1, count( $items ) ); |
363
|
|
|
$this->assertEquals( 4, $total ); |
364
|
|
|
|
365
|
|
|
foreach( $items as $itemId => $item ) { |
366
|
|
|
$this->assertEquals( $itemId, $item->getId() ); |
367
|
|
|
} |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
|
371
|
|
|
public function testSearchItemsDefault() |
372
|
|
|
{ |
373
|
|
|
$search = $this->object->createSearch( true ); |
374
|
|
|
$items = $this->object->searchItems( $search ); |
375
|
|
|
|
376
|
|
|
$this->assertEquals( 0, count( $items ) ); |
377
|
|
|
} |
378
|
|
|
|
379
|
|
|
|
380
|
|
|
public function testGetSubManager() |
381
|
|
|
{ |
382
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'address' ) ); |
383
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'address', 'Standard' ) ); |
384
|
|
|
|
385
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'coupon' ) ); |
386
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'coupon', 'Standard' ) ); |
387
|
|
|
|
388
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'product' ) ); |
389
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'product', 'Standard' ) ); |
390
|
|
|
|
391
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'service' ) ); |
392
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'service', 'Standard' ) ); |
393
|
|
|
|
394
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
395
|
|
|
$this->object->getSubManager( 'unknown' ); |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
|
399
|
|
|
public function testGetSubManagerInvalidName() |
400
|
|
|
{ |
401
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
402
|
|
|
$this->object->getSubManager( 'address', 'unknown' ); |
403
|
|
|
} |
404
|
|
|
|
405
|
|
|
|
406
|
|
|
public function testLoad() |
407
|
|
|
{ |
408
|
|
|
$item = $this->getOrderItem(); |
409
|
|
|
$order = $this->object->load( $item->getId() ); |
410
|
|
|
|
411
|
|
|
|
412
|
|
|
foreach( $order->getAddresses() as $address ) |
413
|
|
|
{ |
414
|
|
|
$this->assertInternalType( 'string', $address->getId() ); |
415
|
|
|
$this->assertNotEquals( '', $address->getId() ); |
416
|
|
|
$this->assertInternalType( 'integer', $address->getBaseId() ); |
417
|
|
|
} |
418
|
|
|
|
419
|
|
|
$this->assertEquals( 2, count( $order->getCoupons() ) ); |
420
|
|
|
|
421
|
|
|
foreach( $order->getCoupons() as $code => $products ) |
422
|
|
|
{ |
423
|
|
|
$this->assertNotEquals( '', $code ); |
424
|
|
|
|
425
|
|
|
foreach( $products as $product ) { |
426
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Order\\Item\\Base\\Product\\Iface', $product ); |
427
|
|
|
} |
428
|
|
|
} |
429
|
|
|
|
430
|
|
|
foreach( $order->getProducts() as $product ) |
431
|
|
|
{ |
432
|
|
|
$this->assertInternalType( 'string', $product->getId() ); |
433
|
|
|
$this->assertNotEquals( '', $product->getId() ); |
434
|
|
|
$this->assertInternalType( 'integer', $product->getBaseId() ); |
435
|
|
|
$this->assertGreaterThan( 0, $product->getPosition() ); |
436
|
|
|
} |
437
|
|
|
|
438
|
|
|
foreach( $order->getServices() as $service ) |
439
|
|
|
{ |
440
|
|
|
$this->assertInternalType( 'string', $service->getId() ); |
441
|
|
|
$this->assertNotEquals( '', $service->getId() ); |
442
|
|
|
$this->assertInternalType( 'integer', $service->getBaseId() ); |
443
|
|
|
} |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
|
447
|
|
|
public function testLoadNone() |
448
|
|
|
{ |
449
|
|
|
$item = $this->getOrderItem(); |
450
|
|
|
$order = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Manager\Base\Base::PARTS_NONE ); |
451
|
|
|
|
452
|
|
|
$this->assertEquals( [], $order->getProducts() ); |
453
|
|
|
$this->assertEquals( [], $order->getCoupons() ); |
454
|
|
|
$this->assertEquals( [], $order->getServices() ); |
455
|
|
|
$this->assertEquals( [], $order->getAddresses() ); |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
|
459
|
|
|
public function testLoadAddress() |
460
|
|
|
{ |
461
|
|
|
$item = $this->getOrderItem(); |
462
|
|
|
$order = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Manager\Base\Base::PARTS_ADDRESS ); |
463
|
|
|
|
464
|
|
|
$this->assertGreaterThan( 0, count( $order->getAddresses() ) ); |
465
|
|
|
$this->assertEquals( [], $order->getCoupons() ); |
466
|
|
|
$this->assertEquals( [], $order->getProducts() ); |
467
|
|
|
$this->assertEquals( [], $order->getServices() ); |
468
|
|
|
} |
469
|
|
|
|
470
|
|
|
|
471
|
|
|
public function testLoadProduct() |
472
|
|
|
{ |
473
|
|
|
$item = $this->getOrderItem(); |
474
|
|
|
$order = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Manager\Base\Base::PARTS_PRODUCT ); |
475
|
|
|
|
476
|
|
|
$this->assertGreaterThan( 0, count( $order->getProducts() ) ); |
477
|
|
|
$this->assertEquals( [], $order->getCoupons() ); |
478
|
|
|
$this->assertEquals( [], $order->getServices() ); |
479
|
|
|
$this->assertEquals( [], $order->getAddresses() ); |
480
|
|
|
} |
481
|
|
|
|
482
|
|
|
|
483
|
|
|
public function testLoadCoupon() |
484
|
|
|
{ |
485
|
|
|
$item = $this->getOrderItem(); |
486
|
|
|
$order = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Manager\Base\Base::PARTS_COUPON ); |
487
|
|
|
|
488
|
|
|
$this->assertGreaterThan( 0, count( $order->getProducts() ) ); |
489
|
|
|
$this->assertGreaterThan( 0, count( $order->getCoupons() ) ); |
490
|
|
|
$this->assertEquals( [], $order->getServices() ); |
491
|
|
|
$this->assertEquals( [], $order->getAddresses() ); |
492
|
|
|
} |
493
|
|
|
|
494
|
|
|
|
495
|
|
|
public function testLoadService() |
496
|
|
|
{ |
497
|
|
|
$item = $this->getOrderItem(); |
498
|
|
|
$order = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Manager\Base\Base::PARTS_SERVICE ); |
499
|
|
|
|
500
|
|
|
$this->assertGreaterThan( 0, count( $order->getServices() ) ); |
501
|
|
|
$this->assertEquals( [], $order->getCoupons() ); |
502
|
|
|
$this->assertEquals( [], $order->getProducts() ); |
503
|
|
|
$this->assertEquals( [], $order->getAddresses() ); |
504
|
|
|
} |
505
|
|
|
|
506
|
|
|
|
507
|
|
|
public function testLoadFresh() |
508
|
|
|
{ |
509
|
|
|
$item = $this->getOrderItem(); |
510
|
|
|
$order = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Manager\Base\Base::PARTS_ALL, true ); |
511
|
|
|
|
512
|
|
|
|
513
|
|
|
$this->assertEquals( 0, count( $order->getCoupons() ) ); |
514
|
|
|
|
515
|
|
|
foreach( $order->getAddresses() as $address ) |
516
|
|
|
{ |
517
|
|
|
$this->assertEquals( null, $address->getId() ); |
518
|
|
|
$this->assertEquals( null, $address->getBaseId() ); |
519
|
|
|
} |
520
|
|
|
|
521
|
|
|
foreach( $order->getProducts() as $product ) |
522
|
|
|
{ |
523
|
|
|
$this->assertEquals( null, $product->getId() ); |
524
|
|
|
$this->assertEquals( null, $product->getBaseId() ); |
525
|
|
|
$this->assertEquals( null, $product->getPosition() ); |
526
|
|
|
} |
527
|
|
|
|
528
|
|
|
foreach( $order->getServices() as $service ) |
529
|
|
|
{ |
530
|
|
|
$this->assertEquals( null, $service->getId() ); |
531
|
|
|
$this->assertEquals( null, $service->getBaseId() ); |
532
|
|
|
} |
533
|
|
|
} |
534
|
|
|
|
535
|
|
|
|
536
|
|
|
public function testLoadFreshNone() |
537
|
|
|
{ |
538
|
|
|
$item = $this->getOrderItem(); |
539
|
|
|
$order = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Manager\Base\Base::PARTS_NONE, true ); |
540
|
|
|
|
541
|
|
|
$this->assertEquals( [], $order->getAddresses() ); |
542
|
|
|
$this->assertEquals( [], $order->getCoupons() ); |
543
|
|
|
$this->assertEquals( [], $order->getProducts() ); |
544
|
|
|
$this->assertEquals( [], $order->getServices() ); |
545
|
|
|
} |
546
|
|
|
|
547
|
|
|
|
548
|
|
|
public function testLoadFreshAddress() |
549
|
|
|
{ |
550
|
|
|
$item = $this->getOrderItem(); |
551
|
|
|
$order = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Manager\Base\Base::PARTS_ADDRESS, true ); |
552
|
|
|
|
553
|
|
|
$this->assertGreaterThan( 0, count( $order->getAddresses() ) ); |
554
|
|
|
$this->assertEquals( [], $order->getCoupons() ); |
555
|
|
|
$this->assertEquals( [], $order->getProducts() ); |
556
|
|
|
$this->assertEquals( [], $order->getServices() ); |
557
|
|
|
} |
558
|
|
|
|
559
|
|
|
|
560
|
|
|
public function testLoadFreshProduct() |
561
|
|
|
{ |
562
|
|
|
$item = $this->getOrderItem(); |
563
|
|
|
$order = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Manager\Base\Base::PARTS_PRODUCT, true ); |
564
|
|
|
|
565
|
|
|
$this->assertGreaterThan( 0, count( $order->getProducts() ) ); |
566
|
|
|
$this->assertEquals( [], $order->getCoupons() ); |
567
|
|
|
$this->assertEquals( [], $order->getAddresses() ); |
568
|
|
|
$this->assertEquals( [], $order->getServices() ); |
569
|
|
|
} |
570
|
|
|
|
571
|
|
|
|
572
|
|
|
public function testLoadFreshCoupon() |
573
|
|
|
{ |
574
|
|
|
$item = $this->getOrderItem(); |
575
|
|
|
$order = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Manager\Base\Base::PARTS_COUPON, true ); |
576
|
|
|
|
577
|
|
|
$this->assertEquals( [], $order->getAddresses() ); |
578
|
|
|
$this->assertEquals( [], $order->getCoupons() ); |
579
|
|
|
$this->assertEquals( [], $order->getProducts() ); |
580
|
|
|
$this->assertEquals( [], $order->getServices() ); |
581
|
|
|
} |
582
|
|
|
|
583
|
|
|
|
584
|
|
|
public function testLoadFreshService() |
585
|
|
|
{ |
586
|
|
|
$item = $this->getOrderItem(); |
587
|
|
|
$order = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Manager\Base\Base::PARTS_SERVICE, true ); |
588
|
|
|
|
589
|
|
|
$this->assertGreaterThan( 0, count( $order->getServices() ) ); |
590
|
|
|
$this->assertEquals( [], $order->getCoupons() ); |
591
|
|
|
$this->assertEquals( [], $order->getAddresses() ); |
592
|
|
|
$this->assertEquals( [], $order->getProducts() ); |
593
|
|
|
} |
594
|
|
|
|
595
|
|
|
|
596
|
|
|
public function testStore() |
597
|
|
|
{ |
598
|
|
|
$item = $this->getOrderItem(); |
599
|
|
|
|
600
|
|
|
$basket = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Manager\Base\Base::PARTS_ALL, true ); |
601
|
|
|
$this->object->store( $basket ); |
602
|
|
|
|
603
|
|
|
$newBasketId = $basket->getId(); |
604
|
|
|
|
605
|
|
|
$basket = $this->object->load( $newBasketId ); |
606
|
|
|
$this->object->deleteItem( $newBasketId ); |
607
|
|
|
|
608
|
|
|
|
609
|
|
|
$this->assertEquals( $item->getCustomerId(), $basket->getCustomerId() ); |
610
|
|
|
$this->assertEquals( $basket->getLocale()->getSiteId(), $basket->getSiteId() ); |
611
|
|
|
|
612
|
|
|
$this->assertEquals( 6.50, $basket->getPrice()->getCosts() ); |
613
|
|
|
|
614
|
|
|
$pos = 1; |
615
|
|
|
$products = $basket->getProducts(); |
616
|
|
|
$this->assertEquals( 4, count( $products ) ); |
617
|
|
|
|
618
|
|
|
foreach( $products as $product ) |
619
|
|
|
{ |
620
|
|
|
$this->assertEquals( 2, count( $product->getAttributes() ) ); |
621
|
|
|
$this->assertEquals( $pos++, $product->getPosition() ); |
622
|
|
|
} |
623
|
|
|
|
624
|
|
|
$this->assertEquals( 2, count( $basket->getAddresses() ) ); |
625
|
|
|
|
626
|
|
|
$services = $basket->getServices(); |
627
|
|
|
$this->assertEquals( 2, count( $services ) ); |
628
|
|
|
|
629
|
|
|
$attributes = []; |
630
|
|
|
foreach( $services as $service ) { |
631
|
|
|
$attributes[$service->getCode()] = $service->getAttributes(); |
632
|
|
|
} |
633
|
|
|
|
634
|
|
|
$this->assertEquals( 9, count( $attributes['OGONE'] ) ); |
635
|
|
|
$this->assertEquals( 0, count( $attributes['73'] ) ); |
636
|
|
|
|
637
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
638
|
|
|
$this->object->getItem( $newBasketId ); |
639
|
|
|
} |
640
|
|
|
|
641
|
|
|
|
642
|
|
|
public function testStoreExisting() |
643
|
|
|
{ |
644
|
|
|
$item = $this->getOrderItem(); |
645
|
|
|
|
646
|
|
|
$basket = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Manager\Base\Base::PARTS_ALL, true ); |
647
|
|
|
$this->object->store( $basket ); |
648
|
|
|
$newBasketId = $basket->getId(); |
649
|
|
|
$this->object->store( $basket ); |
650
|
|
|
$newBasket = $this->object->load( $newBasketId ); |
651
|
|
|
|
652
|
|
|
$this->object->deleteItem( $newBasketId ); |
653
|
|
|
|
654
|
|
|
|
655
|
|
|
$newAddresses = $newBasket->getAddresses(); |
656
|
|
|
|
657
|
|
|
foreach( $basket->getAddresses() as $key => $address ) { |
658
|
|
|
$this->assertEquals( $address->getId(), $newAddresses[$key]->getId() ); |
659
|
|
|
} |
660
|
|
|
|
661
|
|
|
$newProducts = $newBasket->getProducts(); |
662
|
|
|
|
663
|
|
|
foreach( $basket->getProducts() as $key => $product ) |
664
|
|
|
{ |
665
|
|
|
// key+1 is because of the array_splice() in \Aimeos\MShop\Order\Item\Base\Standard::addProduct() |
666
|
|
|
// so it doesn't make sense to hand over the key as second parameter to addProduct() in |
667
|
|
|
// \Aimeos\MShop\Order\Manager\Base\Standard::loadFresh() to try to enforce a 1-based numbering |
668
|
|
|
$this->assertEquals( $product->getId(), $newProducts[$key + 1]->getId() ); |
669
|
|
|
$this->assertEquals( $product->getPosition(), $newProducts[$key + 1]->getPosition() ); |
670
|
|
|
} |
671
|
|
|
|
672
|
|
|
$newServices = $newBasket->getServices(); |
673
|
|
|
|
674
|
|
|
foreach( $basket->getServices() as $key => $service ) { |
675
|
|
|
$this->assertEquals( $service->getId(), $newServices[$key]->getId() ); |
676
|
|
|
} |
677
|
|
|
} |
678
|
|
|
|
679
|
|
|
|
680
|
|
|
public function testStoreBundles() |
681
|
|
|
{ |
682
|
|
|
$search = $this->object->createSearch(); |
683
|
|
|
|
684
|
|
|
$expr = []; |
685
|
|
|
$expr[] = $search->compare( '==', 'order.base.sitecode', 'unittest' ); |
686
|
|
|
$expr[] = $search->compare( '==', 'order.base.price', 4800.00 ); |
687
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
688
|
|
|
$results = $this->object->searchItems( $search ); |
689
|
|
|
|
690
|
|
|
if( ( $item = reset( $results ) ) == false ) { |
691
|
|
|
throw new \RuntimeException( 'No order found' ); |
692
|
|
|
} |
693
|
|
|
|
694
|
|
|
$basket = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Manager\Base\Base::PARTS_ALL, true ); |
695
|
|
|
$this->object->store( $basket ); |
696
|
|
|
|
697
|
|
|
$newBasketId = $basket->getId(); |
698
|
|
|
|
699
|
|
|
$basket = $this->object->load( $newBasketId ); |
700
|
|
|
$this->object->deleteItem( $newBasketId ); |
701
|
|
|
|
702
|
|
|
$this->assertEquals( $item->getCustomerId(), $basket->getCustomerId() ); |
703
|
|
|
$this->assertEquals( $basket->getLocale()->getSiteId(), $basket->getSiteId() ); |
704
|
|
|
|
705
|
|
|
$pos = 1; |
706
|
|
|
$products = $basket->getProducts(); |
707
|
|
|
|
708
|
|
|
$this->assertEquals( 2, count( $products ) ); |
709
|
|
|
foreach( $products as $product ) |
710
|
|
|
{ |
711
|
|
|
$this->assertEquals( 2, count( $product->getProducts() ) ); |
712
|
|
|
$this->assertEquals( $pos, $product->getPosition() ); |
713
|
|
|
$pos += 3; // two sub-products in between |
714
|
|
|
} |
715
|
|
|
|
716
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
717
|
|
|
$this->object->getItem( $newBasketId ); |
718
|
|
|
} |
719
|
|
|
|
720
|
|
|
|
721
|
|
|
public function testStoreNone() |
722
|
|
|
{ |
723
|
|
|
$item = $this->getOrderItem(); |
724
|
|
|
|
725
|
|
|
$basket = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Manager\Base\Base::PARTS_ALL, true ); |
726
|
|
|
$this->object->store( $basket, \Aimeos\MShop\Order\Manager\Base\Base::PARTS_NONE ); |
727
|
|
|
|
728
|
|
|
$newBasketId = $basket->getId(); |
729
|
|
|
|
730
|
|
|
$basket = $this->object->load( $newBasketId, \Aimeos\MShop\Order\Manager\Base\Base::PARTS_ALL ); |
731
|
|
|
$this->object->deleteItem( $newBasketId ); |
732
|
|
|
|
733
|
|
|
$this->assertEquals( [], $basket->getCoupons() ); |
734
|
|
|
$this->assertEquals( [], $basket->getAddresses() ); |
735
|
|
|
$this->assertEquals( [], $basket->getProducts() ); |
736
|
|
|
$this->assertEquals( [], $basket->getServices() ); |
737
|
|
|
} |
738
|
|
|
|
739
|
|
|
|
740
|
|
|
public function testStoreAddress() |
741
|
|
|
{ |
742
|
|
|
$item = $this->getOrderItem(); |
743
|
|
|
|
744
|
|
|
$basket = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Manager\Base\Base::PARTS_ALL, true ); |
745
|
|
|
$this->object->store( $basket, \Aimeos\MShop\Order\Manager\Base\Base::PARTS_ADDRESS ); |
746
|
|
|
|
747
|
|
|
$newBasketId = $basket->getId(); |
748
|
|
|
|
749
|
|
|
$basket = $this->object->load( $newBasketId, \Aimeos\MShop\Order\Manager\Base\Base::PARTS_ALL ); |
750
|
|
|
$this->object->deleteItem( $newBasketId ); |
751
|
|
|
|
752
|
|
|
$this->assertGreaterThan( 0, count( $basket->getAddresses() ) ); |
753
|
|
|
$this->assertEquals( [], $basket->getCoupons() ); |
754
|
|
|
$this->assertEquals( [], $basket->getProducts() ); |
755
|
|
|
$this->assertEquals( [], $basket->getServices() ); |
756
|
|
|
} |
757
|
|
|
|
758
|
|
|
|
759
|
|
|
public function testStoreProduct() |
760
|
|
|
{ |
761
|
|
|
$item = $this->getOrderItem(); |
762
|
|
|
|
763
|
|
|
$basket = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Manager\Base\Base::PARTS_ALL, true ); |
764
|
|
|
$this->object->store( $basket, \Aimeos\MShop\Order\Manager\Base\Base::PARTS_PRODUCT ); |
765
|
|
|
|
766
|
|
|
$newBasketId = $basket->getId(); |
767
|
|
|
|
768
|
|
|
$basket = $this->object->load( $newBasketId, \Aimeos\MShop\Order\Manager\Base\Base::PARTS_ALL ); |
769
|
|
|
$this->object->deleteItem( $newBasketId ); |
770
|
|
|
|
771
|
|
|
$this->assertGreaterThan( 0, count( $basket->getProducts() ) ); |
772
|
|
|
$this->assertEquals( [], $basket->getAddresses() ); |
773
|
|
|
$this->assertEquals( [], $basket->getCoupons() ); |
774
|
|
|
$this->assertEquals( [], $basket->getServices() ); |
775
|
|
|
} |
776
|
|
|
|
777
|
|
|
|
778
|
|
|
public function testStoreService() |
779
|
|
|
{ |
780
|
|
|
$item = $this->getOrderItem(); |
781
|
|
|
|
782
|
|
|
$basket = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Manager\Base\Base::PARTS_ALL, true ); |
783
|
|
|
$this->object->store( $basket, \Aimeos\MShop\Order\Manager\Base\Base::PARTS_SERVICE ); |
784
|
|
|
|
785
|
|
|
$newBasketId = $basket->getId(); |
786
|
|
|
|
787
|
|
|
$basket = $this->object->load( $newBasketId, \Aimeos\MShop\Order\Manager\Base\Base::PARTS_ALL ); |
788
|
|
|
$this->object->deleteItem( $newBasketId ); |
789
|
|
|
|
790
|
|
|
$this->assertGreaterThan( 0, count( $basket->getServices() ) ); |
791
|
|
|
$this->assertEquals( [], $basket->getAddresses() ); |
792
|
|
|
$this->assertEquals( [], $basket->getCoupons() ); |
793
|
|
|
$this->assertEquals( [], $basket->getProducts() ); |
794
|
|
|
} |
795
|
|
|
|
796
|
|
|
|
797
|
|
|
public function testLoadStoreCoupons() |
798
|
|
|
{ |
799
|
|
|
$search = $this->object->createSearch(); |
800
|
|
|
$search->setConditions( $search->compare( '==', 'order.base.price', '672.00' ) ); |
801
|
|
|
$results = $this->object->searchItems( $search ); |
802
|
|
|
|
803
|
|
|
if( ( $item = reset( $results ) ) === false ) { |
804
|
|
|
throw new \RuntimeException( 'No order found' ); |
805
|
|
|
} |
806
|
|
|
|
807
|
|
|
$basket = $this->object->load( $item->getId(), \Aimeos\MShop\Order\Manager\Base\Base::PARTS_ALL, true ); |
808
|
|
|
|
809
|
|
|
$this->assertEquals( '672.00', $basket->getPrice()->getValue() ); |
810
|
|
|
$this->assertEquals( '37.00', $basket->getPrice()->getCosts() ); |
811
|
|
|
$this->assertEquals( 0, count( $basket->getCoupons() ) ); |
812
|
|
|
|
813
|
|
|
$basket->addCoupon( 'CDEF' ); |
814
|
|
|
$basket->addCoupon( '5678', $basket->getProducts() ); |
815
|
|
|
$this->assertEquals( 2, count( $basket->getCoupons() ) ); |
816
|
|
|
|
817
|
|
|
$this->object->store( $basket ); |
818
|
|
|
$newBasket = $this->object->load( $basket->getId() ); |
819
|
|
|
$this->object->deleteItem( $newBasket->getId() ); |
820
|
|
|
|
821
|
|
|
$this->assertEquals( '1344.00', $newBasket->getPrice()->getValue() ); |
822
|
|
|
$this->assertEquals( '64.00', $newBasket->getPrice()->getCosts() ); |
823
|
|
|
$this->assertEquals( '5.00', $newBasket->getPrice()->getRebate() ); |
824
|
|
|
$this->assertEquals( 2, count( $newBasket->getCoupons() ) ); |
825
|
|
|
} |
826
|
|
|
|
827
|
|
|
|
828
|
|
|
/** |
829
|
|
|
* Returns an order base item |
830
|
|
|
* |
831
|
|
|
* @return \Aimeos\MShop\Order\Item\Base\Iface Order base item |
832
|
|
|
* @throws \Exception If no found |
833
|
|
|
*/ |
834
|
|
|
protected function getOrderItem() |
835
|
|
|
{ |
836
|
|
|
$search = $this->object->createSearch(); |
837
|
|
|
|
838
|
|
|
$expr = []; |
839
|
|
|
$expr[] = $search->compare( '==', 'order.base.rebate', 14.50 ); |
840
|
|
|
$expr[] = $search->compare( '==', 'order.base.sitecode', 'unittest' ); |
841
|
|
|
$expr[] = $search->compare( '==', 'order.base.price', 53.50 ); |
842
|
|
|
$expr[] = $search->compare( '==', 'order.base.editor', $this->editor ); |
843
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
844
|
|
|
$results = $this->object->searchItems( $search ); |
845
|
|
|
|
846
|
|
|
if( ( $item = reset( $results ) ) === false ) { |
847
|
|
|
throw new \RuntimeException( 'No order found' ); |
848
|
|
|
} |
849
|
|
|
|
850
|
|
|
return $item; |
851
|
|
|
} |
852
|
|
|
} |
853
|
|
|
|