1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Product\Link\Subjects\LinkSubject |
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 2016 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\Link\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 product links. |
29
|
|
|
* |
30
|
|
|
* @author Tim Wagner <[email protected]> |
31
|
|
|
* @copyright 2016 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 LinkSubject extends AbstractProductSubject |
37
|
|
|
{ |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* The temporary persisted last link ID. |
41
|
|
|
* |
42
|
|
|
* @var integer |
43
|
|
|
*/ |
44
|
|
|
protected $lastLinkId; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* The mapping for the SKUs to the created entity IDs. |
48
|
|
|
* |
49
|
|
|
* @var array |
50
|
|
|
*/ |
51
|
|
|
protected $skuEntityIdMapping = array(); |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Intializes the previously loaded global data for exactly one variants. |
55
|
|
|
* |
56
|
|
|
* @param string $serial The serial of the actual import |
57
|
|
|
* |
58
|
|
|
* @return void |
59
|
|
|
*/ |
60
|
|
|
public function setUp($serial) |
61
|
|
|
{ |
62
|
|
|
|
63
|
|
|
// invoke the parent method |
64
|
|
|
parent::setUp($serial); |
65
|
|
|
|
66
|
|
|
// load the entity manager and the registry processor |
67
|
|
|
$registryProcessor = $this->getRegistryProcessor(); |
68
|
|
|
|
69
|
|
|
// load the status of the actual import process |
70
|
|
|
$status = $registryProcessor->getAttribute($serial); |
71
|
|
|
|
72
|
|
|
// load the attribute set we've prepared intially |
73
|
|
|
$this->skuEntityIdMapping = $status[RegistryKeys::SKU_ENTITY_ID_MAPPING]; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Temporary persist the last link ID. |
78
|
|
|
* |
79
|
|
|
* @param integer $lastLinkId The last link ID |
80
|
|
|
* |
81
|
|
|
* @return void |
82
|
|
|
*/ |
83
|
|
|
public function setLastLinkId($lastLinkId) |
84
|
|
|
{ |
85
|
|
|
$this->lastLinkId = $lastLinkId; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Load the temporary persisted the last link ID. |
90
|
|
|
* |
91
|
|
|
* @return integer The last link ID |
92
|
|
|
*/ |
93
|
|
|
public function getLastLinkId() |
94
|
|
|
{ |
95
|
|
|
return $this->lastLinkId; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Return the entity ID for the passed SKU. |
100
|
|
|
* |
101
|
|
|
* @param string $sku The SKU to return the entity ID for |
102
|
|
|
* |
103
|
|
|
* @return integer The mapped entity ID |
104
|
|
|
* @throws \TechDivision\Import\Product\Link\Exceptions\MapSkuToEntityIdException Is thrown if the SKU is not mapped yet |
105
|
|
|
*/ |
106
|
|
|
public function mapSkuToEntityId($sku) |
107
|
|
|
{ |
108
|
|
|
|
109
|
|
|
// query weather or not the SKU has been mapped |
110
|
|
|
if (isset($this->skuEntityIdMapping[$sku])) { |
111
|
|
|
return $this->skuEntityIdMapping[$sku]; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
// throw an exception if the SKU has not been mapped yet |
115
|
|
|
throw new MapSkuToEntityIdException( |
116
|
|
|
$this->appendExceptionSuffix( |
117
|
|
|
sprintf('Found not mapped entity ID for SKU %s', $sku) |
118
|
|
|
) |
119
|
|
|
); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|