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\FileUploadTrait; |
25
|
|
|
use TechDivision\Import\Subjects\ExportableSubjectInterface; |
26
|
|
|
use TechDivision\Import\Subjects\FileUploadSubjectInterface; |
27
|
|
|
use TechDivision\Import\Category\Utils\PageLayoutKeys; |
28
|
|
|
use TechDivision\Import\Category\Utils\DisplayModeKeys; |
29
|
|
|
use TechDivision\Import\Category\Utils\ConfigurationKeys; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The subject implementation that handles the business logic to persist products. |
33
|
|
|
* |
34
|
|
|
* @author Tim Wagner <[email protected]> |
35
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
36
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
37
|
|
|
* @link https://github.com/techdivision/import-category |
38
|
|
|
* @link http://www.techdivision.com |
39
|
|
|
*/ |
40
|
|
|
class BunchSubject extends AbstractCategorySubject implements ExportableSubjectInterface, FileUploadSubjectInterface |
41
|
|
|
{ |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* The trait that implements the export functionality. |
45
|
|
|
* |
46
|
|
|
* @var \TechDivision\Import\Subjects\ExportableTrait |
47
|
|
|
*/ |
48
|
|
|
use ExportableTrait; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* The trait that provides file upload functionality. |
52
|
|
|
* |
53
|
|
|
* @var \TechDivision\Import\Subjects\FileUploadTrait |
54
|
|
|
*/ |
55
|
|
|
use FileUploadTrait; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* The array with the available display mode keys. |
59
|
|
|
* |
60
|
|
|
* @var array |
61
|
|
|
*/ |
62
|
|
|
protected $availableDisplayModes = array( |
63
|
|
|
'Products only' => DisplayModeKeys::DISPLAY_MODE_PRODUCTS_ONLY, |
64
|
|
|
'Static block only' => DisplayModeKeys::DISPLAY_MODE_STATIC_BLOCK_ONLY, |
65
|
|
|
'Static block and products' => DisplayModeKeys::DISPLAY_MODE_BOTH |
66
|
|
|
); |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* The array with the available page layout keys. |
70
|
|
|
* |
71
|
|
|
* @var array |
72
|
|
|
*/ |
73
|
|
|
protected $availablePageLayouts = array( |
74
|
|
|
'1 column' => PageLayoutKeys::PAGE_LAYOUT_1_COLUMN, |
75
|
|
|
'2 columns with left bar' => PageLayoutKeys::PAGE_LAYOUT_2_COLUMNS_LEFT, |
76
|
|
|
'2 columns with right bar' => PageLayoutKeys::PAGE_LAYOUT_2_COLUMNS_RIGHT, |
77
|
|
|
'3 columns' => PageLayoutKeys::PAGE_LAYOUT_3_COLUMNS, |
78
|
|
|
'Empty' => PageLayoutKeys::PAGE_LAYOUT_EMPTY |
79
|
|
|
); |
80
|
|
|
/** |
81
|
|
|
* The default callback mappings for the Magento standard category attributes. |
82
|
|
|
* |
83
|
|
|
* @var array |
84
|
|
|
*/ |
85
|
|
|
protected $defaultCallbackMappings = array( |
86
|
|
|
'display_mode' => array('import_category.callback.display.mode'), |
87
|
|
|
'page_layout' => array('import_category.callback.page.layout'), |
88
|
|
|
); |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Intializes the previously loaded global data for exactly one bunch. |
92
|
|
|
* |
93
|
|
|
* @param string $serial The serial of the actual import |
94
|
|
|
* |
95
|
|
|
* @return void |
96
|
|
|
*/ |
97
|
|
|
public function setUp($serial) |
98
|
|
|
{ |
99
|
|
|
|
100
|
|
|
// initialize the flag whether to copy images or not |
101
|
|
|
if ($this->getConfiguration()->hasParam(ConfigurationKeys::COPY_IMAGES)) { |
102
|
|
|
$this->setCopyImages($this->getConfiguration()->getParam(ConfigurationKeys::COPY_IMAGES)); |
|
|
|
|
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
// initialize media directory => can be absolute or relative |
106
|
|
|
if ($this->getConfiguration()->hasParam(ConfigurationKeys::MEDIA_DIRECTORY)) { |
107
|
|
|
$this->setMediaDir( |
108
|
|
|
$this->resolvePath( |
109
|
|
|
$this->getConfiguration()->getParam(ConfigurationKeys::MEDIA_DIRECTORY) |
110
|
|
|
) |
111
|
|
|
); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
// initialize images directory => can be absolute or relative |
115
|
|
|
if ($this->getConfiguration()->hasParam(ConfigurationKeys::IMAGES_FILE_DIRECTORY)) { |
116
|
|
|
$this->setImagesFileDir( |
117
|
|
|
$this->resolvePath( |
118
|
|
|
$this->getConfiguration()->getParam(ConfigurationKeys::IMAGES_FILE_DIRECTORY) |
119
|
|
|
) |
120
|
|
|
); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
// prepare the callbacks |
124
|
|
|
parent::setUp($serial); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Return's the default callback mappings. |
129
|
|
|
* |
130
|
|
|
* @return array The default callback mappings |
131
|
|
|
*/ |
132
|
|
|
public function getDefaultCallbackMappings() |
133
|
|
|
{ |
134
|
|
|
return $this->defaultCallbackMappings; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Return's the display mode for the passed display mode string. |
139
|
|
|
* |
140
|
|
|
* @param string $displayMode The display mode string to return the key for |
141
|
|
|
* |
142
|
|
|
* @return integer The requested display mode |
143
|
|
|
* @throws \Exception Is thrown, if the requested display mode is not available |
144
|
|
|
*/ |
145
|
|
|
public function getDisplayModeByValue($displayMode) |
146
|
|
|
{ |
147
|
|
|
|
148
|
|
|
// query whether or not, the requested display mode is available |
149
|
|
|
if (isset($this->availableDisplayModes[$displayMode])) { |
150
|
|
|
return $this->availableDisplayModes[$displayMode]; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
// throw an exception, if not |
154
|
|
|
throw new \Exception(sprintf('Found invalid display mode %s', $displayMode)); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Return's the page layout for the passed page layout string. |
159
|
|
|
* |
160
|
|
|
* @param string $pageLayout The page layout string to return the key for |
161
|
|
|
* |
162
|
|
|
* @return integer The requested page layout |
163
|
|
|
* @throws \Exception Is thrown, if the requested page layout is not available |
164
|
|
|
*/ |
165
|
|
|
public function getPageLayoutByValue($pageLayout) |
166
|
|
|
{ |
167
|
|
|
|
168
|
|
|
// query whether or not, the requested display mode is available |
169
|
|
|
if (isset($this->availablePageLayouts[$pageLayout])) { |
170
|
|
|
return $this->availablePageLayouts[$pageLayout]; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
// throw an exception, if not |
174
|
|
|
throw new \Exception(printf('Found invalid page layout %s', $pageLayout)); |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: