|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Product\Grouped\Subjects\GroupedSubject |
|
5
|
|
|
* |
|
6
|
|
|
* NOTICE OF LICENSE |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
|
9
|
|
|
* that is available through the world-wide-web at this URL: |
|
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
|
11
|
|
|
* |
|
12
|
|
|
* PHP version 5 |
|
13
|
|
|
* |
|
14
|
|
|
* @author Tim Wagner <[email protected]> |
|
15
|
|
|
* @copyright 2019 TechDivision GmbH <[email protected]> |
|
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
17
|
|
|
* @link https://github.com/techdivision/import-product-link |
|
18
|
|
|
* @link http://www.techdivision.com |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Product\Grouped\Subjects; |
|
22
|
|
|
|
|
23
|
|
|
use TechDivision\Import\Utils\RegistryKeys; |
|
24
|
|
|
use TechDivision\Import\Product\Subjects\AbstractProductSubject; |
|
25
|
|
|
use TechDivision\Import\Product\Link\Exceptions\MapSkuToEntityIdException; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* A subject implementation the process to import grouped products. |
|
29
|
|
|
* |
|
30
|
|
|
* @author Tim Wagner <[email protected]> |
|
31
|
|
|
* @copyright 2019 TechDivision GmbH <[email protected]> |
|
32
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
33
|
|
|
* @link https://github.com/techdivision/import-product-link |
|
34
|
|
|
* @link http://www.techdivision.com |
|
35
|
|
|
*/ |
|
36
|
|
|
class GroupedSubject extends AbstractProductSubject |
|
37
|
|
|
{ |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* The mapping for the SKUs to the created entity IDs. |
|
41
|
|
|
* |
|
42
|
|
|
* @var array |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $skuEntityIdMapping = array(); |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Intializes the previously loaded global data for exactly one variants. |
|
48
|
|
|
* |
|
49
|
|
|
* @param string $serial The serial of the actual import |
|
50
|
|
|
* |
|
51
|
|
|
* @return void |
|
52
|
|
|
*/ |
|
53
|
|
|
public function setUp($serial) |
|
54
|
|
|
{ |
|
55
|
|
|
|
|
56
|
|
|
// invoke the parent method |
|
57
|
|
|
parent::setUp($serial); |
|
58
|
|
|
|
|
59
|
|
|
// load the entity manager and the registry processor |
|
60
|
|
|
$registryProcessor = $this->getRegistryProcessor(); |
|
61
|
|
|
|
|
62
|
|
|
// load the status of the actual import process |
|
63
|
|
|
$status = $registryProcessor->getAttribute($serial); |
|
64
|
|
|
|
|
65
|
|
|
// load the attribute set we've prepared intially |
|
66
|
|
|
$this->skuEntityIdMapping = $status[RegistryKeys::SKU_ENTITY_ID_MAPPING]; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Return the entity ID for the passed SKU. |
|
71
|
|
|
* |
|
72
|
|
|
* @param string $sku The SKU to return the entity ID for |
|
73
|
|
|
* |
|
74
|
|
|
* @return integer The mapped entity ID |
|
75
|
|
|
* @throws \TechDivision\Import\Product\Link\Exceptions\MapSkuToEntityIdException Is thrown if the SKU is not mapped yet |
|
76
|
|
|
*/ |
|
77
|
|
|
public function mapSkuToEntityId($sku) |
|
78
|
|
|
{ |
|
79
|
|
|
|
|
80
|
|
|
// query weather or not the SKU has been mapped |
|
81
|
|
|
if (isset($this->skuEntityIdMapping[$sku])) { |
|
82
|
|
|
return $this->skuEntityIdMapping[$sku]; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
// throw an exception if the SKU has not been mapped yet |
|
86
|
|
|
throw new MapSkuToEntityIdException( |
|
87
|
|
|
$this->appendExceptionSuffix( |
|
88
|
|
|
sprintf('Found not mapped entity ID for SKU %s', $sku) |
|
89
|
|
|
) |
|
90
|
|
|
); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|