1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Category\Subjects\BunchSubject |
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-category |
18
|
|
|
* @link http://www.techdivision.com |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Category\Subjects; |
22
|
|
|
|
23
|
|
|
use TechDivision\Import\Subjects\ExportableTrait; |
24
|
|
|
use TechDivision\Import\Subjects\ExportableSubjectInterface; |
25
|
|
|
use TechDivision\Import\Category\Utils\PageLayoutKeys; |
26
|
|
|
use TechDivision\Import\Category\Utils\DisplayModeKeys; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* The subject implementation that handles the business logic to persist products. |
30
|
|
|
* |
31
|
|
|
* @author Tim Wagner <[email protected]> |
32
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
33
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
34
|
|
|
* @link https://github.com/techdivision/import-category |
35
|
|
|
* @link http://www.techdivision.com |
36
|
|
|
*/ |
37
|
|
|
class BunchSubject extends AbstractCategorySubject implements ExportableSubjectInterface |
38
|
|
|
{ |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* The trait that implements the export functionality. |
42
|
|
|
* |
43
|
|
|
* @var \TechDivision\Import\Subjects\ExportableTrait |
44
|
|
|
*/ |
45
|
|
|
use ExportableTrait; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* The array with the available display mode keys. |
49
|
|
|
* |
50
|
|
|
* @var array |
51
|
|
|
*/ |
52
|
|
|
protected $availableDisplayModes = array( |
53
|
|
|
'Products only' => DisplayModeKeys::DISPLAY_MODE_PRODUCTS_ONLY, |
54
|
|
|
'Static block only' => DisplayModeKeys::DISPLAY_MODE_STATIC_BLOCK_ONLY, |
55
|
|
|
'Static block and products' => DisplayModeKeys::DISPLAY_MODE_BOTH |
56
|
|
|
); |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* The array with the available page layout keys. |
60
|
|
|
* |
61
|
|
|
* @var array |
62
|
|
|
*/ |
63
|
|
|
protected $availablePageLayouts = array( |
64
|
|
|
'1 column' => PageLayoutKeys::PAGE_LAYOUT_1_COLUMN, |
65
|
|
|
'2 columns with left bar' => PageLayoutKeys::PAGE_LAYOUT_2_COLUMNS_LEFT, |
66
|
|
|
'2 columns with right bar' => PageLayoutKeys::PAGE_LAYOUT_2_COLUMNS_RIGHT, |
67
|
|
|
'3 columns' => PageLayoutKeys::PAGE_LAYOUT_3_COLUMNS, |
68
|
|
|
'Empty' => PageLayoutKeys::PAGE_LAYOUT_EMPTY |
69
|
|
|
); |
70
|
|
|
/** |
71
|
|
|
* The default callback mappings for the Magento standard category attributes. |
72
|
|
|
* |
73
|
|
|
* @var array |
74
|
|
|
*/ |
75
|
|
|
protected $defaultCallbackMappings = array( |
76
|
|
|
'display_mode' => array('TechDivision\\Import\\Category\\Callbacks\\DisplayModeCallback'), |
77
|
|
|
'page_layout' => array('TechDivision\\Import\\Category\\Callbacks\\PageLayoutCallback'), |
78
|
|
|
); |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Return's the default callback mappings. |
82
|
|
|
* |
83
|
|
|
* @return array The default callback mappings |
84
|
|
|
*/ |
85
|
|
|
public function getDefaultCallbackMappings() |
86
|
|
|
{ |
87
|
|
|
return $this->defaultCallbackMappings; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Return's the display mode for the passed display mode string. |
92
|
|
|
* |
93
|
|
|
* @param string $displayMode The display mode string to return the key for |
94
|
|
|
* |
95
|
|
|
* @return integer The requested display mode |
96
|
|
|
* @throws \Exception Is thrown, if the requested display mode is not available |
97
|
|
|
*/ |
98
|
|
View Code Duplication |
public function getDisplayModeByValue($displayMode) |
|
|
|
|
99
|
|
|
{ |
100
|
|
|
|
101
|
|
|
// query whether or not, the requested display mode is available |
102
|
|
|
if (isset($this->availableDisplayModes[$displayMode])) { |
103
|
|
|
return $this->availableDisplayModes[$displayMode]; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
// throw an exception, if not |
107
|
|
|
throw new \Exception( |
108
|
|
|
sprintf( |
109
|
|
|
'Found invalid display mode %s in file %s on line %d', |
110
|
|
|
$displayMode, |
111
|
|
|
$this->getFilename(), |
112
|
|
|
$this->getLineNumber() |
113
|
|
|
) |
114
|
|
|
); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Return's the page layout for the passed page layout string. |
119
|
|
|
* |
120
|
|
|
* @param string $pageLayout The page layout string to return the key for |
121
|
|
|
* |
122
|
|
|
* @return integer The requested page layout |
123
|
|
|
* @throws \Exception Is thrown, if the requested page layout is not available |
124
|
|
|
*/ |
125
|
|
View Code Duplication |
public function getPageLayoutByValue($pageLayout) |
|
|
|
|
126
|
|
|
{ |
127
|
|
|
|
128
|
|
|
// query whether or not, the requested display mode is available |
129
|
|
|
if (isset($this->availablePageLayouts[$pageLayout])) { |
130
|
|
|
return $this->availablePageLayouts[$pageLayout]; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
// throw an exception, if not |
134
|
|
|
throw new \Exception( |
135
|
|
|
sprintf( |
136
|
|
|
'Found invalid page layout %s in file %s on line %d', |
137
|
|
|
$pageLayout, |
138
|
|
|
$this->getFilename(), |
139
|
|
|
$this->getLineNumber() |
140
|
|
|
) |
141
|
|
|
); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Return's the category with the passed ID. |
146
|
|
|
* |
147
|
|
|
* @param string $id The ID of the category to return |
148
|
|
|
* |
149
|
|
|
* @return array The category |
150
|
|
|
*/ |
151
|
|
|
public function loadCategory($id) |
152
|
|
|
{ |
153
|
|
|
return $this->getCategoryProcessor()->loadCategory($id); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Load's and return's the datetime attribute with the passed entity/attribute/store ID. |
158
|
|
|
* |
159
|
|
|
* @param integer $entityId The entity ID of the attribute |
160
|
|
|
* @param integer $attributeId The attribute ID of the attribute |
161
|
|
|
* @param integer $storeId The store ID of the attribute |
162
|
|
|
* |
163
|
|
|
* @return array|null The datetime attribute |
164
|
|
|
*/ |
165
|
|
|
public function loadCategoryDatetimeAttribute($entityId, $attributeId, $storeId) |
166
|
|
|
{ |
167
|
|
|
return $this->getCategoryProcessor()->loadCategoryDatetimeAttribute($entityId, $attributeId, $storeId); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Load's and return's the decimal attribute with the passed entity/attribute/store ID. |
172
|
|
|
* |
173
|
|
|
* @param integer $entityId The entity ID of the attribute |
174
|
|
|
* @param integer $attributeId The attribute ID of the attribute |
175
|
|
|
* @param integer $storeId The store ID of the attribute |
176
|
|
|
* |
177
|
|
|
* @return array|null The decimal attribute |
178
|
|
|
*/ |
179
|
|
|
public function loadCategoryDecimalAttribute($entityId, $attributeId, $storeId) |
180
|
|
|
{ |
181
|
|
|
return $this->getCategoryProcessor()->loadCategoryDecimalAttribute($entityId, $attributeId, $storeId); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Load's and return's the integer attribute with the passed entity/attribute/store ID. |
186
|
|
|
* |
187
|
|
|
* @param integer $entityId The entity ID of the attribute |
188
|
|
|
* @param integer $attributeId The attribute ID of the attribute |
189
|
|
|
* @param integer $storeId The store ID of the attribute |
190
|
|
|
* |
191
|
|
|
* @return array|null The integer attribute |
192
|
|
|
*/ |
193
|
|
|
public function loadCategoryIntAttribute($entityId, $attributeId, $storeId) |
194
|
|
|
{ |
195
|
|
|
return $this->getCategoryProcessor()->loadCategoryIntAttribute($entityId, $attributeId, $storeId); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Load's and return's the text attribute with the passed entity/attribute/store ID. |
200
|
|
|
* |
201
|
|
|
* @param integer $entityId The entity ID of the attribute |
202
|
|
|
* @param integer $attributeId The attribute ID of the attribute |
203
|
|
|
* @param integer $storeId The store ID of the attribute |
204
|
|
|
* |
205
|
|
|
* @return array|null The text attribute |
206
|
|
|
*/ |
207
|
|
|
public function loadCategoryTextAttribute($entityId, $attributeId, $storeId) |
208
|
|
|
{ |
209
|
|
|
return $this->getCategoryProcessor()->loadCategoryTextAttribute($entityId, $attributeId, $storeId); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* Load's and return's the varchar attribute with the passed entity/attribute/store ID. |
214
|
|
|
* |
215
|
|
|
* @param integer $entityId The entity ID of the attribute |
216
|
|
|
* @param integer $attributeId The attribute ID of the attribute |
217
|
|
|
* @param integer $storeId The store ID of the attribute |
218
|
|
|
* |
219
|
|
|
* @return array|null The varchar attribute |
220
|
|
|
*/ |
221
|
|
|
public function loadCategoryVarcharAttribute($entityId, $attributeId, $storeId) |
222
|
|
|
{ |
223
|
|
|
return $this->getCategoryProcessor()->loadCategoryVarcharAttribute($entityId, $attributeId, $storeId); |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* Persist's the passed category data and return's the ID. |
228
|
|
|
* |
229
|
|
|
* @param array $category The category data to persist |
230
|
|
|
* |
231
|
|
|
* @return string The ID of the persisted entity |
232
|
|
|
*/ |
233
|
|
|
public function persistCategory($category) |
234
|
|
|
{ |
235
|
|
|
return $this->getCategoryProcessor()->persistCategory($category); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* Persist's the passed category varchar attribute. |
240
|
|
|
* |
241
|
|
|
* @param array $attribute The attribute to persist |
242
|
|
|
* |
243
|
|
|
* @return void |
244
|
|
|
*/ |
245
|
|
|
public function persistCategoryVarcharAttribute($attribute) |
246
|
|
|
{ |
247
|
|
|
$this->getCategoryProcessor()->persistCategoryVarcharAttribute($attribute); |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* Persist's the passed category integer attribute. |
252
|
|
|
* |
253
|
|
|
* @param array $attribute The attribute to persist |
254
|
|
|
* |
255
|
|
|
* @return void |
256
|
|
|
*/ |
257
|
|
|
public function persistCategoryIntAttribute($attribute) |
258
|
|
|
{ |
259
|
|
|
$this->getCategoryProcessor()->persistCategoryIntAttribute($attribute); |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* Persist's the passed category decimal attribute. |
264
|
|
|
* |
265
|
|
|
* @param array $attribute The attribute to persist |
266
|
|
|
* |
267
|
|
|
* @return void |
268
|
|
|
*/ |
269
|
|
|
public function persistCategoryDecimalAttribute($attribute) |
270
|
|
|
{ |
271
|
|
|
$this->getCategoryProcessor()->persistCategoryDecimalAttribute($attribute); |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* Persist's the passed category datetime attribute. |
276
|
|
|
* |
277
|
|
|
* @param array $attribute The attribute to persist |
278
|
|
|
* |
279
|
|
|
* @return void |
280
|
|
|
*/ |
281
|
|
|
public function persistCategoryDatetimeAttribute($attribute) |
282
|
|
|
{ |
283
|
|
|
$this->getCategoryProcessor()->persistCategoryDatetimeAttribute($attribute); |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* Persist's the passed category text attribute. |
288
|
|
|
* |
289
|
|
|
* @param array $attribute The attribute to persist |
290
|
|
|
* |
291
|
|
|
* @return void |
292
|
|
|
*/ |
293
|
|
|
public function persistCategoryTextAttribute($attribute) |
294
|
|
|
{ |
295
|
|
|
$this->getCategoryProcessor()->persistCategoryTextAttribute($attribute); |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* Persist's the URL rewrite with the passed data. |
300
|
|
|
* |
301
|
|
|
* @param array $row The URL rewrite to persist |
302
|
|
|
* |
303
|
|
|
* @return string The ID of the persisted entity |
304
|
|
|
*/ |
305
|
|
|
public function persistUrlRewrite($row) |
306
|
|
|
{ |
307
|
|
|
$this->getCategoryProcessor()->persistUrlRewrite($row); |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* Delete's the URL rewrite(s) with the passed attributes. |
312
|
|
|
* |
313
|
|
|
* @param array $row The attributes of the entity to delete |
314
|
|
|
* @param string|null $name The name of the prepared statement that has to be executed |
315
|
|
|
* |
316
|
|
|
* @return void |
317
|
|
|
*/ |
318
|
|
|
public function deleteUrlRewrite($row, $name = null) |
319
|
|
|
{ |
320
|
|
|
$this->getCategoryProcessor()->deleteUrlRewrite($row, $name); |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* Delete's the entity with the passed attributes. |
325
|
|
|
* |
326
|
|
|
* @param array $row The attributes of the entity to delete |
327
|
|
|
* @param string|null $name The name of the prepared statement that has to be executed |
328
|
|
|
* |
329
|
|
|
* @return void |
330
|
|
|
*/ |
331
|
|
|
public function deleteCategory($row, $name = null) |
332
|
|
|
{ |
333
|
|
|
$this->getCategoryProcessor()->deleteCategory($row, $name); |
334
|
|
|
} |
335
|
|
|
} |
336
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.