1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Oro\Bundle\MagentoBundle\Tests\Functional\Fixture; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
6
|
|
|
use Doctrine\Common\DataFixtures\AbstractFixture; |
7
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
8
|
|
|
|
9
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
10
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
11
|
|
|
|
12
|
|
|
use Oro\Bundle\AddressBundle\Entity\Address; |
13
|
|
|
use Oro\Component\Config\Common\ConfigObject; |
14
|
|
|
use Oro\Bundle\IntegrationBundle\Entity\Channel as Integration; |
15
|
|
|
use Oro\Bundle\OrganizationBundle\Entity\Organization; |
16
|
|
|
use Oro\Bundle\UserBundle\Entity\User; |
17
|
|
|
use Oro\Bundle\UserBundle\Model\Gender; |
18
|
|
|
use Oro\Bundle\AccountBundle\Entity\Account; |
19
|
|
|
use Oro\Bundle\ChannelBundle\Builder\BuilderFactory; |
20
|
|
|
use Oro\Bundle\ChannelBundle\Entity\Channel; |
21
|
|
|
use Oro\Bundle\MagentoBundle\Entity\Address as MagentoAddress; |
22
|
|
|
use Oro\Bundle\MagentoBundle\Entity\Cart; |
23
|
|
|
use Oro\Bundle\MagentoBundle\Entity\CartAddress; |
24
|
|
|
use Oro\Bundle\MagentoBundle\Entity\CartItem; |
25
|
|
|
use Oro\Bundle\MagentoBundle\Entity\CartStatus; |
26
|
|
|
use Oro\Bundle\MagentoBundle\Entity\Customer; |
27
|
|
|
use Oro\Bundle\MagentoBundle\Entity\CustomerGroup; |
28
|
|
|
use Oro\Bundle\MagentoBundle\Entity\MagentoSoapTransport; |
29
|
|
|
use Oro\Bundle\MagentoBundle\Entity\Order; |
30
|
|
|
use Oro\Bundle\MagentoBundle\Entity\OrderItem; |
31
|
|
|
use Oro\Bundle\MagentoBundle\Entity\Store; |
32
|
|
|
use Oro\Bundle\MagentoBundle\Entity\Website; |
33
|
|
|
use Oro\Bundle\MagentoBundle\Provider\Transport\SoapTransport; |
34
|
|
|
|
35
|
|
|
class LoadMagentoChannel extends AbstractFixture implements ContainerAwareInterface |
36
|
|
|
{ |
37
|
|
|
const CHANNEL_NAME = 'Magento channel'; |
38
|
|
|
const CHANNEL_TYPE = 'magento'; |
39
|
|
|
|
40
|
|
|
/** @var ObjectManager */ |
41
|
|
|
protected $em; |
42
|
|
|
|
43
|
|
|
/** @var integration */ |
44
|
|
|
protected $integration; |
45
|
|
|
|
46
|
|
|
/** @var MagentoSoapTransport */ |
47
|
|
|
protected $transport; |
48
|
|
|
|
49
|
|
|
/** @var array */ |
50
|
|
|
protected $countries; |
51
|
|
|
|
52
|
|
|
/** @var array */ |
53
|
|
|
protected $regions; |
54
|
|
|
|
55
|
|
|
/** @var Website */ |
56
|
|
|
protected $website; |
57
|
|
|
|
58
|
|
|
/** @var Store */ |
59
|
|
|
protected $store; |
60
|
|
|
|
61
|
|
|
/** @var CustomerGroup */ |
62
|
|
|
protected $customerGroup; |
63
|
|
|
|
64
|
|
|
/** @var Channel */ |
65
|
|
|
protected $channel; |
66
|
|
|
|
67
|
|
|
/** @var BuilderFactory */ |
68
|
|
|
protected $factory; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @var Organization |
72
|
|
|
*/ |
73
|
|
|
protected $organization; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* {@inheritDoc} |
77
|
|
|
*/ |
78
|
|
|
public function setContainer(ContainerInterface $container = null) |
79
|
|
|
{ |
80
|
|
|
$this->factory = $container->get('oro_channel.builder.factory'); |
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* {@inheritDoc} |
85
|
|
|
*/ |
86
|
|
|
public function load(ObjectManager $manager) |
87
|
|
|
{ |
88
|
|
|
$this->em = $manager; |
89
|
|
|
$this->countries = $this->loadStructure('OroAddressBundle:Country', 'getIso2Code'); |
90
|
|
|
$this->regions = $this->loadStructure('OroAddressBundle:Region', 'getCombinedCode'); |
91
|
|
|
$this->organization = $manager->getRepository('OroOrganizationBundle:Organization')->getFirst(); |
92
|
|
|
|
93
|
|
|
$this |
94
|
|
|
->createTransport() |
95
|
|
|
->createIntegration() |
96
|
|
|
->createChannel() |
97
|
|
|
->createWebSite() |
98
|
|
|
->createCustomerGroup() |
99
|
|
|
->createGuestCustomerGroup() |
100
|
|
|
->createStore(); |
101
|
|
|
|
102
|
|
|
$magentoAddress = $this->createMagentoAddress($this->regions['US-AZ'], $this->countries['US']); |
103
|
|
|
$account = $this->createAccount(); |
104
|
|
|
$this->setReference('account', $account); |
105
|
|
|
|
106
|
|
|
$customer = $this->createCustomer(1, $account, $magentoAddress); |
107
|
|
|
$cartAddress1 = $this->createCartAddress($this->regions['US-AZ'], $this->countries['US'], 1); |
108
|
|
|
$cartAddress2 = $this->createCartAddress($this->regions['US-AZ'], $this->countries['US'], 2); |
109
|
|
|
$cartItem = $this->createCartItem(); |
110
|
|
|
$status = $this->getStatus(); |
111
|
|
|
$items = new ArrayCollection(); |
112
|
|
|
$items->add($cartItem); |
113
|
|
|
|
114
|
|
|
$cart = $this->createCart($cartAddress1, $cartAddress2, $customer, $items, $status); |
115
|
|
|
$this->updateCartItem($cartItem, $cart); |
116
|
|
|
|
117
|
|
|
$order = $this->createOrder($cart, $customer); |
118
|
|
|
|
119
|
|
|
$this->setReference('customer', $customer); |
120
|
|
|
$this->setReference('integration', $this->integration); |
121
|
|
|
$this->setReference('cart', $cart); |
122
|
|
|
$this->setReference('order', $order); |
123
|
|
|
|
124
|
|
|
$baseOrderItem = $this->createBaseOrderItem($order); |
125
|
|
|
$order->setItems([$baseOrderItem]); |
126
|
|
|
$this->em->persist($order); |
127
|
|
|
|
128
|
|
|
$cartAddress3 = $this->createGuestCartAddress($this->regions['US-AZ'], $this->countries['US'], null); |
129
|
|
|
$cartAddress4 = $this->createGuestCartAddress($this->regions['US-AZ'], $this->countries['US'], null); |
130
|
|
|
|
131
|
|
|
$cartItem = $this->createCartItem(); |
132
|
|
|
$status = $this->getStatus(); |
133
|
|
|
$items = new ArrayCollection(); |
134
|
|
|
$items->add($cartItem); |
135
|
|
|
$guestCart = $this->createGuestCart($cartAddress3, $cartAddress4, $items, $status); |
136
|
|
|
$this->updateCartItem($cartItem, $guestCart); |
137
|
|
|
$guestOrder = $this->createGuestOrder($guestCart); |
138
|
|
|
|
139
|
|
|
$this->setReference('guestCart', $guestCart); |
140
|
|
|
$this->setReference('guestOrder', $guestOrder); |
141
|
|
|
|
142
|
|
|
$baseOrderItem = $this->createBaseOrderItem($guestOrder); |
143
|
|
|
$order->setItems([$baseOrderItem]); |
144
|
|
|
$this->em->persist($guestOrder); |
145
|
|
|
|
146
|
|
|
$this->em->flush(); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @param $billing |
151
|
|
|
* @param $shipping |
152
|
|
|
* @param Customer $customer |
153
|
|
|
* @param ArrayCollection $item |
154
|
|
|
* @param CartStatus $status |
155
|
|
|
* |
156
|
|
|
* @return Cart |
157
|
|
|
*/ |
158
|
|
View Code Duplication |
protected function createCart($billing, $shipping, Customer $customer, ArrayCollection $item, $status) |
|
|
|
|
159
|
|
|
{ |
160
|
|
|
$cart = new Cart(); |
161
|
|
|
$cart->setOriginId(100); |
162
|
|
|
$cart->setChannel($this->integration); |
163
|
|
|
$cart->setDataChannel($this->channel); |
164
|
|
|
$cart->setBillingAddress($billing); |
165
|
|
|
$cart->setShippingAddress($shipping); |
166
|
|
|
$cart->setCustomer($customer); |
167
|
|
|
$cart->setEmail('[email protected]'); |
168
|
|
|
$cart->setCreatedAt(new \DateTime('now')); |
169
|
|
|
$cart->setUpdatedAt(new \DateTime('now')); |
170
|
|
|
$cart->setCartItems($item); |
171
|
|
|
$cart->setStatus($status); |
172
|
|
|
$cart->setItemsQty(0); |
173
|
|
|
$cart->setItemsCount(1); |
174
|
|
|
$cart->setBaseCurrencyCode('code'); |
175
|
|
|
$cart->setStoreCurrencyCode('code'); |
176
|
|
|
$cart->setQuoteCurrencyCode('USD'); |
177
|
|
|
$cart->setStoreToBaseRate(12); |
178
|
|
|
$cart->setStoreToQuoteRate(12); |
179
|
|
|
$cart->setGrandTotal(2.54); |
180
|
|
|
$cart->setIsGuest(0); |
181
|
|
|
$cart->setStore($this->store); |
182
|
|
|
$cart->setOwner($this->getUser()); |
183
|
|
|
$cart->setOrganization($this->organization); |
184
|
|
|
|
185
|
|
|
$this->em->persist($cart); |
186
|
|
|
|
187
|
|
|
return $cart; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @param $billing |
192
|
|
|
* @param $shipping |
193
|
|
|
* @param ArrayCollection $item |
194
|
|
|
* @param CartStatus $status |
195
|
|
|
* |
196
|
|
|
* @return Cart |
197
|
|
|
*/ |
198
|
|
View Code Duplication |
protected function createGuestCart($billing, $shipping, ArrayCollection $item, $status) |
|
|
|
|
199
|
|
|
{ |
200
|
|
|
$cart = new Cart(); |
201
|
|
|
$cart->setOriginId(101); |
202
|
|
|
$cart->setChannel($this->integration); |
203
|
|
|
$cart->setDataChannel($this->channel); |
204
|
|
|
$cart->setBillingAddress($billing); |
205
|
|
|
$cart->setShippingAddress($shipping); |
206
|
|
|
$cart->setCustomer(null); |
207
|
|
|
$cart->setEmail('[email protected]'); |
208
|
|
|
$cart->setCreatedAt(new \DateTime('now')); |
209
|
|
|
$cart->setUpdatedAt(new \DateTime('now')); |
210
|
|
|
$cart->setCartItems($item); |
211
|
|
|
$cart->setStatus($status); |
212
|
|
|
$cart->setItemsQty(0); |
213
|
|
|
$cart->setItemsCount(1); |
214
|
|
|
$cart->setBaseCurrencyCode('code'); |
215
|
|
|
$cart->setStoreCurrencyCode('code'); |
216
|
|
|
$cart->setQuoteCurrencyCode('usd'); |
217
|
|
|
$cart->setStoreToBaseRate(12); |
218
|
|
|
$cart->setStoreToQuoteRate(12); |
219
|
|
|
$cart->setGrandTotal(2.54); |
220
|
|
|
$cart->setIsGuest(1); |
221
|
|
|
$cart->setStore($this->store); |
222
|
|
|
$cart->setOwner($this->getUser()); |
223
|
|
|
$cart->setOrganization($this->organization); |
224
|
|
|
|
225
|
|
|
$this->em->persist($cart); |
226
|
|
|
|
227
|
|
|
return $cart; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* @param $table |
232
|
|
|
* @param $method |
233
|
|
|
* |
234
|
|
|
* @return array |
235
|
|
|
*/ |
236
|
|
|
protected function loadStructure($table, $method) |
237
|
|
|
{ |
238
|
|
|
$result = []; |
239
|
|
|
$response = $this->em->getRepository($table)->findAll(); |
240
|
|
|
foreach ($response as $row) { |
241
|
|
|
$result[call_user_func([$row, $method])] = $row; |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
return $result; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* @return $this |
249
|
|
|
*/ |
250
|
|
|
protected function createIntegration() |
251
|
|
|
{ |
252
|
|
|
$integration = new Integration(); |
253
|
|
|
$integration->setName('Demo Web store'); |
254
|
|
|
$integration->setType('magento'); |
255
|
|
|
$integration->setConnectors(['customer', 'order', 'cart']); |
256
|
|
|
$integration->setTransport($this->transport); |
257
|
|
|
$integration->setOrganization($this->organization); |
258
|
|
|
|
259
|
|
|
$synchronizationSettings = ConfigObject::create(['isTwoWaySyncEnabled' => true]); |
260
|
|
|
$integration->setSynchronizationSettings($synchronizationSettings); |
261
|
|
|
|
262
|
|
|
$this->em->persist($integration); |
263
|
|
|
$this->integration = $integration; |
|
|
|
|
264
|
|
|
|
265
|
|
|
return $this; |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* @return $this |
270
|
|
|
*/ |
271
|
|
|
protected function createTransport() |
272
|
|
|
{ |
273
|
|
|
$transport = new MagentoSoapTransport; |
274
|
|
|
$transport->setAdminUrl('http://localhost/magento/admin'); |
275
|
|
|
$transport->setApiKey('key'); |
276
|
|
|
$transport->setApiUser('user'); |
277
|
|
|
$transport->setIsExtensionInstalled(true); |
278
|
|
|
$transport->setExtensionVersion(SoapTransport::REQUIRED_EXTENSION_VERSION); |
279
|
|
|
$transport->setMagentoVersion('1.9.1.0'); |
280
|
|
|
$transport->setIsWsiMode(false); |
281
|
|
|
$transport->setWebsiteId('1'); |
282
|
|
|
$transport->setWsdlUrl('http://localhost/magento/api/v2_soap?wsdl=1'); |
283
|
|
|
$transport->setWebsites([['id' => 1, 'label' => 'Website ID: 1, Stores: English, French, German']]); |
284
|
|
|
|
285
|
|
|
$this->em->persist($transport); |
286
|
|
|
$this->transport = $transport; |
287
|
|
|
|
288
|
|
|
return $this; |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* @param $region |
293
|
|
|
* @param $country |
294
|
|
|
* @param $originId |
295
|
|
|
* |
296
|
|
|
* @return CartAddress |
297
|
|
|
*/ |
298
|
|
View Code Duplication |
protected function createCartAddress($region, $country, $originId) |
|
|
|
|
299
|
|
|
{ |
300
|
|
|
$cartAddress = new CartAddress; |
301
|
|
|
$cartAddress->setRegion($region); |
302
|
|
|
$cartAddress->setCountry($country); |
303
|
|
|
$cartAddress->setCity('City'); |
304
|
|
|
$cartAddress->setStreet('street'); |
305
|
|
|
$cartAddress->setPostalCode(123456); |
306
|
|
|
$cartAddress->setFirstName('John'); |
307
|
|
|
$cartAddress->setLastName('Doe'); |
308
|
|
|
$cartAddress->setOriginId($originId); |
309
|
|
|
$cartAddress->setOrganization($this->organization); |
310
|
|
|
|
311
|
|
|
$this->em->persist($cartAddress); |
312
|
|
|
|
313
|
|
|
return $cartAddress; |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
/** |
317
|
|
|
* @param $region |
318
|
|
|
* @param $country |
319
|
|
|
* @param $originId |
320
|
|
|
* |
321
|
|
|
* @return CartAddress |
322
|
|
|
*/ |
323
|
|
View Code Duplication |
protected function createGuestCartAddress($region, $country, $originId) |
|
|
|
|
324
|
|
|
{ |
325
|
|
|
$cartAddress = new CartAddress; |
326
|
|
|
$cartAddress->setRegion($region); |
327
|
|
|
$cartAddress->setCountry($country); |
328
|
|
|
$cartAddress->setCity('City'); |
329
|
|
|
$cartAddress->setStreet('street'); |
330
|
|
|
$cartAddress->setPostalCode(123456); |
331
|
|
|
$cartAddress->setFirstName('Guest Jack'); |
332
|
|
|
$cartAddress->setLastName('Guest White'); |
333
|
|
|
$cartAddress->setOriginId($originId); |
334
|
|
|
$cartAddress->setOrganization($this->organization); |
335
|
|
|
|
336
|
|
|
$this->em->persist($cartAddress); |
337
|
|
|
|
338
|
|
|
return $cartAddress; |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
/** |
342
|
|
|
* @param $region |
343
|
|
|
* @param $country |
344
|
|
|
* |
345
|
|
|
* @return MagentoAddress |
346
|
|
|
*/ |
347
|
|
|
protected function createMagentoAddress($region, $country) |
348
|
|
|
{ |
349
|
|
|
$address = new MagentoAddress; |
350
|
|
|
$address->setRegion($region); |
351
|
|
|
$address->setCountry($country); |
352
|
|
|
$address->setCity('City'); |
353
|
|
|
$address->setStreet('street'); |
354
|
|
|
$address->setPostalCode(123456); |
355
|
|
|
$address->setFirstName('John'); |
356
|
|
|
$address->setLastName('Doe'); |
357
|
|
|
$address->setLabel('label'); |
358
|
|
|
$address->setPrimary(true); |
359
|
|
|
$address->setOrganization('oro'); |
360
|
|
|
$address->setOriginId(1); |
361
|
|
|
$address->setChannel($this->integration); |
362
|
|
|
$address->setOrganization($this->organization); |
363
|
|
|
|
364
|
|
|
$this->em->persist($address); |
365
|
|
|
|
366
|
|
|
return $address; |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
/** |
370
|
|
|
* @param $region |
371
|
|
|
* @param $country |
372
|
|
|
* |
373
|
|
|
* @return Address |
374
|
|
|
*/ |
375
|
|
View Code Duplication |
protected function createAddress($region, $country) |
|
|
|
|
376
|
|
|
{ |
377
|
|
|
$address = new Address; |
378
|
|
|
$address->setRegion($region); |
379
|
|
|
$address->setCountry($country); |
380
|
|
|
$address->setCity('City'); |
381
|
|
|
$address->setStreet('street'); |
382
|
|
|
$address->setPostalCode(123456); |
383
|
|
|
$address->setFirstName('John'); |
384
|
|
|
$address->setLastName('Doe'); |
385
|
|
|
$address->setOrganization($this->organization); |
386
|
|
|
|
387
|
|
|
$this->em->persist($address); |
388
|
|
|
|
389
|
|
|
return $address; |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
/** |
393
|
|
|
* @param $oid |
394
|
|
|
* @param Account $account |
395
|
|
|
* @param MagentoAddress $address |
396
|
|
|
* |
397
|
|
|
* @return Customer |
398
|
|
|
*/ |
399
|
|
|
protected function createCustomer($oid, Account $account, MagentoAddress $address) |
400
|
|
|
{ |
401
|
|
|
$customer = new Customer(); |
402
|
|
|
$customer->setChannel($this->integration); |
403
|
|
|
$customer->setDataChannel($this->channel); |
404
|
|
|
$customer->setFirstName('John'); |
405
|
|
|
$customer->setLastName('Doe'); |
406
|
|
|
$customer->setEmail('[email protected]'); |
407
|
|
|
$customer->setOriginId($oid); |
408
|
|
|
$customer->setIsActive(true); |
409
|
|
|
$customer->setWebsite($this->website); |
410
|
|
|
$customer->setStore($this->store); |
411
|
|
|
$customer->setAccount($account); |
412
|
|
|
$customer->setGender(Gender::MALE); |
413
|
|
|
$customer->setGroup($this->customerGroup); |
414
|
|
|
// TODO: DateTimeZones should be removed in BAP-8710. Tests should be passed for: |
415
|
|
|
// - Oro\Bundle\MagentoBundle\Tests\Functional\Controller\Api\Rest\CustomerControllerTest |
416
|
|
|
// - Oro\Bundle\MagentoBundle\Tests\Functional\Controller\Api\Rest\MagentoCustomerControllerTest |
417
|
|
|
$customer->setCreatedAt(new \DateTime('now', new \DateTimezone('UTC'))); |
418
|
|
|
$customer->setUpdatedAt(new \DateTime('now', new \DateTimezone('UTC'))); |
419
|
|
|
$customer->addAddress($address); |
420
|
|
|
$customer->setOwner($this->getUser()); |
421
|
|
|
$customer->setOrganization($this->organization); |
422
|
|
|
|
423
|
|
|
$this->em->persist($customer); |
424
|
|
|
|
425
|
|
|
return $customer; |
426
|
|
|
} |
427
|
|
|
|
428
|
|
|
/** |
429
|
|
|
* @return $this |
430
|
|
|
*/ |
431
|
|
View Code Duplication |
protected function createWebSite() |
|
|
|
|
432
|
|
|
{ |
433
|
|
|
$website = new Website(); |
434
|
|
|
$website->setName('web site'); |
435
|
|
|
$website->setOriginId(1); |
436
|
|
|
$website->setCode('web site code'); |
437
|
|
|
$website->setChannel($this->integration); |
438
|
|
|
|
439
|
|
|
$this->setReference('website', $website); |
440
|
|
|
$this->em->persist($website); |
441
|
|
|
$this->website = $website; |
442
|
|
|
|
443
|
|
|
return $this; |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
/** |
447
|
|
|
* @return $this |
448
|
|
|
*/ |
449
|
|
View Code Duplication |
protected function createStore() |
|
|
|
|
450
|
|
|
{ |
451
|
|
|
$store = new Store; |
452
|
|
|
$store->setName('demo store'); |
453
|
|
|
$store->setChannel($this->integration); |
454
|
|
|
$store->setCode(1); |
455
|
|
|
$store->setWebsite($this->website); |
456
|
|
|
$store->setOriginId(1); |
457
|
|
|
|
458
|
|
|
$this->em->persist($store); |
459
|
|
|
$this->store = $store; |
460
|
|
|
$this->setReference('store', $store); |
461
|
|
|
|
462
|
|
|
return $this; |
463
|
|
|
} |
464
|
|
|
|
465
|
|
|
/** |
466
|
|
|
* @return Account |
467
|
|
|
*/ |
468
|
|
View Code Duplication |
protected function createAccount() |
|
|
|
|
469
|
|
|
{ |
470
|
|
|
$account = new Account; |
471
|
|
|
$account->setName('acc'); |
472
|
|
|
$account->setOwner($this->getUser()); |
473
|
|
|
$account->setOrganization($this->organization); |
474
|
|
|
|
475
|
|
|
$this->em->persist($account); |
476
|
|
|
|
477
|
|
|
return $account; |
478
|
|
|
} |
479
|
|
|
|
480
|
|
|
/** |
481
|
|
|
* @return $this |
482
|
|
|
*/ |
483
|
|
|
protected function createCustomerGroup() |
484
|
|
|
{ |
485
|
|
|
$customerGroup = new CustomerGroup; |
486
|
|
|
$customerGroup->setName('group'); |
487
|
|
|
$customerGroup->setChannel($this->integration); |
488
|
|
|
$customerGroup->setOriginId(1); |
489
|
|
|
|
490
|
|
|
$this->em->persist($customerGroup); |
491
|
|
|
$this->setReference('customer_group', $customerGroup); |
492
|
|
|
$this->customerGroup = $customerGroup; |
493
|
|
|
|
494
|
|
|
return $this; |
495
|
|
|
} |
496
|
|
|
|
497
|
|
|
/** |
498
|
|
|
* @return $this |
499
|
|
|
*/ |
500
|
|
|
protected function createGuestCustomerGroup() |
501
|
|
|
{ |
502
|
|
|
$customerGroup = new CustomerGroup; |
503
|
|
|
$customerGroup->setName('NOT LOGGED IN'); |
504
|
|
|
$customerGroup->setChannel($this->integration); |
505
|
|
|
$customerGroup->setOriginId(0); |
506
|
|
|
|
507
|
|
|
$this->em->persist($customerGroup); |
508
|
|
|
return $this; |
509
|
|
|
} |
510
|
|
|
|
511
|
|
|
/** |
512
|
|
|
* @return CartItem |
513
|
|
|
*/ |
514
|
|
|
protected function createCartItem() |
515
|
|
|
{ |
516
|
|
|
$cartItem = new CartItem(); |
517
|
|
|
$cartItem->setName('item' . mt_rand(0, 99999)); |
518
|
|
|
$cartItem->setDescription('something'); |
519
|
|
|
$cartItem->setPrice(mt_rand(10, 99999)); |
520
|
|
|
$cartItem->setProductId(1); |
521
|
|
|
$cartItem->setFreeShipping('true'); |
522
|
|
|
$cartItem->setIsVirtual(1); |
523
|
|
|
$cartItem->setRowTotal(100); |
524
|
|
|
$cartItem->setTaxAmount(10); |
525
|
|
|
$cartItem->setProductType('type'); |
526
|
|
|
$cartItem->setSku('sku'); |
527
|
|
|
$cartItem->setQty(0); |
528
|
|
|
$cartItem->setDiscountAmount(0); |
529
|
|
|
$cartItem->setTaxPercent(0); |
530
|
|
|
$cartItem->setCreatedAt(new \DateTime('now')); |
531
|
|
|
$cartItem->setUpdatedAt(new \DateTime('now')); |
532
|
|
|
$cartItem->setOwner($this->organization); |
533
|
|
|
|
534
|
|
|
$this->em->persist($cartItem); |
535
|
|
|
|
536
|
|
|
return $cartItem; |
537
|
|
|
} |
538
|
|
|
|
539
|
|
|
/** |
540
|
|
|
* @return CartStatus |
541
|
|
|
*/ |
542
|
|
|
protected function getStatus() |
543
|
|
|
{ |
544
|
|
|
$status = $this->em->getRepository('OroMagentoBundle:CartStatus')->findOneBy(['name' => 'open']); |
545
|
|
|
|
546
|
|
|
return $status; |
547
|
|
|
} |
548
|
|
|
|
549
|
|
|
/** |
550
|
|
|
* @param CartItem $cartItem |
551
|
|
|
* @param Cart $cart |
552
|
|
|
* |
553
|
|
|
* @return $this |
554
|
|
|
*/ |
555
|
|
|
protected function updateCartItem(CartItem $cartItem, Cart $cart) |
556
|
|
|
{ |
557
|
|
|
$cartItem->setCart($cart); |
558
|
|
|
$this->em->persist($cartItem); |
559
|
|
|
|
560
|
|
|
return $this; |
561
|
|
|
} |
562
|
|
|
|
563
|
|
|
/** |
564
|
|
|
* @param Cart $cart |
565
|
|
|
* @param Customer $customer |
566
|
|
|
* |
567
|
|
|
* @return Order |
568
|
|
|
*/ |
569
|
|
View Code Duplication |
protected function createOrder(Cart $cart, Customer $customer) |
|
|
|
|
570
|
|
|
{ |
571
|
|
|
$order = new Order(); |
572
|
|
|
$order->setChannel($this->integration); |
573
|
|
|
$order->setDataChannel($this->channel); |
574
|
|
|
$order->setStatus('open'); |
575
|
|
|
$order->setIncrementId('100000307'); |
576
|
|
|
$order->setCreatedAt(new \DateTime('now')); |
577
|
|
|
$order->setUpdatedAt(new \DateTime('now')); |
578
|
|
|
$order->setCart($cart); |
579
|
|
|
$order->setStore($this->store); |
580
|
|
|
$order->setCustomer($customer); |
581
|
|
|
$order->setCustomerEmail('[email protected]'); |
582
|
|
|
$order->setDiscountAmount(4.40); |
583
|
|
|
$order->setTaxAmount(12.47); |
584
|
|
|
$order->setShippingAmount(5); |
585
|
|
|
$order->setTotalPaidAmount(17.85); |
586
|
|
|
$order->setTotalInvoicedAmount(11); |
587
|
|
|
$order->setTotalRefundedAmount(4); |
588
|
|
|
$order->setTotalCanceledAmount(0); |
589
|
|
|
$order->setShippingMethod('some unique shipping method'); |
590
|
|
|
$order->setRemoteIp('127.0.0.1'); |
591
|
|
|
$order->setGiftMessage('some very unique gift message'); |
592
|
|
|
$order->setOwner($this->getUser()); |
593
|
|
|
$order->setOrganization($this->organization); |
594
|
|
|
|
595
|
|
|
$this->em->persist($order); |
596
|
|
|
|
597
|
|
|
return $order; |
598
|
|
|
} |
599
|
|
|
|
600
|
|
|
/** |
601
|
|
|
* @param Cart $cart |
602
|
|
|
* |
603
|
|
|
* @return Order |
604
|
|
|
*/ |
605
|
|
View Code Duplication |
protected function createGuestOrder(Cart $cart) |
|
|
|
|
606
|
|
|
{ |
607
|
|
|
$order = new Order(); |
608
|
|
|
$order->setChannel($this->integration); |
609
|
|
|
$order->setDataChannel($this->channel); |
610
|
|
|
$order->setStatus('open'); |
611
|
|
|
$order->setIncrementId('100000308'); |
612
|
|
|
$order->setCreatedAt(new \DateTime('now')); |
613
|
|
|
$order->setUpdatedAt(new \DateTime('now')); |
614
|
|
|
$order->setCart($cart); |
615
|
|
|
$order->setStore($this->store); |
616
|
|
|
$order->setCustomer(null); |
|
|
|
|
617
|
|
|
$order->setIsGuest(1); |
|
|
|
|
618
|
|
|
$order->setCustomerEmail('[email protected]'); |
619
|
|
|
$order->setDiscountAmount(4.40); |
620
|
|
|
$order->setTaxAmount(12.47); |
621
|
|
|
$order->setShippingAmount(5); |
622
|
|
|
$order->setTotalPaidAmount(17.85); |
623
|
|
|
$order->setTotalInvoicedAmount(11); |
624
|
|
|
$order->setTotalRefundedAmount(4); |
625
|
|
|
$order->setTotalCanceledAmount(0); |
626
|
|
|
$order->setShippingMethod('some unique shipping method'); |
627
|
|
|
$order->setRemoteIp('127.0.0.1'); |
628
|
|
|
$order->setGiftMessage('some very unique gift message'); |
629
|
|
|
$order->setOwner($this->getUser()); |
630
|
|
|
$order->setOrganization($this->organization); |
631
|
|
|
|
632
|
|
|
$this->em->persist($order); |
633
|
|
|
|
634
|
|
|
return $order; |
635
|
|
|
} |
636
|
|
|
|
637
|
|
|
/** |
638
|
|
|
* @param Order $order |
639
|
|
|
* @return OrderItem |
640
|
|
|
*/ |
641
|
|
|
protected function createBaseOrderItem(Order $order) |
642
|
|
|
{ |
643
|
|
|
$orderItem = new OrderItem(); |
644
|
|
|
$orderItem->setId(mt_rand(0, 9999)); |
645
|
|
|
$orderItem->setName('some order item'); |
646
|
|
|
$orderItem->setSku('some sku'); |
647
|
|
|
$orderItem->setQty(1); |
648
|
|
|
$orderItem->setOrder($order); |
649
|
|
|
$orderItem->setCost(51.00); |
650
|
|
|
$orderItem->setPrice(75.00); |
651
|
|
|
$orderItem->setWeight(6.12); |
652
|
|
|
$orderItem->setTaxPercent(2); |
653
|
|
|
$orderItem->setTaxAmount(1.5); |
654
|
|
|
$orderItem->setDiscountPercent(4); |
655
|
|
|
$orderItem->setDiscountAmount(0); |
656
|
|
|
$orderItem->setRowTotal(234); |
657
|
|
|
$orderItem->setOwner($this->organization); |
658
|
|
|
|
659
|
|
|
$this->em->persist($orderItem); |
660
|
|
|
|
661
|
|
|
return $orderItem; |
662
|
|
|
} |
663
|
|
|
|
664
|
|
|
/** |
665
|
|
|
* @return User |
666
|
|
|
*/ |
667
|
|
|
protected function getUser() |
668
|
|
|
{ |
669
|
|
|
$user = $this->em->getRepository('OroUserBundle:User')->findOneBy(['username' => 'admin']); |
670
|
|
|
|
671
|
|
|
return $user; |
672
|
|
|
} |
673
|
|
|
|
674
|
|
|
/** |
675
|
|
|
* @return LoadMagentoChannel |
676
|
|
|
*/ |
677
|
|
|
protected function createChannel() |
678
|
|
|
{ |
679
|
|
|
$channel = $this |
680
|
|
|
->factory |
681
|
|
|
->createBuilder() |
682
|
|
|
->setName(self::CHANNEL_NAME) |
683
|
|
|
->setChannelType(self::CHANNEL_TYPE) |
684
|
|
|
->setStatus(Channel::STATUS_ACTIVE) |
685
|
|
|
->setDataSource($this->integration) |
686
|
|
|
->setOwner($this->organization) |
687
|
|
|
->setEntities() |
688
|
|
|
->getChannel(); |
689
|
|
|
|
690
|
|
|
$this->em->persist($channel); |
691
|
|
|
$this->em->flush(); |
692
|
|
|
|
693
|
|
|
$this->setReference('default_channel', $channel); |
694
|
|
|
|
695
|
|
|
$this->channel = $channel; |
696
|
|
|
|
697
|
|
|
return $this; |
698
|
|
|
} |
699
|
|
|
} |
700
|
|
|
|
If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe: