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')) { |
|
|
|
|
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
|
|
|
|
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.