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_PK_MAPPINGS |
48
|
|
|
); |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Construct a new instance. |
52
|
|
|
* |
53
|
|
|
* @param \TechDivision\Import\Configuration\ConfigurationInterface $configuration The configuration instance |
54
|
|
|
*/ |
55
|
|
|
public function __construct(ConfigurationInterface $configuration) |
56
|
|
|
{ |
57
|
|
|
$this->configuration = $configuration; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Returns the primary key member name for the actual Magento edition. |
62
|
|
|
* |
63
|
|
|
* @return string The primary key member name |
64
|
|
|
* @throws \Exception Is thrown if the edition is not supported/available |
65
|
|
|
*/ |
66
|
|
|
public function getSkuToPkMappingKey() |
67
|
|
|
{ |
68
|
|
|
|
69
|
|
|
// make sure the edition name is in upper cases |
70
|
|
|
$editionName = strtoupper($this->configuration->getMagentoEdition()); |
71
|
|
|
|
72
|
|
|
// return the primary key member name for the actual edition |
73
|
|
|
if (isset($this->editionSkuToPkMappings[$editionName])) { |
74
|
|
|
return $this->editionSkuToPkMappings[$editionName]; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
// throw an exception if the edition is NOT supported/available |
78
|
|
|
throw new \Exception(sprintf('Found not supported/available Magento edition name "%s"', $editionName)); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Returns the array with the SKU => PK mapping for the given serial and registry processor. |
83
|
|
|
* |
84
|
|
|
* @param \TechDivision\Import\Services\RegistryProcessorInterface $registryProcessor The registry processor with the actual import status |
85
|
|
|
* @param string $serial The serial of the actual import |
86
|
|
|
* |
87
|
|
|
* @return array The array with the SKU => PK mapping |
88
|
|
|
*/ |
89
|
|
|
public function getSkuToPkMapping(RegistryProcessorInterface $registryProcessor, $serial) |
90
|
|
|
{ |
91
|
|
|
|
92
|
|
|
// load the status for the import of the passed subject |
93
|
|
|
$status = $registryProcessor->getAttribute(RegistryKeys::STATUS); |
94
|
|
|
|
95
|
|
|
// query whether or not the SKU => PK mapping is available |
96
|
|
|
if (isset($status[$this->getSkuToPkMappingKey()])) { |
97
|
|
|
return $status[$this->getSkuToPkMappingKey()]; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
// return an empty array |
101
|
|
|
return array(); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Adds the passed SKU => PK mapping to the passed registry processor. |
106
|
|
|
* |
107
|
|
|
* @param \TechDivision\Import\Services\RegistryProcessorInterface $registryProcessor The registry processor with the actual import status |
108
|
|
|
* @param string $serial The serial of the actual import |
109
|
|
|
* @param array $skuToPkMapping The SKU => PK mapping to add |
110
|
|
|
* |
111
|
|
|
* @return void |
112
|
|
|
*/ |
113
|
|
|
public function setSkuToPkMapping(RegistryProcessorInterface $registryProcessor, $serial, array $skuToPkMapping) |
114
|
|
|
{ |
115
|
|
|
$registryProcessor->mergeAttributesRecursive(RegistryKeys::STATUS, array($this->getSkuToPkMappingKey() => $skuToPkMapping)); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Returns the array with the SKU => PK mapping for the given serial and registry processor. |
120
|
|
|
* |
121
|
|
|
* @param \TechDivision\Import\Services\RegistryProcessorInterface $registryProcessor The registry processor with the actual import status |
122
|
|
|
* @param string $serial The serial of the actual import |
123
|
|
|
* |
124
|
|
|
* @return array The array with the PK => SKU mapping |
125
|
|
|
* @see \TechDivision\Import\Product\Utils\SkuToPkMappingUtilInterface::getSkuToPkMapping() |
126
|
|
|
*/ |
127
|
|
|
public function getInvertedSkuToPkMapping(RegistryProcessorInterface $registryProcessor, $serial) |
128
|
|
|
{ |
129
|
|
|
return array_flip($this->getSkuToPkMapping($registryProcessor, $serial)); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|