Completed
Push — master ( c2123c...66812a )
by
unknown
12:37
created

LoadMagentoChannel::createGuestCart()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 31
Code Lines 27

Duplication

Lines 31
Ratio 100 %

Importance

Changes 0
Metric Value
dl 31
loc 31
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 27
nc 1
nop 4
1
<?php
2
3
namespace OroCRM\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
19
use OroCRM\Bundle\AccountBundle\Entity\Account;
20
use OroCRM\Bundle\ChannelBundle\Builder\BuilderFactory;
21
use OroCRM\Bundle\ChannelBundle\Entity\Channel;
22
use OroCRM\Bundle\MagentoBundle\Entity\Address as MagentoAddress;
23
use OroCRM\Bundle\MagentoBundle\Entity\Cart;
24
use OroCRM\Bundle\MagentoBundle\Entity\CartAddress;
25
use OroCRM\Bundle\MagentoBundle\Entity\CartItem;
26
use OroCRM\Bundle\MagentoBundle\Entity\CartStatus;
27
use OroCRM\Bundle\MagentoBundle\Entity\Customer;
28
use OroCRM\Bundle\MagentoBundle\Entity\CustomerGroup;
29
use OroCRM\Bundle\MagentoBundle\Entity\MagentoSoapTransport;
30
use OroCRM\Bundle\MagentoBundle\Entity\Order;
31
use OroCRM\Bundle\MagentoBundle\Entity\OrderItem;
32
use OroCRM\Bundle\MagentoBundle\Entity\Store;
33
use OroCRM\Bundle\MagentoBundle\Entity\Website;
34
use OroCRM\Bundle\MagentoBundle\Provider\Transport\SoapTransport;
35
36
class LoadMagentoChannel extends AbstractFixture implements ContainerAwareInterface
37
{
38
    const CHANNEL_NAME = 'Magento channel';
39
    const CHANNEL_TYPE = 'magento';
40
41
    /** @var ObjectManager */
42
    protected $em;
43
44
    /** @var integration */
45
    protected $integration;
46
47
    /** @var MagentoSoapTransport */
48
    protected $transport;
49
50
    /** @var array */
51
    protected $countries;
52
53
    /** @var array */
54
    protected $regions;
55
56
    /** @var Website */
57
    protected $website;
58
59
    /** @var Store */
60
    protected $store;
61
62
    /** @var CustomerGroup */
63
    protected $customerGroup;
64
65
    /** @var Channel */
66
    protected $channel;
67
68
    /** @var BuilderFactory */
69
    protected $factory;
70
71
    /**
72
     * @var Organization
73
     */
74
    protected $organization;
75
76
    /**
77
     * {@inheritDoc}
78
     */
79
    public function setContainer(ContainerInterface $container = null)
80
    {
81
        $this->factory = $container->get('orocrm_channel.builder.factory');
0 ignored issues
show
Bug introduced by
It seems like $container is not always an object, but can also be of type null. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
82
    }
83
84
    /**
85
     * {@inheritDoc}
86
     */
87
    public function load(ObjectManager $manager)
88
    {
89
        $this->em        = $manager;
90
        $this->countries = $this->loadStructure('OroAddressBundle:Country', 'getIso2Code');
91
        $this->regions   = $this->loadStructure('OroAddressBundle:Region', 'getCombinedCode');
92
        $this->organization = $manager->getRepository('OroOrganizationBundle:Organization')->getFirst();
93
94
        $this
95
            ->createTransport()
96
            ->createIntegration()
97
            ->createChannel()
98
            ->createWebSite()
99
            ->createCustomerGroup()
100
            ->createGuestCustomerGroup()
101
            ->createStore();
102
103
        $magentoAddress = $this->createMagentoAddress($this->regions['US-AZ'], $this->countries['US']);
104
        $account        = $this->createAccount();
105
        $this->setReference('account', $account);
106
107
        $customer       = $this->createCustomer(1, $account, $magentoAddress);
108
        $cartAddress1   = $this->createCartAddress($this->regions['US-AZ'], $this->countries['US'], 1);
109
        $cartAddress2   = $this->createCartAddress($this->regions['US-AZ'], $this->countries['US'], 2);
110
        $cartItem       = $this->createCartItem();
111
        $status         = $this->getStatus();
112
        $items          = new ArrayCollection();
113
        $items->add($cartItem);
114
115
        $cart = $this->createCart($cartAddress1, $cartAddress2, $customer, $items, $status);
116
        $this->updateCartItem($cartItem, $cart);
117
118
        $order = $this->createOrder($cart, $customer);
119
120
        $this->setReference('customer', $customer);
121
        $this->setReference('integration', $this->integration);
122
        $this->setReference('cart', $cart);
123
        $this->setReference('order', $order);
124
125
        $baseOrderItem = $this->createBaseOrderItem($order);
126
        $order->setItems([$baseOrderItem]);
127
        $this->em->persist($order);
128
129
        $cartAddress3 = $this->createGuestCartAddress($this->regions['US-AZ'], $this->countries['US'], null);
130
        $cartAddress4 = $this->createGuestCartAddress($this->regions['US-AZ'], $this->countries['US'], null);
131
132
        $cartItem = $this->createCartItem();
133
        $status   = $this->getStatus();
134
        $items    = new ArrayCollection();
135
        $items->add($cartItem);
136
        $guestCart = $this->createGuestCart($cartAddress3, $cartAddress4, $items, $status);
137
        $this->updateCartItem($cartItem, $guestCart);
138
        $guestOrder = $this->createGuestOrder($guestCart);
139
140
        $this->setReference('guestCart', $guestCart);
141
        $this->setReference('guestOrder', $guestOrder);
142
143
        $baseOrderItem = $this->createBaseOrderItem($guestOrder);
144
        $order->setItems([$baseOrderItem]);
145
        $this->em->persist($guestOrder);
146
147
        $this->em->flush();
148
    }
149
150
    /**
151
     * @param                 $billing
152
     * @param                 $shipping
153
     * @param Customer        $customer
154
     * @param ArrayCollection $item
155
     * @param CartStatus      $status
156
     *
157
     * @return Cart
158
     */
159 View Code Duplication
    protected function createCart($billing, $shipping, Customer $customer, ArrayCollection $item, $status)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
160
    {
161
        $cart = new Cart();
162
        $cart->setOriginId(100);
163
        $cart->setChannel($this->integration);
164
        $cart->setDataChannel($this->channel);
165
        $cart->setBillingAddress($billing);
166
        $cart->setShippingAddress($shipping);
167
        $cart->setCustomer($customer);
168
        $cart->setEmail('[email protected]');
169
        $cart->setCreatedAt(new \DateTime('now'));
170
        $cart->setUpdatedAt(new \DateTime('now'));
171
        $cart->setCartItems($item);
172
        $cart->setStatus($status);
173
        $cart->setItemsQty(0);
174
        $cart->setItemsCount(1);
175
        $cart->setBaseCurrencyCode('code');
176
        $cart->setStoreCurrencyCode('code');
177
        $cart->setQuoteCurrencyCode('usd');
178
        $cart->setStoreToBaseRate(12);
179
        $cart->setStoreToQuoteRate(12);
180
        $cart->setGrandTotal(2.54);
181
        $cart->setIsGuest(0);
182
        $cart->setStore($this->store);
183
        $cart->setOwner($this->getUser());
184
        $cart->setOrganization($this->organization);
185
186
        $this->em->persist($cart);
187
188
        return $cart;
189
    }
190
191
    /**
192
     * @param                 $billing
193
     * @param                 $shipping
194
     * @param ArrayCollection $item
195
     * @param CartStatus      $status
196
     *
197
     * @return Cart
198
     */
199 View Code Duplication
    protected function createGuestCart($billing, $shipping, ArrayCollection $item, $status)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
200
    {
201
        $cart = new Cart();
202
        $cart->setOriginId(101);
203
        $cart->setChannel($this->integration);
204
        $cart->setDataChannel($this->channel);
205
        $cart->setBillingAddress($billing);
206
        $cart->setShippingAddress($shipping);
207
        $cart->setCustomer(null);
208
        $cart->setEmail('[email protected]');
209
        $cart->setCreatedAt(new \DateTime('now'));
210
        $cart->setUpdatedAt(new \DateTime('now'));
211
        $cart->setCartItems($item);
212
        $cart->setStatus($status);
213
        $cart->setItemsQty(0);
214
        $cart->setItemsCount(1);
215
        $cart->setBaseCurrencyCode('code');
216
        $cart->setStoreCurrencyCode('code');
217
        $cart->setQuoteCurrencyCode('usd');
218
        $cart->setStoreToBaseRate(12);
219
        $cart->setStoreToQuoteRate(12);
220
        $cart->setGrandTotal(2.54);
221
        $cart->setIsGuest(1);
222
        $cart->setStore($this->store);
223
        $cart->setOwner($this->getUser());
224
        $cart->setOrganization($this->organization);
225
226
        $this->em->persist($cart);
227
228
        return $cart;
229
    }
230
231
    /**
232
     * @param $table
233
     * @param $method
234
     *
235
     * @return array
236
     */
237
    protected function loadStructure($table, $method)
238
    {
239
        $result   = [];
240
        $response = $this->em->getRepository($table)->findAll();
241
        foreach ($response as $row) {
242
            $result[call_user_func([$row, $method])] = $row;
243
        }
244
245
        return $result;
246
    }
247
248
    /**
249
     * @return $this
250
     */
251
    protected function createIntegration()
252
    {
253
        $integration = new Integration();
254
        $integration->setName('Demo Web store');
255
        $integration->setType('magento');
256
        $integration->setConnectors(['customer', 'order', 'cart']);
257
        $integration->setTransport($this->transport);
258
        $integration->setOrganization($this->organization);
259
260
        $synchronizationSettings = ConfigObject::create(['isTwoWaySyncEnabled' => true]);
261
        $integration->setSynchronizationSettings($synchronizationSettings);
262
263
        $this->em->persist($integration);
264
        $this->integration = $integration;
0 ignored issues
show
Documentation Bug introduced by
It seems like $integration of type object<Oro\Bundle\Integr...nBundle\Entity\Channel> is incompatible with the declared type object<OroCRM\Bundle\Mag...al\Fixture\integration> of property $integration.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
265
266
        return $this;
267
    }
268
269
    /**
270
     * @return $this
271
     */
272
    protected function createTransport()
273
    {
274
        $transport = new MagentoSoapTransport;
275
        $transport->setAdminUrl('http://localhost/magento/admin');
276
        $transport->setApiKey('key');
277
        $transport->setApiUser('user');
278
        $transport->setIsExtensionInstalled(true);
279
        $transport->setExtensionVersion(SoapTransport::REQUIRED_EXTENSION_VERSION);
280
        $transport->setMagentoVersion('1.9.1.0');
281
        $transport->setIsWsiMode(false);
282
        $transport->setWebsiteId('1');
283
        $transport->setWsdlUrl('http://localhost/magento/api/v2_soap?wsdl=1');
284
        $transport->setWebsites([['id' => 1, 'label' => 'Website ID: 1, Stores: English, French, German']]);
285
286
        $this->em->persist($transport);
287
        $this->transport = $transport;
288
289
        return $this;
290
    }
291
292
    /**
293
     * @param $region
294
     * @param $country
295
     * @param $originId
296
     *
297
     * @return CartAddress
298
     */
299 View Code Duplication
    protected function createCartAddress($region, $country, $originId)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
300
    {
301
        $cartAddress = new CartAddress;
302
        $cartAddress->setRegion($region);
303
        $cartAddress->setCountry($country);
304
        $cartAddress->setCity('City');
305
        $cartAddress->setStreet('street');
306
        $cartAddress->setPostalCode(123456);
307
        $cartAddress->setFirstName('John');
308
        $cartAddress->setLastName('Doe');
309
        $cartAddress->setOriginId($originId);
310
        $cartAddress->setOrganization($this->organization);
311
312
        $this->em->persist($cartAddress);
313
314
        return $cartAddress;
315
    }
316
317
    /**
318
     * @param $region
319
     * @param $country
320
     * @param $originId
321
     *
322
     * @return CartAddress
323
     */
324 View Code Duplication
    protected function createGuestCartAddress($region, $country, $originId)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
325
    {
326
        $cartAddress = new CartAddress;
327
        $cartAddress->setRegion($region);
328
        $cartAddress->setCountry($country);
329
        $cartAddress->setCity('City');
330
        $cartAddress->setStreet('street');
331
        $cartAddress->setPostalCode(123456);
332
        $cartAddress->setFirstName('Guest Jack');
333
        $cartAddress->setLastName('Guest White');
334
        $cartAddress->setOriginId($originId);
335
        $cartAddress->setOrganization($this->organization);
336
337
        $this->em->persist($cartAddress);
338
339
        return $cartAddress;
340
    }
341
342
    /**
343
     * @param $region
344
     * @param $country
345
     *
346
     * @return MagentoAddress
347
     */
348
    protected function createMagentoAddress($region, $country)
349
    {
350
        $address = new MagentoAddress;
351
        $address->setRegion($region);
352
        $address->setCountry($country);
353
        $address->setCity('City');
354
        $address->setStreet('street');
355
        $address->setPostalCode(123456);
356
        $address->setFirstName('John');
357
        $address->setLastName('Doe');
358
        $address->setLabel('label');
359
        $address->setPrimary(true);
360
        $address->setOrganization('oro');
361
        $address->setOriginId(1);
362
        $address->setChannel($this->integration);
363
        $address->setOrganization($this->organization);
364
365
        $this->em->persist($address);
366
367
        return $address;
368
    }
369
370
    /**
371
     * @param $region
372
     * @param $country
373
     *
374
     * @return Address
375
     */
376 View Code Duplication
    protected function createAddress($region, $country)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
377
    {
378
        $address = new Address;
379
        $address->setRegion($region);
380
        $address->setCountry($country);
381
        $address->setCity('City');
382
        $address->setStreet('street');
383
        $address->setPostalCode(123456);
384
        $address->setFirstName('John');
385
        $address->setLastName('Doe');
386
        $address->setOrganization($this->organization);
387
388
        $this->em->persist($address);
389
390
        return $address;
391
    }
392
393
    /**
394
     * @param                $oid
395
     * @param Account        $account
396
     * @param MagentoAddress $address
397
     *
398
     * @return Customer
399
     */
400
    protected function createCustomer($oid, Account $account, MagentoAddress $address)
401
    {
402
        $customer = new Customer();
403
        $customer->setChannel($this->integration);
404
        $customer->setDataChannel($this->channel);
405
        $customer->setFirstName('John');
406
        $customer->setLastName('Doe');
407
        $customer->setEmail('[email protected]');
408
        $customer->setOriginId($oid);
409
        $customer->setIsActive(true);
410
        $customer->setWebsite($this->website);
411
        $customer->setStore($this->store);
412
        $customer->setAccount($account);
413
        $customer->setGender(Gender::MALE);
414
        $customer->setGroup($this->customerGroup);
415
        // TODO: DateTimeZones should be removed in BAP-8710. Tests should be passed for:
416
        //  - OroCRM\Bundle\MagentoBundle\Tests\Functional\Controller\Api\Rest\CustomerControllerTest
417
        //  - OroCRM\Bundle\MagentoBundle\Tests\Functional\Controller\Api\Rest\MagentoCustomerControllerTest
418
        $customer->setCreatedAt(new \DateTime('now', new \DateTimezone('UTC')));
419
        $customer->setUpdatedAt(new \DateTime('now', new \DateTimezone('UTC')));
420
        $customer->addAddress($address);
421
        $customer->setOwner($this->getUser());
422
        $customer->setOrganization($this->organization);
423
424
        $this->em->persist($customer);
425
426
        return $customer;
427
    }
428
429
    /**
430
     * @return $this
431
     */
432 View Code Duplication
    protected function createWebSite()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
433
    {
434
        $website = new Website();
435
        $website->setName('web site');
436
        $website->setOriginId(1);
437
        $website->setCode('web site code');
438
        $website->setChannel($this->integration);
439
440
        $this->setReference('website', $website);
441
        $this->em->persist($website);
442
        $this->website = $website;
443
444
        return $this;
445
    }
446
447
    /**
448
     * @return $this
449
     */
450 View Code Duplication
    protected function createStore()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
451
    {
452
        $store = new Store;
453
        $store->setName('demo store');
454
        $store->setChannel($this->integration);
455
        $store->setCode(1);
456
        $store->setWebsite($this->website);
457
        $store->setOriginId(1);
458
459
        $this->em->persist($store);
460
        $this->store = $store;
461
        $this->setReference('store', $store);
462
463
        return $this;
464
    }
465
466
    /**
467
     * @return Account
468
     */
469 View Code Duplication
    protected function createAccount()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
470
    {
471
        $account = new Account;
472
        $account->setName('acc');
473
        $account->setOwner($this->getUser());
474
        $account->setOrganization($this->organization);
475
476
        $this->em->persist($account);
477
478
        return $account;
479
    }
480
481
    /**
482
     * @return $this
483
     */
484
    protected function createCustomerGroup()
485
    {
486
        $customerGroup = new CustomerGroup;
487
        $customerGroup->setName('group');
488
        $customerGroup->setChannel($this->integration);
489
        $customerGroup->setOriginId(1);
490
491
        $this->em->persist($customerGroup);
492
        $this->setReference('customer_group', $customerGroup);
493
        $this->customerGroup = $customerGroup;
494
495
        return $this;
496
    }
497
498
    /**
499
     * @return $this
500
     */
501
    protected function createGuestCustomerGroup()
502
    {
503
        $customerGroup = new CustomerGroup;
504
        $customerGroup->setName('NOT LOGGED IN');
505
        $customerGroup->setChannel($this->integration);
506
        $customerGroup->setOriginId(0);
507
508
        $this->em->persist($customerGroup);
509
        return $this;
510
    }
511
512
    /**
513
     * @return CartItem
514
     */
515
    protected function createCartItem()
516
    {
517
        $cartItem = new CartItem();
518
        $cartItem->setName('item' . mt_rand(0, 99999));
519
        $cartItem->setDescription('something');
520
        $cartItem->setPrice(mt_rand(10, 99999));
521
        $cartItem->setProductId(1);
522
        $cartItem->setFreeShipping('true');
523
        $cartItem->setIsVirtual(1);
524
        $cartItem->setRowTotal(100);
525
        $cartItem->setTaxAmount(10);
526
        $cartItem->setProductType('type');
527
        $cartItem->setSku('sku');
528
        $cartItem->setQty(0);
529
        $cartItem->setDiscountAmount(0);
530
        $cartItem->setTaxPercent(0);
531
        $cartItem->setCreatedAt(new \DateTime('now'));
532
        $cartItem->setUpdatedAt(new \DateTime('now'));
533
        $cartItem->setOwner($this->organization);
534
535
        $this->em->persist($cartItem);
536
537
        return $cartItem;
538
    }
539
540
    /**
541
     * @return CartStatus
542
     */
543
    protected function getStatus()
544
    {
545
        $status = $this->em->getRepository('OroCRMMagentoBundle:CartStatus')->findOneBy(['name' => 'open']);
546
547
        return $status;
548
    }
549
550
    /**
551
     * @param CartItem $cartItem
552
     * @param Cart     $cart
553
     *
554
     * @return $this
555
     */
556
    protected function updateCartItem(CartItem $cartItem, Cart $cart)
557
    {
558
        $cartItem->setCart($cart);
559
        $this->em->persist($cartItem);
560
561
        return $this;
562
    }
563
564
    /**
565
     * @param Cart     $cart
566
     * @param Customer $customer
567
     *
568
     * @return Order
569
     */
570 View Code Duplication
    protected function createOrder(Cart $cart, Customer $customer)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
571
    {
572
        $order = new Order();
573
        $order->setChannel($this->integration);
574
        $order->setDataChannel($this->channel);
575
        $order->setStatus('open');
576
        $order->setIncrementId('100000307');
577
        $order->setCreatedAt(new \DateTime('now'));
578
        $order->setUpdatedAt(new \DateTime('now'));
579
        $order->setCart($cart);
580
        $order->setStore($this->store);
581
        $order->setCustomer($customer);
582
        $order->setCustomerEmail('[email protected]');
583
        $order->setDiscountAmount(4.40);
584
        $order->setTaxAmount(12.47);
585
        $order->setShippingAmount(5);
586
        $order->setTotalPaidAmount(17.85);
587
        $order->setTotalInvoicedAmount(11);
588
        $order->setTotalRefundedAmount(4);
589
        $order->setTotalCanceledAmount(0);
590
        $order->setShippingMethod('some unique shipping method');
591
        $order->setRemoteIp('127.0.0.1');
592
        $order->setGiftMessage('some very unique gift message');
593
        $order->setOwner($this->getUser());
594
        $order->setOrganization($this->organization);
595
596
        $this->em->persist($order);
597
598
        return $order;
599
    }
600
601
    /**
602
     * @param Cart $cart
603
     *
604
     * @return Order
605
     */
606 View Code Duplication
    protected function createGuestOrder(Cart $cart)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
607
    {
608
        $order = new Order();
609
        $order->setChannel($this->integration);
610
        $order->setDataChannel($this->channel);
611
        $order->setStatus('open');
612
        $order->setIncrementId('100000308');
613
        $order->setCreatedAt(new \DateTime('now'));
614
        $order->setUpdatedAt(new \DateTime('now'));
615
        $order->setCart($cart);
616
        $order->setStore($this->store);
617
        $order->setCustomer(null);
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Oro\Bundle\Busine...ndle\Entity\BasePerson>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
618
        $order->setIsGuest(1);
0 ignored issues
show
Documentation introduced by
1 is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
619
        $order->setCustomerEmail('[email protected]');
620
        $order->setDiscountAmount(4.40);
621
        $order->setTaxAmount(12.47);
622
        $order->setShippingAmount(5);
623
        $order->setTotalPaidAmount(17.85);
624
        $order->setTotalInvoicedAmount(11);
625
        $order->setTotalRefundedAmount(4);
626
        $order->setTotalCanceledAmount(0);
627
        $order->setShippingMethod('some unique shipping method');
628
        $order->setRemoteIp('127.0.0.1');
629
        $order->setGiftMessage('some very unique gift message');
630
        $order->setOwner($this->getUser());
631
        $order->setOrganization($this->organization);
632
633
        $this->em->persist($order);
634
635
        return $order;
636
    }
637
638
    /**
639
     * @param Order $order
640
     * @return OrderItem
641
     */
642
    protected function createBaseOrderItem(Order $order)
643
    {
644
        $orderItem = new OrderItem();
645
        $orderItem->setId(mt_rand(0, 9999));
646
        $orderItem->setName('some order item');
647
        $orderItem->setSku('some sku');
648
        $orderItem->setQty(1);
649
        $orderItem->setOrder($order);
650
        $orderItem->setCost(51.00);
651
        $orderItem->setPrice(75.00);
652
        $orderItem->setWeight(6.12);
653
        $orderItem->setTaxPercent(2);
654
        $orderItem->setTaxAmount(1.5);
655
        $orderItem->setDiscountPercent(4);
656
        $orderItem->setDiscountAmount(0);
657
        $orderItem->setRowTotal(234);
658
        $orderItem->setOwner($this->organization);
659
660
        $this->em->persist($orderItem);
661
662
        return $orderItem;
663
    }
664
665
    /**
666
     * @return User
667
     */
668
    protected function getUser()
669
    {
670
        $user = $this->em->getRepository('OroUserBundle:User')->findOneBy(['username' => 'admin']);
671
672
        return $user;
673
    }
674
675
    /**
676
     * @return LoadMagentoChannel
677
     */
678
    protected function createChannel()
679
    {
680
        $channel = $this
681
            ->factory
682
            ->createBuilder()
683
            ->setName(self::CHANNEL_NAME)
684
            ->setChannelType(self::CHANNEL_TYPE)
685
            ->setStatus(Channel::STATUS_ACTIVE)
686
            ->setDataSource($this->integration)
687
            ->setOwner($this->organization)
688
            ->setEntities()
689
            ->getChannel();
690
691
        $this->em->persist($channel);
692
        $this->em->flush();
693
694
        $this->setReference('default_channel', $channel);
695
696
        $this->channel = $channel;
697
698
        return $this;
699
    }
700
}
701