1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Product\Utils\SkuToPkMappingUtil |
5
|
|
|
* |
6
|
|
|
* PHP version 7 |
7
|
|
|
* |
8
|
|
|
* @author MET <[email protected]> |
9
|
|
|
* @copyright 2024 TechDivision GmbH <[email protected]> |
10
|
|
|
* @license https://opensource.org/licenses/MIT |
11
|
|
|
* @link https://github.com/techdivision/import-product |
12
|
|
|
* @link http://www.techdivision.com |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace TechDivision\Import\Product\TierPrice\Utils; |
16
|
|
|
|
17
|
|
|
use TechDivision\Import\Configuration\ConfigurationInterface; |
18
|
|
|
use TechDivision\Import\Product\Utils\SkuToPkMappingUtilInterface; |
19
|
|
|
use TechDivision\Import\Utils\EditionNamesInterface; |
20
|
|
|
use TechDivision\Import\Services\RegistryProcessorInterface; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Utility class for edition based primary key handling. |
24
|
|
|
* |
25
|
|
|
* @author MET <[email protected]> |
26
|
|
|
* @copyright 2024 TechDivision GmbH <[email protected]> |
27
|
|
|
* @license https://opensource.org/licenses/MIT |
28
|
|
|
* @link https://github.com/techdivision/import-product |
29
|
|
|
* @link http://www.techdivision.com |
30
|
|
|
*/ |
31
|
|
|
class PrimarySkuToPkMappingUtil implements SkuToPkMappingUtilInterface |
32
|
|
|
{ |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* The configuration instance. |
36
|
|
|
* |
37
|
|
|
* @var \TechDivision\Import\Configuration\ConfigurationInterface |
38
|
|
|
*/ |
39
|
|
|
protected $configuration; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* The mapping for the edition for SKU => entity/row ID mapping. |
43
|
|
|
* |
44
|
|
|
* @var array |
45
|
|
|
*/ |
46
|
|
|
protected $editionSkuToPkMappings = array( |
47
|
|
|
EditionNamesInterface::EE => RegistryKeys::PRIMARY_SKU_TO_ROW_PK_MAPPINGS, |
48
|
|
|
EditionNamesInterface::CE => RegistryKeys::PRIMARY_SKU_TO_PK_MAPPINGS |
49
|
|
|
); |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Construct a new instance. |
53
|
|
|
* |
54
|
|
|
* @param \TechDivision\Import\Configuration\ConfigurationInterface $configuration The configuration instance |
55
|
|
|
*/ |
56
|
|
|
public function __construct(ConfigurationInterface $configuration) |
57
|
|
|
{ |
58
|
|
|
$this->configuration = $configuration; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Returns the primary key member name for the actual Magento edition. |
63
|
|
|
* |
64
|
|
|
* @return string The primary key member name |
65
|
|
|
* @throws \Exception Is thrown if the edition is not supported/available |
66
|
|
|
*/ |
67
|
|
|
public function getSkuToPkMappingKey() |
68
|
|
|
{ |
69
|
|
|
|
70
|
|
|
// make sure the edition name is in upper cases |
71
|
|
|
$editionName = strtoupper($this->configuration->getMagentoEdition()); |
72
|
|
|
|
73
|
|
|
// return the primary key member name for the actual edition |
74
|
|
|
if (isset($this->editionSkuToPkMappings[$editionName])) { |
75
|
|
|
return $this->editionSkuToPkMappings[$editionName]; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
// throw an exception if the edition is NOT supported/available |
79
|
|
|
throw new \Exception(sprintf('Found not supported/available Magento edition name "%s"', $editionName)); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Returns the array with the SKU => PK mapping for the given serial and registry processor. |
84
|
|
|
* |
85
|
|
|
* @param \TechDivision\Import\Services\RegistryProcessorInterface $registryProcessor The registry processor with the actual import status |
86
|
|
|
* @param string $serial The serial of the actual import |
87
|
|
|
* |
88
|
|
|
* @return array The array with the SKU => PK mapping |
89
|
|
|
*/ |
90
|
|
|
public function getSkuToPkMapping(RegistryProcessorInterface $registryProcessor, $serial) |
91
|
|
|
{ |
92
|
|
|
|
93
|
|
|
// load the status for the import of the passed subject |
94
|
|
|
$status = $registryProcessor->getAttribute(RegistryKeys::STATUS); |
95
|
|
|
|
96
|
|
|
// query whether or not the SKU => PK mapping is available |
97
|
|
|
if (isset($status[$this->getSkuToPkMappingKey()])) { |
98
|
|
|
return $status[$this->getSkuToPkMappingKey()]; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
// return an empty array |
102
|
|
|
return array(); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Adds the passed SKU => PK mapping to the passed registry processor. |
107
|
|
|
* |
108
|
|
|
* @param \TechDivision\Import\Services\RegistryProcessorInterface $registryProcessor The registry processor with the actual import status |
109
|
|
|
* @param string $serial The serial of the actual import |
110
|
|
|
* @param array $skuToPkMapping The SKU => PK mapping to add |
111
|
|
|
* |
112
|
|
|
* @return void |
113
|
|
|
*/ |
114
|
|
|
public function setSkuToPkMapping(RegistryProcessorInterface $registryProcessor, $serial, array $skuToPkMapping) |
115
|
|
|
{ |
116
|
|
|
$registryProcessor->mergeAttributesRecursive(RegistryKeys::STATUS, array($this->getSkuToPkMappingKey() => $skuToPkMapping)); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Returns the array with the SKU => PK mapping for the given serial and registry processor. |
121
|
|
|
* |
122
|
|
|
* @param \TechDivision\Import\Services\RegistryProcessorInterface $registryProcessor The registry processor with the actual import status |
123
|
|
|
* @param string $serial The serial of the actual import |
124
|
|
|
* |
125
|
|
|
* @return array The array with the PK => SKU mapping |
126
|
|
|
* @see \TechDivision\Import\Product\Utils\SkuToPkMappingUtilInterface::getSkuToPkMapping() |
127
|
|
|
*/ |
128
|
|
|
public function getInvertedSkuToPkMapping(RegistryProcessorInterface $registryProcessor, $serial) |
129
|
|
|
{ |
130
|
|
|
return array_flip($this->getSkuToPkMapping($registryProcessor, $serial)); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|