Completed
Push — 1.10 ( 5930b6...ffb454 )
by
unknown
07:44
created

LoadOrderDataWithFixedDate::load()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 35
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 35
rs 8.8571
c 1
b 0
f 0
cc 2
eloc 23
nc 2
nop 1
1
<?php
2
3
namespace OroCRM\Bundle\MagentoBundle\Tests\Functional\Fixture;
4
5
use Doctrine\Common\Persistence\ObjectManager;
6
7
use Oro\Bundle\ConfigBundle\Config\ConfigManager;
8
use Oro\Bundle\UserBundle\Migrations\Data\ORM\LoadAdminUserData;
9
10
use OroCRM\Bundle\MagentoBundle\Entity\Order;
11
12
class LoadOrderDataWithFixedDate extends LoadRFMOrderData
13
{
14
    /**
15
     * @var array Orders
16
     */
17
    protected $orderData = [
18
        [
19
            'status' => 'done',
20
            'incrementId' => '1',
21
            'customerEmail' => '[email protected]',
22
            'created' => '2017-07-01 00:00:00',
23
            'discountAmount' => 4.40,
24
            'taxAmount' => 12.47,
25
            'shippingAmount' => 5,
26
            'totalPaidAmount' => 17.85,
27
            'subtotalAmount' => 15.5,
28
            'totalInvoicedAmount' => 11,
29
            'totalRefundedAmount' => 4,
30
            'totalCanceledAmount' => 0,
31
            'shippingMethod' => 'some unique shipping method',
32
            'remoteIp' => 'unique ip',
33
            'giftMessage' => 'some very unique gift message',
34
        ],
35
        [
36
            'status' => 'done',
37
            'incrementId' => '2',
38
            'customerEmail' => '[email protected]',
39
            'created' => '2017-07-04 23:59:59',
40
            'discountAmount' => 4.40,
41
            'taxAmount' => 12.47,
42
            'shippingAmount' => 5,
43
            'totalPaidAmount' => 17.85,
44
            'subtotalAmount' => 15.5,
45
            'totalInvoicedAmount' => 11,
46
            'totalRefundedAmount' => 4,
47
            'totalCanceledAmount' => 0,
48
            'shippingMethod' => 'some unique shipping method',
49
            'remoteIp' => 'unique ip',
50
            'giftMessage' => 'some very unique gift message'
51
        ],
52
        [
53
            'status' => 'done',
54
            'incrementId' => '3',
55
            'customerEmail' => '[email protected]',
56
            'created' => '2017-07-05 00:00:00',
57
            'discountAmount' => 4.40,
58
            'taxAmount' => 12.47,
59
            'shippingAmount' => 5,
60
            'totalPaidAmount' => 17.85,
61
            'subtotalAmount' => 17.85,
62
            'totalInvoicedAmount' => 11,
63
            'totalRefundedAmount' => 4,
64
            'totalCanceledAmount' => 0,
65
            'shippingMethod' => 'some unique shipping method',
66
            'remoteIp' => 'unique ip',
67
            'giftMessage' => 'some very unique gift message'
68
        ],
69
        [
70
            'status' => 'done',
71
            'incrementId' => '4',
72
            'customerEmail' => '[email protected]',
73
            'created' => '2017-06-30 23:59:59',
74
            'discountAmount' => 4.40,
75
            'taxAmount' => 12.47,
76
            'shippingAmount' => 5,
77
            'totalPaidAmount' => 17.85,
78
            'subtotalAmount' => 17.85,
79
            'totalInvoicedAmount' => 11,
80
            'totalRefundedAmount' => 4,
81
            'totalCanceledAmount' => 0,
82
            'shippingMethod' => 'some unique shipping method',
83
            'remoteIp' => 'unique ip',
84
            'giftMessage' => 'some very unique gift message'
85
        ],
86
    ];
87
88
    /**
89
     * {@inheritdoc}
90
     */
91
    public function load(ObjectManager $manager)
92
    {
93
        /**
94
         * @var $configManager ConfigManager
95
         */
96
        $configManager = $this->container->get('oro_config.user');
97
98
        $userManager = $this->container->get('oro_user.manager');
99
        $admin = $userManager->findUserByEmail(LoadAdminUserData::DEFAULT_ADMIN_EMAIL);
100
        $organization = $manager->getRepository('OroOrganizationBundle:Organization')->getFirst();
101
102
        foreach ($this->orderData as $data) {
103
            $entity = new Order();
104
            $entity->setOwner($admin);
105
            $entity->setOrganization($organization);
106
107
            $created = new \DateTime(
108
                $data['created'],
109
                new \DateTimeZone($configManager->get('oro_locale.timezone'))
110
            );
111
            $entity->setCreatedAt($created);
112
            $entity->setUpdatedAt($created);
113
114
            $data['channel'] = $this->getReference('integration');
115
            $data['dataChannel'] = $this->getReference('default_channel');
116
            $data['cart'] = $this->getReference('cart');
117
            $data['store'] = $this->getReference('store');
118
            $data['customer'] = $this->getReference('customer');
119
120
            $this->setEntityPropertyValues($entity, $data, ['created']);
121
            $manager->persist($entity);
122
        }
123
        $manager->remove($this->getReference('order'));
124
        $manager->flush();
125
    }
126
}
127