1 | <?php |
||
36 | abstract class AbstractProductImportObserver extends AbstractObserver implements ProductImportObserverInterface |
||
37 | { |
||
38 | |||
39 | /** |
||
40 | * The actual row, that has to be processed. |
||
41 | * |
||
42 | * @var array |
||
43 | */ |
||
44 | protected $row = array(); |
||
45 | |||
46 | /** |
||
47 | * Set's the array containing header row. |
||
48 | * |
||
49 | * @param array $headers The array with the header row |
||
50 | * |
||
51 | * @return void |
||
52 | */ |
||
53 | public function setHeaders(array $headers) |
||
57 | |||
58 | /** |
||
59 | * Return's the array containing header row. |
||
60 | * |
||
61 | * @return array The array with the header row |
||
62 | */ |
||
63 | 7 | public function getHeaders() |
|
67 | |||
68 | /** |
||
69 | * Return's TRUE if the passed SKU is the actual one. |
||
70 | * |
||
71 | * @param string $sku The SKU to check |
||
72 | * |
||
73 | * @return boolean TRUE if the passed SKU is the actual one |
||
74 | */ |
||
75 | 7 | public function isLastSku($sku) |
|
79 | |||
80 | /** |
||
81 | * Return's the ID of the product that has been created recently. |
||
82 | * |
||
83 | * @return string The entity Id |
||
84 | */ |
||
85 | 3 | public function getLastEntityId() |
|
89 | |||
90 | /** |
||
91 | * Return's the source date format to use. |
||
92 | * |
||
93 | * @return string The source date format |
||
94 | */ |
||
95 | 1 | public function getSourceDateFormat() |
|
99 | |||
100 | /** |
||
101 | * Cast's the passed value based on the backend type information. |
||
102 | * |
||
103 | * @param string $backendType The backend type to cast to |
||
104 | * @param mixed $value The value to be casted |
||
105 | * |
||
106 | * @return mixed The casted value |
||
107 | */ |
||
108 | public function castValueByBackendType($backendType, $value) |
||
112 | |||
113 | /** |
||
114 | * Set's the store view code the create the product/attributes for. |
||
115 | * |
||
116 | * @param string $storeViewCode The store view code |
||
117 | * |
||
118 | * @return void |
||
119 | */ |
||
120 | 3 | public function setStoreViewCode($storeViewCode) |
|
124 | |||
125 | /** |
||
126 | * Return's the store view code the create the product/attributes for. |
||
127 | * |
||
128 | * @param string|null $default The default value to return, if the store view code has not been set |
||
129 | * |
||
130 | * @return string The store view code |
||
131 | */ |
||
132 | public function getStoreViewCode($default = null) |
||
136 | |||
137 | /** |
||
138 | * Prepare's the store view code in the subject. |
||
139 | * |
||
140 | * @return void |
||
141 | */ |
||
142 | 3 | public function prepareStoreViewCode() |
|
143 | { |
||
144 | |||
145 | // load the headers |
||
146 | 3 | $row = $this->getRow(); |
|
147 | 3 | $headers = $this->getHeaders(); |
|
148 | |||
149 | // initialize the store view code |
||
150 | 3 | $this->setStoreViewCode(null); |
|
151 | |||
152 | // initialize the store view code |
||
153 | 3 | if (isset($row[$headers[ColumnKeys::STORE_VIEW_CODE]])) { |
|
154 | $storeViewCode = $row[$headers[ColumnKeys::STORE_VIEW_CODE]]; |
||
155 | if (!empty($storeViewCode)) { |
||
156 | $this->setStoreViewCode($storeViewCode); |
||
157 | } |
||
158 | } |
||
159 | 3 | } |
|
160 | |||
161 | /** |
||
162 | * Set's the actual row, that has to be processed. |
||
163 | * |
||
164 | * @param array $row The row |
||
165 | */ |
||
|
|||
166 | 6 | public function setRow(array $row) |
|
170 | |||
171 | /** |
||
172 | * Return's the actual row, that has to be processed. |
||
173 | * |
||
174 | * @return array The row |
||
175 | */ |
||
176 | 6 | public function getRow() |
|
180 | |||
181 | /** |
||
182 | * Tries to format the passed value to a valid date with format 'Y-m-d H:i:s'. |
||
183 | * If the passed value is NOT a valid date, NULL will be returned. |
||
184 | * |
||
185 | * @param string|null $value The value to format |
||
186 | * |
||
187 | * @return string The formatted date |
||
188 | */ |
||
189 | 1 | public function formatDate($value) |
|
200 | |||
201 | /** |
||
202 | * Query whether or not the value with the passed key exists. |
||
203 | * |
||
204 | * @param string $key The key of the value to query |
||
205 | * |
||
206 | * @return boolean TRUE if the value is set, else FALSE |
||
207 | */ |
||
208 | 2 | public function hasValue($key) |
|
218 | |||
219 | /** |
||
220 | * Resolve's the value with the passed key from the actual row. If a callback will |
||
221 | * be passed, the callback will be invoked with the found value as parameter. If |
||
222 | * the value is NULL or empty, the default value will be returned. |
||
223 | * |
||
224 | * @param string $key The key of the value to return |
||
225 | * @param mixed|null $default The default value, that has to be returned, if the row's value is empty |
||
226 | * @param callable|null $callback The callback that has to be invoked on the value, e. g. to format it |
||
227 | * |
||
228 | * @return mixed|null The, almost formatted, value |
||
229 | */ |
||
230 | 6 | public function getValue($key, $default = null, callable $callback = null) |
|
231 | { |
||
232 | |||
233 | // load row and headers |
||
234 | 6 | $row = $this->getRow(); |
|
235 | 6 | $headers = $this->getHeaders(); |
|
236 | |||
237 | // initialize the value |
||
238 | 6 | $value = null; |
|
239 | |||
240 | // query wheter or not, the value with the requested key is available |
||
241 | 6 | if (isset($headers[$key]) && isset($row[$headers[$key]])) { |
|
242 | 6 | $value = $row[$headers[$key]]; |
|
243 | 6 | } |
|
244 | |||
245 | // query whether or not, a callback has been passed |
||
246 | 6 | if (is_callable($callback)) { |
|
247 | 1 | $value = call_user_func($callback, $value); |
|
248 | 1 | } |
|
249 | |||
250 | // query whether or not |
||
251 | 6 | if ($value == null && $default != null) { |
|
252 | $value = $default; |
||
253 | } |
||
254 | |||
255 | // return the value |
||
256 | 6 | return $value; |
|
257 | } |
||
258 | |||
259 | /** |
||
260 | * Initialize's and return's a new entity with the status 'create'. |
||
261 | * |
||
262 | * @param array $attr The attributes to merge into the new entity |
||
263 | * |
||
264 | * @return array The initialized entity |
||
265 | */ |
||
266 | 4 | public function initializeEntity(array $attr = array()) |
|
270 | |||
271 | /** |
||
272 | * Merge's and return's the entity with the passed attributes and set's the |
||
273 | * status to 'update'. |
||
274 | * |
||
275 | * @param array $entity The entity to merge the attributes into |
||
276 | * @param array $attr The attributes to be merged |
||
277 | * |
||
278 | * @return array The merged entity |
||
279 | */ |
||
280 | 2 | public function mergeEntity(array $entity, array $attr) |
|
284 | } |
||
285 |