Completed
Push — 1.9 ( d8eb28...5c3e2e )
by
unknown
61:52 queued 29s
created

extractCustomersValues()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 10
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
namespace OroCRM\Bundle\MagentoBundle\ImportExport\Converter;
4
5
use Oro\Bundle\IntegrationBundle\ImportExport\DataConverter\AbstractTreeDataConverter;
6
7
class GuestCustomerDataConverter extends AbstractTreeDataConverter
8
{
9
    /**
10
     * @var array
11
     */
12
    public static $conversionRules = [
13
        'customerEmail' => 'email',
14
        'customer_firstname' => 'firstName',
15
        'customer_lastname' => 'lastName',
16
        'createdAt' => 'createdAt',
17
        'updatedAt' => 'updatedAt',
18
        'store_id' => 'store:originId',
19
        'storeName' => 'createdIn',
20
    ];
21
22
    /**
23
     * @param array $orderData
24
     * @return array
25
     */
26
    public static function extractCustomersValues(array $orderData)
27
    {
28
        $customerData = array_intersect_key($orderData, self::$conversionRules);
29
30
        if (!empty($orderData['store']['originId'])) {
31
            $customerData['store_id'] = $orderData['store']['originId'];
32
        }
33
34
        return $customerData;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    protected function getHeaderConversionRules()
41
    {
42
        return self::$conversionRules;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function convertToImportFormat(array $importedRecord, $skipNullValues = true)
49
    {
50 View Code Duplication
        if ($this->context && $this->context->hasOption('channel')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
51
            $importedRecord['store:channel:id'] = $this->context->getOption('channel');
52
            $importedRecord['website:channel:id'] = $this->context->getOption('channel');
53
            $importedRecord['group:channel:id'] = $this->context->getOption('channel');
54
        }
55
56
        // extract view from 'website\nstore\view' string
57
        if (!empty($importedRecord['storeName'])) {
58
            $createdIn = explode("\n", $importedRecord['storeName']);
59
            $importedRecord['storeName'] = end($createdIn);
60
        }
61
62
        $importedRecord = parent::convertToImportFormat($importedRecord, $skipNullValues);
63
        $importedRecord = AttributesConverterHelper::addUnknownAttributes($importedRecord, $this->context);
64
65
        $importedRecord['confirmed'] = false;
66
        $importedRecord['guest'] = true;
67
68
        return $importedRecord;
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    protected function getBackendHeader()
75
    {
76
        return array_values($this->getHeaderConversionRules());
77
    }
78
}
79