|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Product\Observers\AbstractProductImportObserver |
|
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 |
|
18
|
|
|
* @link http://www.techdivision.com |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Product\Observers; |
|
22
|
|
|
|
|
23
|
|
|
use TechDivision\Import\Observers\AbstractObserver; |
|
24
|
|
|
use TechDivision\Import\Product\Utils\ColumnKeys; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* A SLSB that handles the process to import product bunches. |
|
28
|
|
|
* |
|
29
|
|
|
* @author Tim Wagner <[email protected]> |
|
30
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
|
31
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
32
|
|
|
* @link https://github.com/techdivision/import-product |
|
33
|
|
|
* @link http://www.techdivision.com |
|
34
|
|
|
*/ |
|
35
|
|
|
abstract class AbstractProductImportObserver extends AbstractObserver implements ProductImportObserverInterface |
|
36
|
|
|
{ |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Set's the array containing header row. |
|
40
|
|
|
* |
|
41
|
|
|
* @param array $headers The array with the header row |
|
42
|
|
|
* |
|
43
|
|
|
* @return void |
|
44
|
|
|
*/ |
|
45
|
|
|
public function setHeaders(array $headers) |
|
46
|
|
|
{ |
|
47
|
|
|
$this->getSubject()->setHeaders($headers); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Return's the array containing header row. |
|
52
|
|
|
* |
|
53
|
|
|
* @return array The array with the header row |
|
54
|
|
|
*/ |
|
55
|
6 |
|
public function getHeaders() |
|
56
|
|
|
{ |
|
57
|
6 |
|
return $this->getSubject()->getHeaders(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Return's TRUE if the passed SKU is the actual one. |
|
62
|
|
|
* |
|
63
|
|
|
* @param string $sku The SKU to check |
|
64
|
|
|
* |
|
65
|
|
|
* @return boolean TRUE if the passed SKU is the actual one |
|
66
|
|
|
*/ |
|
67
|
6 |
|
public function isLastSku($sku) |
|
68
|
|
|
{ |
|
69
|
6 |
|
return $this->getSubject()->getLastSku() === $sku; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Return's the ID of the product that has been created recently. |
|
74
|
|
|
* |
|
75
|
|
|
* @return string The entity Id |
|
76
|
|
|
*/ |
|
77
|
3 |
|
public function getLastEntityId() |
|
78
|
|
|
{ |
|
79
|
3 |
|
return $this->getSubject()->getLastEntityId(); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Return's the source date format to use. |
|
84
|
|
|
* |
|
85
|
|
|
* @return string The source date format |
|
86
|
|
|
*/ |
|
87
|
|
|
public function getSourceDateFormat() |
|
88
|
|
|
{ |
|
89
|
|
|
return $this->getSubject()->getSourceDateFormat(); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Cast's the passed value based on the backend type information. |
|
94
|
|
|
* |
|
95
|
|
|
* @param string $backendType The backend type to cast to |
|
96
|
|
|
* @param mixed $value The value to be casted |
|
97
|
|
|
* |
|
98
|
|
|
* @return mixed The casted value |
|
99
|
|
|
*/ |
|
100
|
|
|
public function castValueByBackendType($backendType, $value) |
|
101
|
|
|
{ |
|
102
|
|
|
return $this->getSubject()->castValueByBackendType($backendType, $value); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Set's the store view code the create the product/attributes for. |
|
107
|
|
|
* |
|
108
|
|
|
* @param string $storeViewCode The store view code |
|
109
|
|
|
* |
|
110
|
|
|
* @return void |
|
111
|
|
|
*/ |
|
112
|
|
|
public function setStoreViewCode($storeViewCode) |
|
113
|
|
|
{ |
|
114
|
|
|
$this->getSubject()->setStoreViewCode($storeViewCode); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Return's the store view code the create the product/attributes for. |
|
119
|
|
|
* |
|
120
|
|
|
* @param string|null $default The default value to return, if the store view code has not been set |
|
121
|
|
|
* |
|
122
|
|
|
* @return string The store view code |
|
123
|
|
|
*/ |
|
124
|
|
|
public function getStoreViewCode($default = null) |
|
125
|
|
|
{ |
|
126
|
|
|
return $this->getSubject()->getStoreViewCode($default); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* Prepare's the store view code in the subject. |
|
131
|
|
|
* |
|
132
|
|
|
* @param array $row The row with the data |
|
133
|
|
|
* |
|
134
|
|
|
* @return void |
|
135
|
|
|
*/ |
|
136
|
3 |
|
public function prepareStoreViewCode($row) |
|
137
|
|
|
{ |
|
138
|
|
|
|
|
139
|
|
|
// load the headers |
|
140
|
3 |
|
$headers = $this->getHeaders(); |
|
141
|
|
|
|
|
142
|
|
|
// initialize the store view code |
|
143
|
3 |
|
$this->setStoreViewCode(null); |
|
144
|
|
|
|
|
145
|
|
|
// initialize the store view code |
|
146
|
3 |
|
if (isset($row[$headers[ColumnKeys::STORE_VIEW_CODE]])) { |
|
147
|
|
|
$storeViewCode = $row[$headers[ColumnKeys::STORE_VIEW_CODE]]; |
|
148
|
|
|
if (!empty($storeViewCode)) { |
|
149
|
|
|
$this->setStoreViewCode($storeViewCode); |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
3 |
|
} |
|
153
|
|
|
} |
|
154
|
|
|
|