Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like wpshop_attributes often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use wpshop_attributes, and based on these observations, apply Extract Interface, too.
1 | <?php if ( !defined( 'ABSPATH' ) ) exit; |
||
23 | class wpshop_attributes{ |
||
24 | /* Define the database table used in the current class */ |
||
25 | const dbTable = WPSHOP_DBT_ATTRIBUTE; |
||
26 | /* Define the url listing slug used in the current class */ |
||
27 | const urlSlugListing = WPSHOP_URL_SLUG_ATTRIBUTE_LISTING; |
||
28 | /* Define the url edition slug used in the current class */ |
||
29 | const urlSlugEdition = WPSHOP_URL_SLUG_ATTRIBUTE_LISTING; |
||
30 | /* Define the current entity code */ |
||
31 | const currentPageCode = 'attributes'; |
||
32 | /* Define the page title */ |
||
33 | const pageContentTitle = 'Attributes'; |
||
34 | /* Define the page title when adding an attribute */ |
||
35 | const pageAddingTitle = 'Add an attribute'; |
||
36 | /* Define the page title when editing an attribute */ |
||
37 | const pageEditingTitle = 'Attribute "%s" edit'; |
||
38 | /* Define the page title when editing an attribute */ |
||
39 | const pageTitle = 'Attributes list'; |
||
40 | |||
41 | /* Define the path to page main icon */ |
||
42 | public $pageIcon = ''; |
||
43 | /* Define the message to output after an action */ |
||
44 | public $pageMessage = ''; |
||
45 | |||
46 | public static $select_option_info_cache = array(); |
||
47 | |||
48 | /** |
||
49 | * Get the url listing slug of the current class |
||
50 | * |
||
51 | * @return string The table of the class |
||
52 | */ |
||
53 | function setMessage($message){ |
||
|
|||
54 | $this->pageMessage = $message; |
||
55 | } |
||
56 | /** |
||
57 | * Get the url listing slug of the current class |
||
58 | * |
||
59 | * @return string The table of the class |
||
60 | */ |
||
61 | function getListingSlug(){ |
||
62 | return self::urlSlugListing; |
||
63 | } |
||
64 | /** |
||
65 | * Get the url edition slug of the current class |
||
66 | * |
||
67 | * @return string The table of the class |
||
68 | */ |
||
69 | function getEditionSlug(){ |
||
70 | return self::urlSlugEdition; |
||
71 | } |
||
72 | /** |
||
73 | * Get the database table of the current class |
||
74 | * |
||
75 | * @return string The table of the class |
||
76 | */ |
||
77 | public static function getDbTable(){ |
||
78 | return self::dbTable; |
||
79 | } |
||
80 | /** |
||
81 | * Define the title of the page |
||
82 | * |
||
83 | * @return string $title The title of the page looking at the environnement |
||
84 | */ |
||
85 | function pageTitle(){ |
||
86 | $action = isset($_REQUEST['action']) ? sanitize_text_field($_REQUEST['action']) : ''; |
||
87 | $objectInEdition = isset($_REQUEST['id']) ? sanitize_key($_REQUEST['id']) : ''; |
||
88 | $page = !empty( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
||
89 | |||
90 | $title = __(self::pageTitle, 'wpshop' ); |
||
91 | if($action != ''){ |
||
92 | View Code Duplication | if(($action == 'edit') || ($action == 'delete')){ |
|
93 | $editedItem = self::getElement($objectInEdition); |
||
94 | $title = sprintf(__(self::pageEditingTitle, 'wpshop'), str_replace("\\", "", $editedItem->frontend_label)); |
||
95 | } |
||
96 | elseif($action == 'add') |
||
97 | $title = __(self::pageAddingTitle, 'wpshop'); |
||
98 | } |
||
99 | elseif((self::getEditionSlug() != self::getListingSlug()) && ($page == self::getEditionSlug())) |
||
100 | $title = __(self::pageAddingTitle, 'wpshop'); |
||
101 | |||
102 | return $title; |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * Define the different message and action after an action is send through the element interface |
||
107 | */ |
||
108 | function elementAction(){ |
||
109 | global $wpdb, $initialEavData; |
||
110 | |||
111 | $pageMessage = $actionResult = ''; |
||
112 | $attribute_undeletable = unserialize(WPSHOP_ATTRIBUTE_UNDELETABLE); |
||
113 | |||
114 | /* Start definition of output message when action is doing on another page */ |
||
115 | /************ CHANGE THE FIELD NAME TO TAKE TO DISPLAY *************/ |
||
116 | /****************************************************************************/ |
||
117 | $action = isset($_REQUEST['action']) ? sanitize_text_field($_REQUEST['action']) : 'add'; |
||
118 | $saveditem = isset($_REQUEST['saveditem']) ? sanitize_text_field($_REQUEST['saveditem']) : ''; |
||
119 | $set_section = !empty($_REQUEST[self::getDbTable()]['set_section']) ? sanitize_text_field($_REQUEST[self::getDbTable()]['set_section']) : ''; |
||
120 | //@TODO $_REQUEST |
||
121 | $id = !empty($_REQUEST['id']) ? (int) $_REQUEST['id'] : null; |
||
122 | if(!empty($action) && ($action=='activate') ){ |
||
123 | if( isset($id) ) { |
||
124 | $query = $wpdb->update(self::getDbTable(), array('status'=>'moderated'), array('id'=>$id)); |
||
125 | wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . self::getListingSlug() . "&action=edit&id=" . $id)); |
||
126 | } |
||
127 | } |
||
128 | View Code Duplication | if(($action != '') && ($action == 'saveok') && ($saveditem > 0)){ |
|
129 | $editedElement = self::getElement($saveditem); |
||
130 | $pageMessage = '<img src="' . WPSHOP_SUCCES_ICON . '" alt="action success" class="wpshopPageMessage_Icon" />' . sprintf(__('%s succesfully saved', 'wpshop'), '<span class="bold" >' . $editedElement->code . '</span>'); |
||
131 | } |
||
132 | elseif(($action != '') && ($action == 'deleteok') && ($saveditem > 0)){ |
||
133 | $editedElement = self::getElement($saveditem, "'deleted'"); |
||
134 | $pageMessage = '<img src="' . WPSHOP_SUCCES_ICON . '" alt="action success" class="wpshopPageMessage_Icon" />' . sprintf(__('%s succesfully deleted', 'wpshop'), '<span class="bold" >' . $editedElement->code . '</span>'); |
||
135 | } |
||
136 | |||
137 | $attribute_parameter = !empty( $_REQUEST[self::getDbTable()] ) ? (array)$_REQUEST[self::getDbTable()] : array(); |
||
138 | if ( !empty($set_section) ) unset($attribute_parameter['set_section']); |
||
139 | |||
140 | $wpshop_attribute_combo_values_list_order_def = !empty($attribute_parameter['wpshop_attribute_combo_values_list_order_def']) ? $attribute_parameter['wpshop_attribute_combo_values_list_order_def'] : array(); |
||
141 | // @TODO $_REQUEST |
||
142 | // unset($_REQUEST[self::getDbTable()]['wpshop_attribute_combo_values_list_order_def']); |
||
143 | |||
144 | if(!isset($attribute_parameter['status'])){ |
||
145 | $attribute_parameter['status'] = 'moderated'; |
||
146 | } |
||
147 | if(!isset($attribute_parameter['is_historisable'])){ |
||
148 | $attribute_parameter['is_historisable'] = 'no'; |
||
149 | } |
||
150 | if(!isset($attribute_parameter['is_required'])){ |
||
151 | $attribute_parameter['is_required'] = 'no'; |
||
152 | } |
||
153 | if(!isset($attribute_parameter['is_used_in_admin_listing_column'])){ |
||
154 | $attribute_parameter['is_used_in_admin_listing_column'] = 'no'; |
||
155 | } |
||
156 | if(!isset($attribute_parameter['is_used_in_quick_add_form'])){ |
||
157 | $attribute_parameter['is_used_in_quick_add_form'] = 'no'; |
||
158 | } |
||
159 | if(!isset($attribute_parameter['is_intrinsic'])){ |
||
160 | $attribute_parameter['is_intrinsic'] = 'no'; |
||
161 | } |
||
162 | if(!isset($attribute_parameter['is_requiring_unit'])){ |
||
163 | $attribute_parameter['is_requiring_unit'] = 'no'; |
||
164 | } |
||
165 | if(!isset($attribute_parameter['is_visible_in_front'])){ |
||
166 | $attribute_parameter['is_visible_in_front'] = 'no'; |
||
167 | } |
||
168 | if(!isset($attribute_parameter['is_visible_in_front_listing'])){ |
||
169 | $attribute_parameter['is_visible_in_front_listing'] = 'no'; |
||
170 | } |
||
171 | if(!isset($attribute_parameter['is_used_for_sort_by'])){ |
||
172 | $attribute_parameter['is_used_for_sort_by'] = 'no'; |
||
173 | } |
||
174 | if(!isset($attribute_parameter['is_visible_in_advanced_search'])){ |
||
175 | $attribute_parameter['is_visible_in_advanced_search'] = 'no'; |
||
176 | } |
||
177 | if(!isset($attribute_parameter['is_searchable'])){ |
||
178 | $attribute_parameter['is_searchable'] = 'no'; |
||
179 | } |
||
180 | if(!isset($attribute_parameter['is_used_for_variation'])){ |
||
181 | $attribute_parameter['is_used_for_variation'] = 'no'; |
||
182 | } |
||
183 | if(!isset($attribute_parameter['is_used_in_variation'])){ |
||
184 | $attribute_parameter['is_used_in_variation'] = 'no'; |
||
185 | } |
||
186 | if(!isset($attribute_parameter['is_user_defined'])){ |
||
187 | $attribute_parameter['is_user_defined'] = 'no'; |
||
188 | } |
||
189 | if(!isset($attribute_parameter['_display_informations_about_value'])){ |
||
190 | $attribute_parameter['_display_informations_about_value'] = 'no'; |
||
191 | } |
||
192 | |||
193 | /* Check frontend input and data type */ |
||
194 | if (!empty($attribute_parameter['frontend_input'])) { |
||
195 | switch ($attribute_parameter['frontend_input']) { |
||
196 | View Code Duplication | case 'short_text': |
|
197 | $attribute_parameter['frontend_input'] = 'text'; |
||
198 | if ( empty($attribute_parameter['backend_input']) ) $attribute_parameter['backend_input'] = 'text'; |
||
199 | $attribute_parameter['data_type'] = 'varchar'; |
||
200 | break; |
||
201 | View Code Duplication | case 'date_field': |
|
202 | $attribute_parameter['frontend_input'] = 'text'; |
||
203 | if ( empty($attribute_parameter['backend_input']) ) $attribute_parameter['backend_input'] = 'text'; |
||
204 | $attribute_parameter['data_type'] = 'datetime'; |
||
205 | break; |
||
206 | View Code Duplication | case 'float_field': |
|
207 | $attribute_parameter['frontend_input'] = 'text'; |
||
208 | if ( empty($attribute_parameter['backend_input']) ) $attribute_parameter['backend_input'] = 'text'; |
||
209 | $attribute_parameter['data_type'] = 'decimal'; |
||
210 | break; |
||
211 | View Code Duplication | case 'hidden_field': |
|
212 | $attribute_parameter['frontend_input'] = 'hidden'; |
||
213 | if ( empty($attribute_parameter['backend_input']) ) $attribute_parameter['backend_input'] = 'text'; |
||
214 | $attribute_parameter['data_type'] = 'varchar'; |
||
215 | break; |
||
216 | View Code Duplication | case 'pass_field': |
|
217 | $attribute_parameter['frontend_input'] = 'password'; |
||
218 | if ( empty($attribute_parameter['backend_input']) ) $attribute_parameter['backend_input'] = 'text'; |
||
219 | $attribute_parameter['data_type'] = 'varchar'; |
||
220 | break; |
||
221 | |||
222 | View Code Duplication | case 'select': |
|
223 | $attribute_parameter['frontend_input'] = 'select'; |
||
224 | if ( empty($attribute_parameter['backend_input']) || empty($id) ) |
||
225 | $attribute_parameter['backend_input'] = 'multiple-select'; |
||
226 | $attribute_parameter['data_type'] = 'integer'; |
||
227 | break; |
||
228 | View Code Duplication | case 'multiple-select': |
|
229 | $attribute_parameter['frontend_input'] = 'multiple-select'; |
||
230 | if ( empty($attribute_parameter['backend_input']) || empty($id) ) |
||
231 | $attribute_parameter['backend_input'] = 'multiple-select'; |
||
232 | $attribute_parameter['data_type'] = 'integer'; |
||
233 | break; |
||
234 | View Code Duplication | case 'radio': |
|
235 | $attribute_parameter['frontend_input'] = 'radio'; |
||
236 | if ( empty($attribute_parameter['backend_input']) || empty($id) ) |
||
237 | $attribute_parameter['backend_input'] = 'multiple-select'; |
||
238 | $attribute_parameter['data_type'] = 'integer'; |
||
239 | break; |
||
240 | View Code Duplication | case 'checkbox': |
|
241 | $attribute_parameter['frontend_input'] = 'checkbox'; |
||
242 | if ( empty($attribute_parameter['backend_input']) || empty($id) ) |
||
243 | $attribute_parameter['backend_input'] = 'multiple-select'; |
||
244 | $attribute_parameter['data_type'] = 'integer'; |
||
245 | break; |
||
246 | |||
247 | View Code Duplication | case 'textarea': |
|
248 | $attribute_parameter['frontend_input'] = 'textarea'; |
||
249 | if ( empty($attribute_parameter['backend_input']) || empty($id) ) |
||
250 | $attribute_parameter['backend_input'] = 'textarea'; |
||
251 | $attribute_parameter['data_type'] = 'text'; |
||
252 | break; |
||
253 | } |
||
254 | } |
||
255 | else { |
||
256 | $attribute_parameter['frontend_input'] = 'text'; |
||
257 | if ( empty($attribute_parameter['backend_input']) ) $attribute_parameter['backend_input'] = 'text'; |
||
258 | $attribute_parameter['data_type'] = 'varchar'; |
||
259 | } |
||
260 | |||
261 | /* Check if the checkbox for ajax activation is checked for data update */ |
||
262 | // if(!isset($attribute_parameter['use_ajax_for_filling_field']) || empty($attribute_parameter['use_ajax_for_filling_field'])){ |
||
263 | // $attribute_parameter['use_ajax_for_filling_field']='no'; |
||
264 | // } |
||
265 | $attribute_parameter['use_ajax_for_filling_field'] = 'yes'; |
||
266 | if( $attribute_parameter['backend_input'] == 'multiple-select' ) { |
||
267 | $attribute_parameter['is_used_for_variation'] = 'yes'; |
||
268 | } |
||
269 | |||
270 | /* Define the database operation type from action launched by the user */ |
||
271 | $attribute_parameter['default_value'] = (!empty($attribute_parameter['default_value']) && is_array($attribute_parameter['default_value'])) ? serialize($attribute_parameter['default_value']) : (isset($attribute_parameter['default_value']) ? str_replace('"', "'", $attribute_parameter['default_value']) : ''); |
||
272 | if ( $attribute_parameter['data_type'] == 'datetime' ) { |
||
273 | $date_default_value_trasform_into_config = array('default_value' => $attribute_parameter['default_value'], 'field_options' => (!empty($_POST[self::getDbTable() . '_options']) ? $_POST[self::getDbTable() . '_options'] : null)); |
||
274 | $attribute_parameter['default_value'] = serialize( $date_default_value_trasform_into_config ); |
||
275 | } |
||
276 | /***************************** GENERIC **************************/ |
||
277 | /*************************************************************************/ |
||
278 | $pageAction = (!empty($attribute_parameter['frontend_label']) && isset($_REQUEST[self::getDbTable() . '_action'])) ? sanitize_text_field($_REQUEST[self::getDbTable() . '_action']) : ((!empty($_GET['action']) && ($_GET['action']=='delete')) ? sanitize_text_field($_GET['action']) : ''); |
||
279 | $id = isset($attribute_parameter['id']) ? sanitize_key($attribute_parameter['id']) : ((!empty($_GET['id'])) ? $_GET['id'] : ''); |
||
280 | if(($pageAction != '') && (($pageAction == 'edit') || ($pageAction == 'editandcontinue'))){ |
||
281 | if(current_user_can('wpshop_edit_attributes')){ |
||
282 | $attribute_parameter['last_update_date'] = date('Y-m-d H:i:s'); |
||
283 | if($pageAction == 'delete'){ |
||
284 | $attribute_code = $attribute_parameter['code']; |
||
285 | if(!isset($attribute_parameter['code']) || ($attribute_parameter['code'] == '')){ |
||
286 | $attribute = self::getElement($id, "'valid', 'moderated', 'notused'", 'id'); |
||
287 | $attribute_code = $attribute->code; |
||
288 | } |
||
289 | if(!in_array($attribute_code, $attribute_undeletable)){ |
||
290 | if(current_user_can('wpshop_delete_attributes')){ |
||
291 | $attribute_parameter['status'] = 'deleted'; |
||
292 | } |
||
293 | else{ |
||
294 | $actionResult = 'userNotAllowedForActionDelete'; |
||
295 | } |
||
296 | } |
||
297 | else{ |
||
298 | $actionResult = 'unDeletableAtribute'; |
||
299 | } |
||
300 | } |
||
301 | $actionResult = wpshop_database::update($attribute_parameter, $id, self::getDbTable()); |
||
302 | } |
||
303 | else{ |
||
304 | $actionResult = 'userNotAllowedForActionEdit'; |
||
305 | } |
||
306 | } |
||
307 | elseif(($pageAction != '') && (($pageAction == 'delete'))){ |
||
308 | $attribute_code = ''; |
||
309 | View Code Duplication | if (empty( $attribute_parameter['code'])) { |
|
310 | $attribute = self::getElement($id, "'valid', 'moderated', 'notused', 'deleted'", 'id'); |
||
311 | $attribute_code = $attribute->code; |
||
312 | } |
||
313 | View Code Duplication | if (!in_array($attribute_code, $attribute_undeletable)) { |
|
314 | if(current_user_can('wpshop_delete_attributes')){ |
||
315 | $attribute_parameter['last_update_date'] = current_time('mysql', 0); |
||
316 | $attribute_parameter['status'] = 'deleted'; |
||
317 | $actionResult = wpshop_database::update($attribute_parameter, $id, self::getDbTable()); |
||
318 | } |
||
319 | else |
||
320 | $actionResult = 'userNotAllowedForActionDelete'; |
||
321 | } |
||
322 | else |
||
323 | $actionResult = 'unDeletableAtribute'; |
||
324 | } |
||
325 | View Code Duplication | elseif(($pageAction != '') && (($pageAction == 'save') || ($pageAction == 'saveandcontinue') || ($pageAction == 'add'))){ |
|
326 | if(current_user_can('wpshop_add_attributes')){ |
||
327 | $attribute_parameter['creation_date'] = current_time('mysql', 0); |
||
328 | if(trim($attribute_parameter['code']) == ''){ |
||
329 | $attribute_parameter['code'] = $attribute_parameter['frontend_label']; |
||
330 | } |
||
331 | $attribute_parameter['code'] = wpshop_tools::slugify(str_replace("\'", "_", str_replace('\"', "_", $attribute_parameter['code'])), array('noAccent', 'noSpaces', 'lowerCase', 'noPunctuation')); |
||
332 | $code_exists = self::getElement($attribute_parameter['code'], "'valid', 'moderated', 'deleted'", 'code'); |
||
333 | if((is_object($code_exists) || is_array($code_exists)) && (count($code_exists) > 0)){ |
||
334 | $attribute_parameter['code'] = $attribute_parameter['code'] . '_' . (count($code_exists) + rand()); |
||
335 | } |
||
336 | $actionResult = wpshop_database::save($attribute_parameter, self::getDbTable()); |
||
337 | $id = $wpdb->insert_id; |
||
338 | } |
||
339 | else{ |
||
340 | $actionResult = 'userNotAllowedForActionAdd'; |
||
341 | } |
||
342 | } |
||
343 | |||
344 | /* When an action is launched and there is a result message */ |
||
345 | /************ CHANGE THE FIELD NAME TO TAKE TO DISPLAY *************/ |
||
346 | /************ CHANGE ERROR MESSAGE FOR SPECIFIC CASE *************/ |
||
347 | /****************************************************************************/ |
||
348 | if($actionResult != ''){ |
||
349 | $elementIdentifierForMessage = __('the attribute', 'wpshop'); |
||
350 | if(!empty($attribute_parameter['name']))$elementIdentifierForMessage = '<span class="bold" >' . $attribute_parameter['frontend_label'] . '</span>'; |
||
351 | if ($actionResult == 'error') {/* CHANGE HERE FOR SPECIFIC CASE */ |
||
352 | $pageMessage .= '<img src="' . WPSHOP_ERROR_ICON . '" alt="action error" class="wpshopPageMessage_Icon" />' . sprintf(__('An error occured while saving %s', 'wpshop'), $elementIdentifierForMessage, ' -> ' . $wpdb->last_error); |
||
353 | } |
||
354 | else if (($actionResult == 'done') || ($actionResult == 'nothingToUpdate')) {/* CHANGE HERE FOR SPECIFIC CASE */ |
||
355 | /*****************************************************************************************************************/ |
||
356 | /************************* CHANGE FOR SPECIFIC ACTION FOR CURRENT ELEMENT ****************************/ |
||
357 | /*****************************************************************************************************************/ |
||
358 | /* Add the different option for the attribute that are set to combo box for frontend input */ |
||
359 | $done_options_value = array(); |
||
360 | $default_value = $attribute_parameter['default_value']; |
||
361 | $i = 1; |
||
362 | $options = !empty($_REQUEST['options']) ? (array) $_REQUEST['options'] : array(); |
||
363 | $optionsValue = !empty($_REQUEST['optionsValue']) ? (array) $_REQUEST['optionsValue'] : array(); |
||
364 | $optionsUpdate = !empty($_REQUEST['optionsUpdate']) ? (array) $_REQUEST['optionsUpdate'] : array(); |
||
365 | $optionsUpdateValue = !empty($_REQUEST['optionsUpdateValue']) ? (array) $_REQUEST['optionsUpdateValue'] : array(); |
||
366 | if ( !empty($optionsUpdate) ) { |
||
367 | /** |
||
368 | * Check if there is an attribute code into sended request or if we have to get the code from database (Bug fix) |
||
369 | */ |
||
370 | View Code Duplication | if (empty($attribute_parameter['code'])) { |
|
371 | $attribute = self::getElement($id, "'valid', 'moderated', 'notused'", 'id'); |
||
372 | $attribute_code = $attribute->code; |
||
373 | } |
||
374 | else { |
||
375 | $attribute_code = $attribute_parameter['code']; |
||
376 | } |
||
377 | foreach ($optionsUpdate as $option_key => $option_label) { |
||
378 | $option_value = !empty($optionsUpdateValue[$option_key]) ? str_replace(",", ".", $optionsUpdateValue[$option_key]) : ''; |
||
379 | |||
380 | if ( empty($option_value) || !in_array($option_value, $done_options_value) ) { |
||
381 | /* Update an existing value only if the value does not exist into existing list */ |
||
382 | $label = (($option_label != '') ? $option_label : str_replace(",", ".", $option_value)); |
||
383 | $value = str_replace(",", ".", $option_value); |
||
384 | if( !WPSHOP_DISPLAY_VALUE_FOR_ATTRIBUTE_SELECT ) { |
||
385 | $label = $option_label; |
||
386 | $value = str_replace(",", ".", $label); |
||
387 | } |
||
388 | |||
389 | $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('last_update_date' => current_time('mysql', 0), 'position' => $i, 'label' => stripslashes($label), 'value' => stripslashes($value)), array('id' => $option_key)); |
||
390 | $done_options_value[] = str_replace(",", ".", $option_value); |
||
391 | |||
392 | /* Check if this value is used for price calculation and make update on the different product using this value */ |
||
393 | if($attribute_code == WPSHOP_PRODUCT_PRICE_TAX){ |
||
394 | $action = wpshop_prices::mass_update_prices(); |
||
395 | } |
||
396 | } |
||
397 | |||
398 | View Code Duplication | if($default_value == $option_key) { |
|
399 | /* Update an existing a only if the value does not exist into existing list */ |
||
400 | $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('last_update_date' => current_time('mysql', 0), 'default_value' => $option_key), array('id' => $id)); |
||
401 | $done_options_value[] = str_replace(",", ".", $option_value); |
||
402 | } |
||
403 | $i++; |
||
404 | } |
||
405 | } |
||
406 | if ( !empty($options) ) { |
||
407 | foreach ( $options as $option_key => $option_label ) { |
||
408 | $option_value = !empty($optionsValue[$option_key]) ? str_replace(",", ".", $optionsValue[$option_key]) : sanitize_title($option_label); |
||
409 | |||
410 | /* Check what value to use for the new values */ |
||
411 | $label = (!empty($option_label) ? $option_label : str_replace(",", ".", $option_value)); |
||
412 | if( !WPSHOP_DISPLAY_VALUE_FOR_ATTRIBUTE_SELECT && empty($option_value) ) { |
||
413 | $label = $option_label; |
||
414 | $option_value = sanitize_title($label); |
||
415 | } |
||
416 | |||
417 | // If the optionsUpdateValue is empty, set it a empty array to avoid error calling the in_array() function |
||
418 | // $_REQUEST['optionsUpdateValue'] = !empty($_REQUEST['optionsUpdateValue']) ? $_REQUEST['optionsUpdateValue'] : array(); |
||
419 | |||
420 | if (!in_array($option_value, $done_options_value) && !in_array($option_value, $optionsUpdateValue) ) { |
||
421 | |||
422 | $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('creation_date' => current_time('mysql', 0), 'status' => 'valid', 'attribute_id' => $id, 'position' => $i, 'label' => stripslashes($label), 'value' => stripslashes($option_value))); |
||
423 | $done_options_value[] = str_replace(",", ".", $option_value); |
||
424 | $last_insert_id = $wpdb->insert_id; |
||
425 | |||
426 | View Code Duplication | if (empty($default_value)) { |
|
427 | /* Update an existing a only if the value does not exist into existing list */ |
||
428 | $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('last_update_date' => current_time('mysql', 0), 'default_value' => $last_insert_id), array('id' => $id)); |
||
429 | $done_options_value[] = str_replace(",", ".", $option_value); |
||
430 | } |
||
431 | |||
432 | } |
||
433 | $i++; |
||
434 | } |
||
435 | } |
||
436 | |||
437 | // If the is_used_for_sort_by is mark as yes, we have to get out some attributes and save it separately |
||
438 | if( (!empty($attribute_parameter['is_used_for_sort_by']) && ($attribute_parameter['is_used_for_sort_by'] == 'yes')) || (!empty($attribute_parameter['is_filterable']) && ($attribute_parameter['is_filterable'] == 'yes')) || (!empty($attribute_parameter['is_searchable']) && ($attribute_parameter['is_searchable'] == 'yes')) ){ |
||
439 | $attribute_code = $attribute_parameter['code']; |
||
440 | if(!isset($attribute_parameter['code']) || ($attribute_parameter['code'] == '')){ |
||
441 | $attribute = self::getElement($id, "'valid', 'moderated', 'notused'", 'id'); |
||
442 | $attribute_code = $attribute->code; |
||
443 | } |
||
444 | |||
445 | $count_products = wp_count_posts(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
||
446 | for( $i = 0; $i <= $count_products->publish; $i+= 20 ) { |
||
447 | $query = $wpdb->prepare( 'SELECT * FROM '. $wpdb->posts .' WHERE post_type = %s AND post_status = %s ORDER BY ID DESC LIMIT '.$i.', 20', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'publish' ); |
||
448 | $products = $wpdb->get_results( $query ); |
||
449 | if ( !empty($products) ) { |
||
450 | foreach( $products as $product ) { |
||
451 | $query = $wpdb->prepare("SELECT value FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . $attribute_parameter['data_type'] . " WHERE attribute_id = %d AND entity_type_id = %d AND entity_id = %d AND value != '' ORDER BY creation_date_value DESC", $id, $attribute_parameter['entity_id'], $product->ID); |
||
452 | $value = $wpdb->get_var($query); |
||
453 | update_post_meta($product->ID, '_' . $attribute_code, $value); |
||
454 | } |
||
455 | } |
||
456 | } |
||
457 | wp_reset_query(); |
||
458 | } |
||
459 | |||
460 | if ( $pageAction != 'delete' ) {/* Add the new attribute in the additionnal informations attribute group */ |
||
461 | if ( !empty($set_section) ) { |
||
462 | $choosen_set_section = explode('_', $set_section); |
||
463 | $set_id = $choosen_set_section[0]; |
||
464 | $group_id = $choosen_set_section[1]; |
||
465 | } |
||
466 | else{ |
||
467 | $attribute_current_attribute_set = 0; |
||
468 | $query = $wpdb->prepare(" |
||
469 | SELECT id |
||
470 | FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " AS ATTRIBUTE_SET_DETAILS |
||
471 | WHERE ATTRIBUTE_SET_DETAILS.status = 'valid' |
||
472 | AND ATTRIBUTE_SET_DETAILS.attribute_id = %d |
||
473 | AND ATTRIBUTE_SET_DETAILS.entity_type_id = %d", $id, $attribute_parameter['entity_id']); |
||
474 | $attribute_current_attribute_set = $wpdb->get_results($query); |
||
475 | |||
476 | if ( empty($attribute_current_attribute_set) ) { |
||
477 | $query = $wpdb->prepare(" |
||
478 | SELECT |
||
479 | ( |
||
480 | SELECT ATTRIBUTE_SET.id |
||
481 | FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " AS ATTRIBUTE_SET |
||
482 | WHERE ATTRIBUTE_SET.entity_id = %d |
||
483 | AND ATTRIBUTE_SET.default_set = 'yes' |
||
484 | ) AS attribute_set_id, |
||
485 | ( |
||
486 | SELECT ATTRIBUTE_GROUP.id |
||
487 | FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " AS ATTRIBUTE_GROUP |
||
488 | INNER JOIN " . WPSHOP_DBT_ATTRIBUTE_SET . " AS ATTRIBUTE_SET ON ((ATTRIBUTE_SET.id = ATTRIBUTE_GROUP.attribute_set_id) AND (ATTRIBUTE_SET.entity_id = %d)) |
||
489 | WHERE ATTRIBUTE_GROUP.default_group = 'yes' |
||
490 | AND ATTRIBUTE_GROUP.status = 'valid' |
||
491 | ) AS attribute_group_id" |
||
492 | , $attribute_parameter['entity_id'], $attribute_parameter['entity_id'], $attribute_parameter['entity_id'], $attribute_parameter['entity_id'] |
||
493 | ); |
||
494 | $wpshop_default_group = $wpdb->get_row($query); |
||
495 | |||
496 | $set_id = $wpshop_default_group->attribute_set_id; |
||
497 | $default_group_id = ( !empty( $wpshop_default_group->default_attribute_group_id) ) ? $wpshop_default_group->default_attribute_group_id : ''; |
||
498 | $group_id = !empty($default_group_id) ? $default_group_id : $wpshop_default_group->attribute_group_id; |
||
499 | } |
||
500 | } |
||
501 | |||
502 | if ( !empty($set_id) && !empty($group_id) ) { |
||
503 | $query = $wpdb->prepare( |
||
504 | "SELECT (MAX(position) + 1) AS position |
||
505 | FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " |
||
506 | WHERE attribute_set_id = %s |
||
507 | AND attribute_group_id = %s |
||
508 | AND entity_type_id = %s ", |
||
509 | $set_id, |
||
510 | $group_id, |
||
511 | $attribute_parameter['entity_id'] |
||
512 | ); |
||
513 | $wpshopAttributePosition = $wpdb->get_var($query); |
||
514 | if($wpshopAttributePosition == 0)$wpshopAttributePosition = 1; |
||
515 | $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $attribute_parameter['entity_id'], 'attribute_set_id' => $set_id, 'attribute_group_id' => $group_id, 'attribute_id' => $id, 'position' => $wpshopAttributePosition)); |
||
516 | } |
||
517 | } |
||
518 | |||
519 | if ( !empty($wpshop_attribute_combo_values_list_order_def) ) { |
||
520 | $post_order = explode(',', $wpshop_attribute_combo_values_list_order_def); |
||
521 | $position = 1; |
||
522 | foreach ($post_order as $post_id) { |
||
523 | $wpdb->update($wpdb->posts, array('menu_order' => $position), array('ID' => str_replace('post_', '', $post_id))); |
||
524 | $position++; |
||
525 | } |
||
526 | } |
||
527 | |||
528 | /************************* GENERIC ****************************/ |
||
529 | /*************************************************************************/ |
||
530 | $pageMessage .= '<img src="' . WPSHOP_SUCCES_ICON . '" alt="action success" class="wpshopPageMessage_Icon" />' . sprintf(__('%s succesfully saved', 'wpshop'), $elementIdentifierForMessage); |
||
531 | /* if(($pageAction == 'edit') || ($pageAction == 'save')){ |
||
532 | wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . self::getListingSlug() . "&action=saveok&saveditem=" . $id)); |
||
533 | } |
||
534 | else */ |
||
535 | View Code Duplication | if ( $pageAction == 'add' ) |
|
536 | wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . self::getListingSlug() . "&action=edit&id=" . $id)); |
||
537 | elseif ( $pageAction == 'delete' ) |
||
538 | wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . self::getListingSlug() . "&action=deleteok&saveditem=" . $id)); |
||
539 | } |
||
540 | View Code Duplication | elseif(($actionResult == 'userNotAllowedForActionEdit') || ($actionResult == 'userNotAllowedForActionAdd') || ($actionResult == 'userNotAllowedForActionDelete')){ |
|
541 | $pageMessage .= '<img src="' . WPSHOP_ERROR_ICON . '" alt="action error" class="wpshopPageMessage_Icon" />' . __('You are not allowed to do this action', 'wpshop'); |
||
542 | } |
||
543 | elseif(($actionResult == 'unDeletableAtribute')){ |
||
544 | $pageMessage .= '<img src="' . WPSHOP_ERROR_ICON . '" alt="action error" class="wpshopPageMessage_Icon" />' . __('This attribute could not be deleted due to configuration', 'wpshop'); |
||
545 | } |
||
546 | |||
547 | if(empty($attribute_parameter['frontend_label']) && ($pageAction!='delete')){ |
||
548 | $pageMessage .= __('Please enter an label for the attribut', 'wpshop'); |
||
549 | } |
||
550 | } |
||
551 | |||
552 | self::setMessage($pageMessage); |
||
553 | } |
||
554 | |||
555 | /** |
||
556 | * Return the list page content, containing the table that present the item list |
||
557 | * |
||
558 | * @return string $listItemOutput The html code that output the item list |
||
559 | */ |
||
560 | function elementList() { |
||
561 | global $wpdb; |
||
562 | //Create an instance of our package class... |
||
563 | $wpshop_list_table = new wpshop_attributes_custom_List_table(); |
||
564 | //Fetch, prepare, sort, and filter our data... |
||
565 | $status="'valid'"; |
||
566 | $attribute_status = !empty($_REQUEST['attribute_status']) ? sanitize_text_field( $_REQUEST['attribute_status'] ) : null; |
||
567 | $s = !empty($_REQUEST['s']) ? sanitize_text_field( $_REQUEST['s'] ) : null; |
||
568 | $order = !empty($_REQUEST['order']) ? sanitize_text_field($_REQUEST['order']) : null; |
||
569 | $orderby = !empty($_REQUEST['orderby']) ? sanitize_text_field($_REQUEST['orderby']) : null; |
||
570 | if(!empty($attribute_status)){ |
||
571 | switch($attribute_status){ |
||
572 | case 'unactive': |
||
573 | $status="'moderated', 'notused'"; |
||
574 | if(empty($order_by) && empty($order)){ |
||
575 | // @TODO : REQUEST |
||
576 | // $_REQUEST['orderby']='status'; |
||
577 | // $_REQUEST['order']='asc'; |
||
578 | } |
||
579 | break; |
||
580 | default: |
||
581 | $status="'".sanitize_text_field($_REQUEST['attribute_status'])."'"; |
||
582 | break; |
||
583 | } |
||
584 | } |
||
585 | View Code Duplication | if ( !empty($s) ) { |
|
586 | $query = $wpdb->prepare("SELECT * FROM " . self::dbTable . ' WHERE frontend_label LIKE "%%%1$s%%" OR frontend_label LIKE "%%%2$s%%" AND backend_label LIKE "%%%1$s%%" OR backend_label LIKE "%%%2$s%%" AND code LIKE "%%%1$s%%" OR code LIKE "%%%2$s%%"', $s, __($s, 'wpshop') ); |
||
587 | $attr_set_list = $wpdb->get_results( $query ); |
||
588 | } |
||
589 | else { |
||
590 | $attr_set_list = self::getElement( '', $status ); |
||
591 | } |
||
592 | $i=0; |
||
593 | $attribute_set_list=array(); |
||
594 | foreach($attr_set_list as $attr_set){ |
||
595 | if(!empty($attr_set->id) && ($attr_set->code != 'product_attribute_set_id') ){ |
||
596 | $attribute_set_list[$i]['id'] = $attr_set->id; |
||
597 | $attribute_set_list[$i]['name'] = $attr_set->frontend_label; |
||
598 | $attribute_set_list[$i]['status'] = $attr_set->status; |
||
599 | $attribute_set_list[$i]['entity'] = $attr_set->entity_id; |
||
600 | $attribute_set_list[$i]['code'] = $attr_set->code; |
||
601 | $i++; |
||
602 | } |
||
603 | } |
||
604 | |||
605 | |||
606 | $wpshop_list_table->datas = $attribute_set_list; |
||
607 | $wpshop_list_table->prepare_items(); |
||
608 | |||
609 | ob_start(); |
||
610 | ?> |
||
611 | <div class="wrap"> |
||
612 | <!-- Forms are NOT created automatically, so you need to wrap the table in one to use features like bulk actions --> |
||
613 | <?php $wpshop_list_table->views() ?> |
||
614 | <form id="attributes_filter" method="get"> |
||
615 | <input type="hidden" name="page" value="<?php echo esc_attr($_REQUEST['page']); ?>" /> |
||
616 | <?php $wpshop_list_table->search_box('search', sanitize_text_field($_REQUEST['page']) . '_search_input'); ?> |
||
617 | </form> |
||
618 | <form id="attributes_filter" method="get"> |
||
619 | <!-- For plugins, we also need to ensure that the form posts back to our current page --> |
||
620 | <input type="hidden" name="page" value="<?php echo esc_attr($_REQUEST['page']); ?>" /> |
||
621 | <!-- Now we can render the completed list table --> |
||
622 | <?php $wpshop_list_table->display() ?> |
||
623 | </form> |
||
624 | </div> |
||
625 | <?php |
||
626 | $element_output = ob_get_contents(); |
||
627 | ob_end_clean(); |
||
628 | |||
629 | return $element_output; |
||
630 | } |
||
631 | |||
632 | /** |
||
633 | * Return the page content to add a new item |
||
634 | * |
||
635 | * @return string The html code that output the interface for adding a nem item |
||
636 | */ |
||
637 | function elementEdition($itemToEdit = '') { |
||
638 | global $attribute_displayed_field, $attribute_options_group; |
||
639 | $dbFieldList = wpshop_database::fields_to_input(self::getDbTable()); |
||
640 | $editedItem = ''; |
||
641 | if($itemToEdit != '') |
||
642 | $editedItem = self::getElement($itemToEdit); |
||
643 | |||
644 | $the_form_content_hidden = $the_form_general_content = ''; |
||
645 | $the_form_option_content_list = array(); |
||
646 | foreach($dbFieldList as $input_key => $input_def){ |
||
647 | |||
648 | if(!isset($attribute_displayed_field) || !is_array($attribute_displayed_field) || in_array($input_def['name'], $attribute_displayed_field)){ |
||
649 | $input_def['label'] = $input_def['name']; |
||
650 | $input_def_id=$input_def['id']='wpshop_' . self::currentPageCode . '_edition_table_field_id_'.$input_def['label']; |
||
651 | |||
652 | $pageAction = isset($_REQUEST[self::getDbTable() . '_action']) ? sanitize_text_field($_REQUEST[self::getDbTable() . '_action']) : ''; |
||
653 | $requestFormValue = isset($_REQUEST[self::currentPageCode][$input_def['label']]) ? sanitize_text_field($_REQUEST[self::currentPageCode][$input_def['label']]) : ''; |
||
654 | $currentFieldValue = $input_def['value']; |
||
655 | View Code Duplication | if(is_object($editedItem)) |
|
656 | $currentFieldValue = $editedItem->{$input_def['label']}; |
||
657 | elseif(($pageAction != '') && ($requestFormValue != '')) |
||
658 | $currentFieldValue = $requestFormValue; |
||
659 | |||
660 | if($input_def['label'] == 'status'){ |
||
661 | View Code Duplication | if(in_array('notused', $input_def['possible_value'])){ |
|
662 | $key = array_keys($input_def['possible_value'], 'notused'); |
||
663 | unset($input_def['possible_value'][$key[0]]); |
||
664 | } |
||
665 | View Code Duplication | if(in_array('dbl', $input_def['possible_value'])){ |
|
666 | $key = array_keys($input_def['possible_value'], 'dbl'); |
||
667 | unset($input_def['possible_value'][$key[0]]); |
||
668 | } |
||
669 | |||
670 | $input_def['type'] = 'checkbox'; |
||
671 | $input_def['label'] = __('Use this attribute', 'wpshop'); |
||
672 | $input_def['possible_value'] = array('valid'); |
||
673 | $input_def_id.='_valid'; |
||
674 | $input_def['options_label']['custom'] = '<a href="#" title="'.__('Check this box for using this attribute', 'wpshop').'" class="wpshop_infobulle_marker">?</a>'; |
||
675 | } |
||
676 | |||
677 | if ( (substr($input_def['label'], 0, 3) == 'is_') || ( $input_def['label'] == '_display_informations_about_value') ) { |
||
678 | $input_def['type'] = 'checkbox'; |
||
679 | $input_def['possible_value'] = 'yes'; |
||
680 | } |
||
681 | switch($input_def['label']){ |
||
682 | View Code Duplication | case 'is_requiring_unit': |
|
683 | $input_def['options_label']['custom'] = '<a href="#" title="'.__('Check this box for using unit with this attribute', 'wpshop').'" class="wpshop_infobulle_marker">?</a>'; |
||
684 | break; |
||
685 | View Code Duplication | case 'is_visible_in_front': |
|
686 | $input_def['options_label']['custom'] = '<a href="#" title="'.__('Check this box for displaying this attribute in shop', 'wpshop').'" class="wpshop_infobulle_marker">?</a>'; |
||
687 | break; |
||
688 | View Code Duplication | case 'is_visible_in_front_listing': |
|
689 | $input_def['options_label']['custom'] = '<a href="#" title="'.__('Check this box for displaying this attribute in product listing in shop', 'wpshop').'" class="wpshop_infobulle_marker">?</a>'; |
||
690 | break; |
||
691 | View Code Duplication | case 'is_used_for_sort_by': |
|
692 | $input_def['options_label']['custom'] = '<a href="#" title="'.__('Check this box for displaying this attribute into sortbar', 'wpshop').'" class="wpshop_infobulle_marker">?</a>'; |
||
693 | break; |
||
694 | View Code Duplication | case 'is_searchable': |
|
695 | $input_def['options_label']['custom'] = '<a href="#" title="'.__('Check this box for including values of this attribute as search parameter', 'wpshop').'" class="wpshop_infobulle_marker">?</a>'; |
||
696 | break; |
||
697 | View Code Duplication | case 'is_visible_in_advanced_search': |
|
698 | $input_def['options_label']['custom'] = '<a href="#" title="'.__('Check this box for using in advanced search form', 'wpshop').'" class="wpshop_infobulle_marker">?</a>'; |
||
699 | break; |
||
700 | View Code Duplication | case 'frontend_css_class': |
|
701 | $input_def['options_label']['custom'] = '<a href="#" title="'.__('Separate with a space each CSS Class', 'wpshop').'" class="wpshop_infobulle_marker">?</a>'; |
||
702 | break; |
||
703 | View Code Duplication | case 'backend_css_class': |
|
704 | $input_def['options_label']['custom'] = '<a href="#" title="'.__('Separate with a space each CSS Class', 'wpshop').'" class="wpshop_infobulle_marker">?</a>'; |
||
705 | break; |
||
706 | View Code Duplication | case 'is_historisable': |
|
707 | $input_def['options_label']['custom'] = '<a href="#" title="'.__('Check this box if you want to save the different value this attribute, each time it is modified', 'wpshop').'" class="wpshop_infobulle_marker">?</a>'; |
||
708 | break; |
||
709 | View Code Duplication | case 'is_filterable': |
|
710 | $input_def['options_label']['custom'] = '<a href="#" title="'.__('Check this box if you want to use this attribute in the filter search', 'wpshop').'" class="wpshop_infobulle_marker">?</a>'; |
||
711 | break; |
||
712 | View Code Duplication | case 'is_intrinsic': |
|
713 | $input_def['options_label']['custom'] = '<a href="#" title="'.__('Check this box if this attribute is intrinsic for a product', 'wpshop').'" class="wpshop_infobulle_marker">?</a>'; |
||
714 | break; |
||
715 | View Code Duplication | case 'is_used_for_variation': |
|
716 | $input_def['options_label']['custom'] = '<a href="#" title="'.__('Check this box if this attribute is used for variation. It means that the user would be able to choose a value in frontend', 'wpshop').'" class="wpshop_infobulle_marker">?</a>'; |
||
717 | break; |
||
718 | case 'is_used_in_variation': |
||
719 | $input_def['options_label']['custom'] = '<a href="#" title="'.__('Check this box if you want to use this attribute for variation definition', 'wpshop').'" class="wpshop_infobulle_marker">?</a>'; |
||
720 | if ( !empty($editedItem) && ($editedItem->is_used_for_variation == 'yes') ) { |
||
721 | $input_def['option'] = 'disabled="disabled"'; |
||
722 | } |
||
723 | break; |
||
724 | View Code Duplication | case 'is_user_defined': |
|
725 | $input_def['options_label']['custom'] = '<a href="#" title="'.__('Check this box if you want your customer to choose a value for this attribute into frontend product', 'wpshop').'" class="wpshop_infobulle_marker">?</a>'; |
||
726 | break; |
||
727 | } |
||
728 | |||
729 | $input_def['value'] = $currentFieldValue; |
||
730 | if($input_def['label'] == 'code') |
||
731 | $input_def['type'] = 'hidden'; |
||
732 | elseif($input_def['label'] == 'entity_id'){ |
||
733 | $input_def['possible_value'] = wpshop_entities::get_entities_list(); |
||
734 | $input_def['valueToPut'] = 'index'; |
||
735 | $input_def['type'] = 'select'; |
||
736 | |||
737 | $i=0; |
||
738 | foreach($input_def['possible_value'] as $entity_id => $entity_name) { |
||
739 | if($i <= 0){ |
||
740 | $current_entity_id = $entity_id; |
||
741 | } |
||
742 | $i++; |
||
743 | } |
||
744 | } |
||
745 | elseif($input_def['label'] == '_unit_group_id'){ |
||
746 | $input_def['possible_value'] = wpshop_attributes_unit::get_unit_group(); |
||
747 | $input_def['type'] = 'select'; |
||
748 | } |
||
749 | elseif($input_def['label'] == '_default_unit'){ |
||
750 | $unit_group_list = wpshop_attributes_unit::get_unit_group(); |
||
751 | $input_def['possible_value'] = wpshop_attributes_unit::get_unit_list_for_group(!empty($editedItem->_unit_group_id)?$editedItem->_unit_group_id:(!empty($unit_group_list)?$unit_group_list[0]->id:'')); |
||
752 | $input_def['type'] = 'select'; |
||
753 | } |
||
754 | elseif ($input_def['label'] == 'backend_input') { |
||
755 | if ( !is_object($editedItem) ) { |
||
756 | $input_def['type'] = 'hidden'; |
||
757 | } |
||
758 | else { |
||
759 | $new_possible_value = array(); |
||
760 | View Code Duplication | switch ( $editedItem->data_type) { |
|
761 | case 'integer': |
||
762 | $new_possible_value[__('Checkbox', 'wpshop')] = 'checkbox'; |
||
763 | $new_possible_value[__('Radio button', 'wpshop')] = 'radio'; |
||
764 | $new_possible_value[__('select', 'wpshop')] = 'select'; |
||
765 | $new_possible_value[__('multiple-select', 'wpshop')] = 'multiple-select'; |
||
766 | break; |
||
767 | case 'varchar': |
||
768 | switch ( $input_def['value'] ) { |
||
769 | case 'hidden': |
||
770 | $new_possible_value[__('Hidden field', 'wpshop')] = 'hidden_field'; |
||
771 | break; |
||
772 | case 'password': |
||
773 | $new_possible_value[__('Password field', 'wpshop')] = 'pass_field'; |
||
774 | break; |
||
775 | default: |
||
776 | $new_possible_value[__('Text field', 'wpshop')] = 'short_text'; |
||
777 | break; |
||
778 | } |
||
779 | break; |
||
780 | case 'text': |
||
781 | $new_possible_value[__('Textarea field', 'wpshop')] = 'textarea'; |
||
782 | break; |
||
783 | case 'decimal': |
||
784 | $new_possible_value[__('Number field', 'wpshop')] = 'float_field'; |
||
785 | break; |
||
786 | case 'datetime': |
||
787 | $new_possible_value[__('Date field', 'wpshop')] = 'date_field'; |
||
788 | break; |
||
789 | } |
||
790 | $input_def['possible_value'] = $new_possible_value; |
||
791 | } |
||
792 | } |
||
793 | elseif ($input_def['label'] == 'frontend_input') { |
||
794 | $new_possible_value = array(); |
||
795 | |||
796 | if ( is_object($editedItem) ) { |
||
797 | View Code Duplication | switch ( $editedItem->data_type) { |
|
798 | case 'integer': |
||
799 | $new_possible_value[__('Checkbox', 'wpshop')] = 'checkbox'; |
||
800 | $new_possible_value[__('Radio button', 'wpshop')] = 'radio'; |
||
801 | $new_possible_value[__('select', 'wpshop')] = 'select'; |
||
802 | $new_possible_value[__('multiple-select', 'wpshop')] = 'multiple-select'; |
||
803 | break; |
||
804 | case 'varchar': |
||
805 | switch ( $input_def['value'] ) { |
||
806 | case 'hidden': |
||
807 | $new_possible_value[__('Hidden field', 'wpshop')] = 'hidden_field'; |
||
808 | break; |
||
809 | case 'password': |
||
810 | $new_possible_value[__('Password field', 'wpshop')] = 'pass_field'; |
||
811 | break; |
||
812 | default: |
||
813 | $new_possible_value[__('Text field', 'wpshop')] = 'short_text'; |
||
814 | break; |
||
815 | } |
||
816 | break; |
||
817 | case 'text': |
||
818 | $new_possible_value[__('Textarea field', 'wpshop')] = 'textarea'; |
||
819 | break; |
||
820 | case 'decimal': |
||
821 | $new_possible_value[__('Number field', 'wpshop')] = 'float_field'; |
||
822 | break; |
||
823 | case 'datetime': |
||
824 | $new_possible_value[__('Date field', 'wpshop')] = 'date_field'; |
||
825 | break; |
||
826 | } |
||
827 | } |
||
828 | else { |
||
829 | $new_possible_value[__('Text field', 'wpshop')] = 'short_text'; |
||
830 | $new_possible_value[__('Number field', 'wpshop')] = 'float_field'; |
||
831 | $new_possible_value[__('Date field', 'wpshop')] = 'date_field'; |
||
832 | $new_possible_value[__('Textarea field', 'wpshop')] = 'textarea'; |
||
833 | $new_possible_value[__('Password field', 'wpshop')] = 'pass_field'; |
||
834 | $new_possible_value[__('Hidden field', 'wpshop')] = 'hidden_field'; |
||
835 | $new_possible_value[__('Checkbox', 'wpshop')] = 'checkbox'; |
||
836 | $new_possible_value[__('Radio button', 'wpshop')] = 'radio'; |
||
837 | $new_possible_value[__('select', 'wpshop')] = 'select'; |
||
838 | $new_possible_value[__('multiple-select', 'wpshop')] = 'multiple-select'; |
||
839 | } |
||
840 | |||
841 | $input_def['possible_value'] = $new_possible_value; |
||
842 | |||
843 | if ( !empty($editedItem->frontend_input) ) { |
||
844 | switch ( $editedItem->frontend_input ) { |
||
845 | case 'text': |
||
846 | switch ( $editedItem->data_type ) { |
||
847 | case 'varchar': |
||
848 | $input_def['value'] = 'short_text'; |
||
849 | break; |
||
850 | case 'decimal': |
||
851 | $input_def['value'] = 'float_field'; |
||
852 | break; |
||
853 | case 'datetime': |
||
854 | $input_def['value'] = 'date_field'; |
||
855 | break; |
||
856 | case 'hidden': |
||
857 | $input_def['value'] = 'hidden_field'; |
||
858 | break; |
||
859 | case 'password': |
||
860 | $input_def['value'] = 'pass_field'; |
||
861 | break; |
||
862 | } |
||
863 | break; |
||
864 | default: |
||
865 | $input_def['value'] = $editedItem->frontend_input; |
||
866 | break; |
||
867 | } |
||
868 | } |
||
869 | } |
||
870 | |||
871 | if(is_object($editedItem) && (($input_def['label'] == 'code') || ($input_def['label'] == 'data_type') || ($input_def['label'] == 'entity_id'))){ |
||
872 | // $input_def['type'] = 'hidden'; |
||
873 | $input_def['option'] = ' disabled="disabled" '; |
||
874 | $the_form_content_hidden .= '<input type="hidden" name="' . self::getDbTable() . '[' . $input_def['name'] . ']" value="' . $input_def['value'] . '" />'; |
||
875 | $input_def['label'] = $input_def['name']; |
||
876 | $input_def['name'] = $input_def['name'] . '_already_defined'; |
||
877 | } |
||
878 | |||
879 | $input_def['value'] = str_replace("\\", "", $input_def['value']); |
||
880 | |||
881 | $the_input = wpshop_form::check_input_type($input_def, self::getDbTable()); |
||
882 | if ( $input_def['label'] == 'default_value' ) { |
||
883 | if ( !empty($editedItem->frontend_input) ) { |
||
884 | switch ( $editedItem->frontend_input ) { |
||
885 | case 'text': |
||
886 | $input_def['type'] = 'text'; |
||
887 | switch ( $editedItem->data_type ) { |
||
888 | case 'datetime': |
||
889 | $the_input = wpshop_attributes::attribute_type_date_config( unserialize($input_def['value']) ); |
||
890 | |||
891 | $input_def['label'] = __('Date field configuration','wpshop'); |
||
892 | break; |
||
893 | default: |
||
894 | $the_input = wpshop_form::check_input_type($input_def, WPSHOP_DBT_ATTRIBUTE); |
||
895 | break; |
||
896 | } |
||
897 | break; |
||
898 | case 'hidden': |
||
899 | $the_input = ''; |
||
900 | break; |
||
901 | case 'password': |
||
902 | $the_input = ''; |
||
903 | break; |
||
904 | case 'select': |
||
905 | case 'multiple-select': |
||
906 | case 'radio': |
||
907 | case 'checkbox': |
||
908 | $input_def['label'] = __('Options list for attribute','wpshop') . ' |
||
909 | <div class="alignright wpshop_change_select_data_type" > |
||
910 | +' . __('Change data type for this attribute', 'wpshop') . ' |
||
911 | </div>'; |
||
912 | $the_input = wpshop_attributes::get_select_options_list($itemToEdit, $editedItem->data_type_to_use); |
||
913 | |||
914 | break; |
||
915 | case 'textarea': |
||
916 | $input_def['type'] = 'textarea'; |
||
917 | $the_input = wpshop_form::check_input_type($input_def, WPSHOP_DBT_ATTRIBUTE); |
||
918 | break; |
||
919 | } |
||
920 | } |
||
921 | else { |
||
922 | $input_def['type']='text'; |
||
923 | $the_input = wpshop_form::check_input_type($input_def, self::getDbTable()); |
||
924 | } |
||
925 | } |
||
926 | if( $input_def['label'] == '_unit_group_id') { |
||
927 | $the_input .= '<div id="wpshop_loader_input_group_unit"></div>'; |
||
928 | $the_input .= '<a class="button-primary" href="#wpshop_unit_group_list" id="wpshop_attribute_group_unit_manager_opener" data-nonce="' . wp_create_nonce( 'load_unit_interface' ) . '">'.__('Manage group unit', 'wpshop').'</a>'; |
||
929 | } |
||
930 | |||
931 | if( $input_def['label'] == '_default_unit') { |
||
932 | $the_input .= '<div id="wpshop_loader_input_unit"></div>'; |
||
933 | $the_input .= '<a class="button-primary" href="#wpshop_unit_list" id="wpshop_attribute_unit_manager_opener" data-nonce="' . wp_create_nonce( 'load_unit_interface' ) . '">'.__('Manage units', 'wpshop').'</a>'; |
||
934 | $the_input .= '<input type="hidden" name="input_wpshop_load_attribute_unit_list" id="input_wpshop_load_attribute_unit_list" value="' . wp_create_nonce("wpshop_load_attribute_unit_list") . '" />'; |
||
935 | $the_input .= '<div id="wpshop_attribute_unit_manager" title="' . __('Unit management', 'wpshop') . '" class="wpshopHide" ><div class="loading_picture_container" id="product_chooser_picture" ><img src="' . WPSHOP_LOADING_ICON . '" alt="loading..." /></div></div>'; |
||
936 | } |
||
937 | |||
938 | |||
939 | if($input_def['type'] != 'hidden'){ |
||
940 | if ( ($input_def['label'] == 'entity_id') && is_object($editedItem) ) { |
||
941 | $the_input .= '<br/><span class="wpshop_duplicate_attribute" >' . __('Duplicate this attribute to . another entity', 'wpshop') . '</span>'; |
||
942 | } |
||
943 | $input = ' |
||
944 | <tr class="wpshop_' . self::currentPageCode . '_edition_table_line wpshop_' . self::currentPageCode . '_edition_table_line_'.$input_def['name'].'" > |
||
945 | <td class="wpshop_' . self::currentPageCode . '_edition_table_cell wpshop_' . self::currentPageCode . '_edition_table_field_label wpshop_' . self::currentPageCode . '_edition_table_field_label_'.$input_def['name'].'" ><label for="'.$input_def_id.'" >' . __($input_def['label'], 'wpshop') . '</label></td> |
||
946 | <td class="wpshop_' . self::currentPageCode . '_edition_table_cell wpshop_' . self::currentPageCode . '_edition_table_field_input wpshop_' . self::currentPageCode . '_edition_table_field_input_'.$input_def['name'].'" >' . $the_input . '</td> |
||
947 | </tr>'; |
||
948 | if ( (substr($input_def['label'], 0, 3) == 'is_') || (substr($input_def['label'], 0, 1) == '_') || in_array($input_def['label'], unserialize( WPSHOP_ATTRIBUTE_DEF_COLUMN_INTO_OPTIONS )) ) |
||
949 | $the_form_option_content_list[$input_def['label']] = $input; |
||
950 | else { |
||
951 | $the_form_general_content .= $input; |
||
952 | if ( ($input_def['label'] == 'frontend_input') && !is_object($editedItem) ) { |
||
953 | |||
954 | $the_input = wpshop_attributes_set::get_attribute_set_complete_list($current_entity_id, self::getDbTable(), self::currentPageCode); |
||
955 | |||
956 | $input = ' |
||
957 | <tr class="wpshop_' . self::currentPageCode . '_edition_table_line wpshop_' . self::currentPageCode . '_edition_table_line_set_section" > |
||
958 | <td class="wpshop_' . self::currentPageCode . '_edition_table_cell wpshop_' . self::currentPageCode . '_edition_table_field_label wpshop_' . self::currentPageCode . '_edition_table_field_label_set_section" ><label for="'.self::currentPageCode.'_set_section" >' . __('Affect this new attribute to the set section', 'wpshop') . '</label></td> |
||
959 | <td class="wpshop_' . self::currentPageCode . '_edition_table_cell wpshop_' . self::currentPageCode . '_edition_table_field_input wpshop_' . self::currentPageCode . '_edition_table_field_input_set_section" >' . $the_input . '</td> |
||
960 | </tr>'; |
||
961 | $the_form_general_content .= $input; |
||
962 | } |
||
963 | } |
||
964 | } |
||
965 | else{ |
||
966 | $the_form_content_hidden .= ' |
||
967 | ' . $the_input; |
||
968 | } |
||
969 | } |
||
970 | } |
||
971 | |||
972 | |||
973 | |||
974 | |||
975 | |||
976 | $section_legend = ''; |
||
977 | $section_page_code = self::currentPageCode; |
||
978 | $section_content = $the_form_general_content; |
||
979 | |||
980 | ob_start(); |
||
981 | include(WPSHOP_TEMPLATES_DIR.'admin/admin_box_section.tpl.php'); |
||
982 | $the_form_general_content = ob_get_contents(); |
||
983 | ob_end_clean(); |
||
984 | |||
985 | /** It is attribute TVA, add a button to calcilate price in mass **/ |
||
986 | if ( !empty($editedItem) && !empty($editedItem->code) && $editedItem->code == 'tx_tva' ) { |
||
987 | $the_form_general_content .= '<input type="button" data-nonce="' . wp_create_nonce( 'wps_update_products_prices' ) . '" id="wps_update_price_infos" value="' .__('Update all products price', 'wpshop').'" /> <img src="' .WPSHOP_LOADING_ICON. '" alt="" id="update_products_loader" /> <br/>'; |
||
988 | $the_form_general_content .= __('If you have updated your VAT rates, save it and update your products price after', 'wpshop' ); |
||
989 | } |
||
990 | if (!empty($the_form_option_content_list)) { |
||
991 | $the_form_option_content_section=''; |
||
992 | foreach ($attribute_options_group as $group_name => $group_content) { |
||
993 | $section_content = ''; |
||
994 | foreach ($group_content as $group_code) { |
||
995 | if (array_key_exists($group_code, $the_form_option_content_list)) { |
||
996 | $section_content .= $the_form_option_content_list[$group_code]; |
||
997 | unset($the_form_option_content_list[$group_code]); |
||
998 | } |
||
999 | } |
||
1000 | $section_legend = __($group_name,'wpshop'); |
||
1001 | $section_page_code = self::currentPageCode; |
||
1002 | |||
1003 | ob_start(); |
||
1004 | include(WPSHOP_TEMPLATES_DIR.'admin/admin_box_section.tpl.php'); |
||
1005 | $the_form_option_content_section .= ob_get_contents(); |
||
1006 | ob_end_clean(); |
||
1007 | } |
||
1008 | |||
1009 | /* Check there are other attributes to display not in defined group */ |
||
1010 | if (!empty($the_form_option_content_list)) { |
||
1011 | $section_legend = __('General options','wpshop'); |
||
1012 | $section_content = implode('', $the_form_option_content_list); |
||
1013 | $section_page_code = self::currentPageCode; |
||
1014 | |||
1015 | ob_start(); |
||
1016 | include(WPSHOP_TEMPLATES_DIR.'admin/admin_box_section.tpl.php'); |
||
1017 | $the_form_option_content = ob_get_contents(); |
||
1018 | ob_end_clean(); |
||
1019 | |||
1020 | $the_form_option_content .= $the_form_option_content_section; |
||
1021 | } |
||
1022 | |||
1023 | } |
||
1024 | |||
1025 | /* Default content for the current page */ |
||
1026 | $bloc_list[self::currentPageCode]['main_info']['title']=__('Main informations', 'wpshop'); |
||
1027 | $bloc_list[self::currentPageCode]['main_info']['content'] = $the_form_general_content; |
||
1028 | |||
1029 | $bloc_list[self::currentPageCode]['options']['title']=__('Options', 'wpshop'); |
||
1030 | $bloc_list[self::currentPageCode]['options']['content']=$the_form_option_content; |
||
1031 | |||
1032 | $action = !empty( $_REQUEST['action'] ) ? sanitize_text_field( $_REQUEST['action' ] ) : ''; |
||
1033 | $the_form = ' |
||
1034 | <form name="' . self::getDbTable() . '_form" id="' . self::getDbTable() . '_form" method="post" action="#" > |
||
1035 | ' . wpshop_form::form_input(self::getDbTable() . '_action', self::getDbTable() . '_action', (isset($action) && ($action != '') ? sanitize_text_field($action) : 'save') , 'hidden') . ' |
||
1036 | ' . wpshop_form::form_input(self::currentPageCode . '_form_has_modification', self::currentPageCode . '_form_has_modification', 'no' , 'hidden') . $the_form_content_hidden . wpshop_display::custom_page_output_builder($bloc_list, WPSHOP_ATTRIBUTE_EDITION_PAGE_LAYOUT) . ' |
||
1037 | </form> |
||
1038 | <div title="' . __('Change data type for selected attribute', 'wpshop') . '" id="wpshop_dialog_change_select_data_type" ><div id="wpshop_dialog_change_select_data_type_container" ></div></div>'; |
||
1039 | $input_def['possible_value'] = wpshop_entities::get_entities_list(); |
||
1040 | unset($input_def['possible_value'][$current_entity_id]); |
||
1041 | $input_def['valueToPut'] = 'index'; |
||
1042 | $input_def['type'] = 'select'; |
||
1043 | $input_def['name'] = 'wpshop_entity_to_duplicate_to'; |
||
1044 | $input_def['id'] = 'wpshop_entity_to_duplicate_to'; |
||
1045 | $the_form .= ' |
||
1046 | <div title="' . __('Duplicate attribute to another entity', 'wpshop') . '" id="wpshop_dialog_duplicate_attribute" > |
||
1047 | ' . __('Choose an entity to copy the selected attribute to', 'wpshop') . ' |
||
1048 | ' . wpshop_form::check_input_type($input_def) . ' |
||
1049 | </div>'; |
||
1050 | |||
1051 | $the_form .= ' |
||
1052 | <script type="text/javascript" > |
||
1053 | wpshop(document).ready(function(){ |
||
1054 | wpshopMainInterface("'.self::getDbTable().'", "' . __('Are you sure you want to quit this page? You will loose all current modification', 'wpshop') . '", "' . __('Are you sure you want to delete this attributes group?', 'wpshop') . '"); |
||
1055 | |||
1056 | jQuery("#wpshop_dialog_duplicate_attribute").dialog({ |
||
1057 | autoOpen: false, |
||
1058 | width: 500, |
||
1059 | height: 100, |
||
1060 | modal: true, |
||
1061 | dialogClass: "wpshop_uidialog_box", |
||
1062 | resizable: false, |
||
1063 | buttons:{ |
||
1064 | "'.__('Duplicate', 'wpshop').'": function(){ |
||
1065 | var data = { |
||
1066 | action: "wpshop_duplicate_attribute", |
||
1067 | wpshop_ajax_nonce: "' . wp_create_nonce("wpshop_duplicate_attribute") . '", |
||
1068 | attribute_id: jQuery("#wpshop_attributes_edition_table_field_id_id").val(), |
||
1069 | entity: jQuery("#wpshop_entity_to_duplicate_to").val() |
||
1070 | }; |
||
1071 | jQuery.post(ajaxurl, data, function(response) { |
||
1072 | if (response[0]) { |
||
1073 | jQuery("#wpshop_dialog_duplicate_attribute").append(response[1]); |
||
1074 | } |
||
1075 | else { |
||
1076 | alert(response[1]); |
||
1077 | } |
||
1078 | }, "json"); |
||
1079 | }, |
||
1080 | "'.__('Cancel', 'wpshop').'": function(){ |
||
1081 | jQuery(this).dialog("close"); |
||
1082 | jQuery(".wpshop_duplicate_attribute_result").remove(); |
||
1083 | } |
||
1084 | } |
||
1085 | }); |
||
1086 | jQuery(".wpshop_duplicate_attribute").live("click", function(){ |
||
1087 | jQuery("#wpshop_dialog_duplicate_attribute").dialog("open"); |
||
1088 | }); |
||
1089 | |||
1090 | jQuery("#wpshop_dialog_change_select_data_type").dialog({ |
||
1091 | autoOpen: false, |
||
1092 | width: 800, |
||
1093 | height: 200, |
||
1094 | modal: true, |
||
1095 | dialogClass: "wpshop_uidialog_box", |
||
1096 | resizable: false, |
||
1097 | buttons:{ |
||
1098 | "'.__('Change type', 'wpshop').'": function(){ |
||
1099 | var delete_entity = false; |
||
1100 | if(jQuery("#delete_entity").is(":checked")){ |
||
1101 | var delete_entity = true; |
||
1102 | } |
||
1103 | var delete_items_of_entity = false; |
||
1104 | if(jQuery("#delete_items_of_entity").is(":checked")){ |
||
1105 | var delete_items_of_entity = true; |
||
1106 | } |
||
1107 | var data = { |
||
1108 | action: "attribute_select_data_type_change", |
||
1109 | wpshop_ajax_nonce: "' . wp_create_nonce("wpshop_attribute_change_select_data_type_change") . '", |
||
1110 | attribute_id: jQuery("#wpshop_attributes_edition_table_field_id_id").val(), |
||
1111 | internal_data: jQuery("#internal_data").val(), |
||
1112 | data_type: jQuery("#wpshop_attribute_change_data_type_new_type").val(), |
||
1113 | delete_entity: delete_entity, |
||
1114 | delete_items_of_entity: delete_items_of_entity |
||
1115 | }; |
||
1116 | jQuery.post(ajaxurl, data, function(response) { |
||
1117 | jQuery(".wpshop_attributes_edition_table_field_input_default_value").html( response ); |
||
1118 | jQuery("#wpshop_dialog_change_select_data_type").dialog("close"); |
||
1119 | }, "json"); |
||
1120 | }, |
||
1121 | "'.__('Cancel', 'wpshop').'": function(){ |
||
1122 | jQuery(this).dialog("close"); |
||
1123 | } |
||
1124 | } |
||
1125 | }); |
||
1126 | |||
1127 | jQuery(".wpshop_attribute_change_select_data_type_deletion_input").live("click",function() { |
||
1128 | var display = false; |
||
1129 | if (jQuery(".wpshop_attribute_change_select_data_type_deletion_input_item").is(":checked") ) { |
||
1130 | display = true; |
||
1131 | } |
||
1132 | if (jQuery(".wpshop_attribute_change_select_data_type_deletion_input_entity").is(":checked") ) { |
||
1133 | display = true; |
||
1134 | } |
||
1135 | if (display) { |
||
1136 | jQuery(".wpshop_attribute_change_data_type_alert").show(); |
||
1137 | } |
||
1138 | else { |
||
1139 | jQuery(".wpshop_attribute_change_data_type_alert").hide(); |
||
1140 | } |
||
1141 | }); |
||
1142 | |||
1143 | jQuery(".wpshop_change_select_data_type").live("click",function(){ |
||
1144 | jQuery("#wpshop_dialog_change_select_data_type_container").html(jQuery("#wpshopLoadingPicture").html()); |
||
1145 | jQuery("#wpshop_dialog_change_select_data_type").dialog("open"); |
||
1146 | |||
1147 | var data = { |
||
1148 | action: "attribute_select_data_type", |
||
1149 | current_attribute: jQuery("#wpshop_attributes_edition_table_field_id_id").val(), |
||
1150 | wpshop_ajax_nonce: "' . wp_create_nonce("wpshop_attribute_change_select_data_type") . '" |
||
1151 | }; |
||
1152 | jQuery.post(ajaxurl, data, function(response) { |
||
1153 | jQuery("#wpshop_dialog_change_select_data_type_container").html( response ); |
||
1154 | }, "json"); |
||
1155 | |||
1156 | }); |
||
1157 | jQuery("#wpshop_attributes_edition_table_field_id__unit_group_id").change(function(){ |
||
1158 | change_unit_list(); |
||
1159 | });'; |
||
1160 | |||
1161 | if ( !is_object($editedItem) ) { |
||
1162 | $the_form .= ' |
||
1163 | jQuery("#wpshop_attributes_edition_table_field_id_frontend_input").change(function(){ |
||
1164 | jQuery(".wpshop_attributes_edition_table_field_input_default_value").html(jQuery("#wpshopLoadingPicture").html()); |
||
1165 | |||
1166 | var data = { |
||
1167 | action: "attribute_output_type", |
||
1168 | current_type: jQuery(this).val(), |
||
1169 | wpshop_ajax_nonce: "' . wp_create_nonce("wpshop_attribute_output_type_selection") . '" |
||
1170 | }; |
||
1171 | jQuery.post(ajaxurl, data, function(response) { |
||
1172 | jQuery(".wpshop_attributes_edition_table_field_input_default_value").html((response[0])); |
||
1173 | jQuery(".wpshop_attributes_edition_table_field_label_default_value label").html((response[1])); |
||
1174 | }, "json"); |
||
1175 | |||
1176 | // var data = { |
||
1177 | // action: "attribute_frontend_input_type", |
||
1178 | // current_type: jQuery(this).val(), |
||
1179 | // wpshop_ajax_nonce: "' . wp_create_nonce("wpshop_attribute_frontend_input_type") . '" |
||
1180 | // }; |
||
1181 | // jQuery.getJSON(ajaxurl, data, function(response) { |
||
1182 | // jQuery("#wpshop_attributes_edition_table_field_id_frontend_input").html(response); |
||
1183 | // }); |
||
1184 | |||
1185 | });'; |
||
1186 | } |
||
1187 | |||
1188 | $the_form .= ' |
||
1189 | jQuery("#wpshop_attributes_edition_table_field_id_entity_id").change(function(){ |
||
1190 | jQuery(".wpshop_attributes_edition_table_field_input_set_section").html(jQuery("#wpshopLoadingPicture").html()); |
||
1191 | |||
1192 | var data = { |
||
1193 | action: "attribute_entity_set_selection", |
||
1194 | current_entity_id: jQuery(this).val(), |
||
1195 | wpshop_ajax_nonce: "' . wp_create_nonce("wpshop_attribute_entity_set_selection") . '" |
||
1196 | }; |
||
1197 | jQuery.post(ajaxurl, data, function(response) { |
||
1198 | jQuery(".wpshop_attributes_edition_table_field_input_set_section").html( response ); |
||
1199 | }, "json"); |
||
1200 | }); |
||
1201 | |||
1202 | |||
1203 | jQuery("#wpshop_attributes_edition_table_field_id_is_used_for_variation").click(function(){ |
||
1204 | if ( jQuery(this).is(":checked") ) { |
||
1205 | jQuery("#wpshop_attributes_edition_table_field_id_is_used_in_variation").prop("checked", false); |
||
1206 | jQuery("#wpshop_attributes_edition_table_field_id_is_used_in_variation").prop("disabled", true); |
||
1207 | } |
||
1208 | else { |
||
1209 | jQuery("#wpshop_attributes_edition_table_field_id_is_used_in_variation").prop("disabled", false); |
||
1210 | } |
||
1211 | }); |
||
1212 | }); |
||
1213 | function change_unit_list(){ |
||
1214 | var data = { |
||
1215 | action: "load_attribute_unit_list", |
||
1216 | wpshop_ajax_nonce: jQuery("#input_wpshop_load_attribute_unit_list").val(), |
||
1217 | current_group: jQuery("#wpshop_attributes_edition_table_field_id__unit_group_id").val(), |
||
1218 | selected_list:"unit" |
||
1219 | }; |
||
1220 | //Response, update the combo box |
||
1221 | jQuery.post(ajaxurl, data, function(response) { |
||
1222 | if ( response[0] ) { |
||
1223 | jQuery("#wpshop_attributes_edition_table_field_id__default_unit").html(response[1]); |
||
1224 | } |
||
1225 | else { |
||
1226 | alert( response[1] ); |
||
1227 | } |
||
1228 | }, "json"); |
||
1229 | |||
1230 | } |
||
1231 | </script>'; |
||
1232 | |||
1233 | |||
1234 | |||
1235 | |||
1236 | |||
1237 | return $the_form; |
||
1238 | } |
||
1239 | /** |
||
1240 | * Return the different button to save the item currently being added or edited |
||
1241 | * |
||
1242 | * @return string $currentPageButton The html output code with the different button to add to the interface |
||
1243 | */ |
||
1244 | function getPageFormButton($element_id = 0){ |
||
1264 | |||
1265 | /** |
||
1266 | * Get the existing attribute list into database |
||
1267 | * |
||
1268 | * @param integer $element_id optionnal The attribute identifier we want to get. If not specify the entire list will be returned |
||
1269 | * @param string $element_status optionnal The status of element to get into database. Default is set to valid element |
||
1270 | * @param mixed $field_to_search optionnal The field we want to check the row identifier into. Default is to set id |
||
1271 | * |
||
1272 | * @return object $element_list A wordpress database object containing the attribute list |
||
1273 | */ |
||
1274 | public static function getElement($element_id = '', $element_status = "'valid', 'moderated', 'notused'", $field_to_search = 'id', $list = false){ |
||
1312 | |||
1313 | /** |
||
1314 | * Save the different value for attribute of a given entity type and entity |
||
1315 | * |
||
1316 | * @param array $attributeToSet The list of attribute with each value to set like this : ['integer']['tx_tva'] = 10 |
||
1317 | * @param integer $entityTypeId The entity type identifier (products/categories/...) |
||
1318 | * @param integer $entityId The entity identifier we want to save attribute for (The specific product/category/...) |
||
1319 | * @param string $language The language to set the value for into database |
||
1320 | * |
||
1321 | */ |
||
1322 | public static function saveAttributeForEntity($attributeToSet, $entityTypeId, $entityId, $language = WPSHOP_CURRENT_LOCALE, $from = '') { |
||
1459 | |||
1460 | /** |
||
1461 | * Return the value for a given attribute of a given entity type and a given entity |
||
1462 | * |
||
1463 | * @param string $attributeType The extension of the database table to get the attribute value in |
||
1464 | * @param integer $attributeId The attribute identifier we want to get the value for |
||
1465 | * @param integer $entityTypeId The entity type identifier we want to get the attribute value for (example: product = 1) |
||
1466 | * @param integer $entityId The entity id we want the attribute value for |
||
1467 | * |
||
1468 | * @return object $attributeValue A wordpress database object containing the value of the attribute for the selected entity |
||
1469 | */ |
||
1470 | public static function getAttributeValueForEntityInSet($attributeType, $attributeId, $entityTypeId, $entityId, $atribute_params = array()) { |
||
1522 | |||
1523 | /** |
||
1524 | * Get the existing element list into database |
||
1525 | * |
||
1526 | * @param integer $elementId optionnal The element identifier we want to get. If not specify the entire list will be returned |
||
1527 | * @param string $elementStatus optionnal The status of element to get into database. Default is set to valid element |
||
1528 | * |
||
1529 | * @return object $elements A wordpress database object containing the element list |
||
1530 | */ |
||
1531 | public static function getElementWithAttributeAndValue($entityId, $elementId, $language, $keyForArray = '', $outputType = '') { |
||
1586 | |||
1587 | public static function get_attribute_list_for_item($entityId, $elementId, $language = WPSHOP_CURRENT_LOCALE, $defined_entity_type = '', $ead_status = "'valid', 'deleted'") { |
||
1629 | |||
1630 | /** |
||
1631 | * Check if an attribute or an attribute set section have to be displayed on the product output un frontend |
||
1632 | * |
||
1633 | * @param string $attribute_main_config The main configuration for display for the attribute |
||
1634 | * @param array $attribute_custom_config The custom config defined into product page |
||
1635 | * @param string $attribute_or_set Define if we check for an attribute or for an attribute set section |
||
1636 | * @param string $attribute_code The code of element to check the display for |
||
1637 | * @param string $output_type The current output type |
||
1638 | * |
||
1639 | * @return boolean The result to know if the element has to be displayed on frontend |
||
1640 | */ |
||
1641 | public static function check_attribute_display( $attribute_main_config, $attribute_custom_config, $attribute_or_set, $attribute_code, $output_type) { |
||
1664 | |||
1665 | /** |
||
1666 | * Traduit le shortcode et affiche la valeur d'un attribut donn� |
||
1667 | * @param array $atts : tableau de param�tre du shortcode |
||
1668 | * @return mixed |
||
1669 | **/ |
||
1670 | public static function wpshop_att_val_func($atts) { |
||
1724 | /** |
||
1725 | * Build the output for an attribute field |
||
1726 | * |
||
1727 | * @param object $attribute The complete definition for an attribute |
||
1728 | * @param string $attribute_value Optionnal The current value for the attribute |
||
1729 | * @param array $specific_argument Optionnal The different parameters used for filter output |
||
1730 | * @return array The definition for the field used to display an attribute |
||
1731 | */ |
||
1732 | public static function get_attribute_field_definition( $attribute, $attribute_value = '', $specific_argument = array() ) { |
||
1954 | |||
1955 | /** |
||
1956 | * |
||
1957 | * @param array $attribute_list |
||
1958 | * @param string $output_from |
||
1959 | * @return string The output for |
||
1960 | */ |
||
1961 | public static function display_attribute( $attribute_code, $output_from = 'admin', $output_specs = array() ) { |
||
2019 | |||
2020 | /** |
||
2021 | * Output the different tabs into an entity sheet |
||
2022 | * |
||
2023 | * @param string $element_code The current element type represented by the code |
||
2024 | * @param integer $element_id The current element identifier to dislay tabs for |
||
2025 | * @param array $element_definition An array with the different configuration for the current element |
||
2026 | * |
||
2027 | * @return string The html code to output directly tabs |
||
2028 | */ |
||
2029 | public static function attribute_of_entity_to_tab( $element_code, $element_id, $element_definition ) { |
||
2162 | |||
2163 | /** |
||
2164 | * Display value for a given attribute |
||
2165 | * |
||
2166 | * @param unknown_type $attributeDefinition |
||
2167 | * @return multitype:Ambigous <unknown, string> Ambigous <string, string> Ambigous <> |
||
2168 | */ |
||
2169 | public static function wps_attribute_values_display( $attributeDefinition ) { |
||
2212 | |||
2213 | /** |
||
2214 | * Manage display for the output when user uses a shortcode for attributes display |
||
2215 | * @param array $shorcode_args The list of argument passed through the shortcode |
||
2216 | */ |
||
2217 | function wpshop_attributes_shortcode( $shorcode_args ) { |
||
2229 | |||
2230 | /** |
||
2231 | * |
||
2232 | * @param unknown_type $attributeSetId |
||
2233 | * @param unknown_type $currentPageCode |
||
2234 | * @param unknown_type $itemToEdit |
||
2235 | * @param unknown_type $outputType |
||
2236 | * @return Ambigous <multitype:, string> |
||
2237 | */ |
||
2238 | public static function entities_attribute_box($attributeSetId, $currentPageCode, $itemToEdit, $outputType = 'box') { |
||
2378 | |||
2379 | /** |
||
2380 | * Generate the list of element to put into a combobox |
||
2381 | * |
||
2382 | * @param object $attribute Complete definition of attribute to generate output for |
||
2383 | * @return array The output for the combobox |
||
2384 | */ |
||
2385 | public static function get_select_output($attribute, $provenance = array()) { |
||
2464 | |||
2465 | public static function get_affected_value_for_list( $attribute_code, $element_id, $attribute_data_type ) { |
||
2497 | |||
2498 | public static function get_attribute_option_output($item, $attr_code, $attr_option, $additionnal_params = '') { |
||
2514 | |||
2515 | public static function get_attribute_option_fields($postid, $code) { |
||
2538 | |||
2539 | /** |
||
2540 | * Return content informations about a given attribute |
||
2541 | * |
||
2542 | * @param string $attribute_code The code of attribute to get (Not the id because if another system is using eav model it could have some conflict) |
||
2543 | * @param integer $entity_id The current entity we want to have the attribute value for |
||
2544 | * @param string $entity_type The current entity type code we want to have the attribute value for |
||
2545 | * |
||
2546 | * @return object $attribute_value_content The attribute content |
||
2547 | */ |
||
2548 | public static function get_attribute_value_content($attribute_code, $entity_id, $entity_type) { |
||
2558 | |||
2559 | /** |
||
2560 | * Define a function allowing to manage default value for datetime attributes |
||
2561 | * |
||
2562 | * @param mixed $value |
||
2563 | * @return string The complete interface allowing to manage datetime attribute field |
||
2564 | */ |
||
2565 | public static function attribute_type_date_config( $value ) { |
||
2640 | |||
2641 | /** |
||
2642 | * Met a jour un ou plusieurs attributes concernant un produit |
||
2643 | * @param integer $entityId Id du produit |
||
2644 | * @param array $values Valeurs d'attributs |
||
2645 | * @return array |
||
2646 | */ |
||
2647 | public static function setAttributesValuesForItem($entityId, $values=array(), $defaultValueForOthers=false, $from = 'webservice') { |
||
2701 | |||
2702 | /** |
||
2703 | * Recupere les informations concernant une option donnees dans la liste d'un attribut de type liste deroulante |
||
2704 | * |
||
2705 | * @param integer $option_id L'identifiant de l'option dont on veut recuperer les informations |
||
2706 | * @param string $field optionnal Le champs correspondant a l'information que l'on souhaite recuperer |
||
2707 | * @return string $info L'information que l'on souhaite |
||
2708 | */ |
||
2709 | public static function get_attribute_type_select_option_info($option_id, $field = 'label', $attribute_data_type = 'custom', $only_value = false) { |
||
2751 | |||
2752 | /** |
||
2753 | * Get the list of existing element for list type attribute |
||
2754 | * |
||
2755 | * @param integer $attribute_id |
||
2756 | * @return object A wordpress database object with the list of existing element |
||
2757 | */ |
||
2758 | function get_select_option_list_($attribute_id) { |
||
2774 | |||
2775 | /** |
||
2776 | * Recupere la liste des options pour les attributs de type liste deroulante suivant le type de donnees choisi (personnalise ou interne a wordpress) |
||
2777 | * |
||
2778 | * @param integer $attribute_id L'identifiant de l'attribut pour lequel on souhaite recuperer la liste des options |
||
2779 | * @param string $data_type optionnal Le type de donnees choisi pour cet attribut (custom | internal) |
||
2780 | * @return string Le resultat sous forme de code html pour la liste des options |
||
2781 | */ |
||
2782 | function get_select_options_list($attribute_id, $data_type='custom') { |
||
2958 | |||
2959 | /** |
||
2960 | * Get the attribute list affected to an entity in order to generate a shortcode |
||
2961 | * |
||
2962 | * @param integer $entity_id The entity identifier for retrieving attribute list |
||
2963 | * @param string $list_for The type of shortcode we want to generate |
||
2964 | * @param string $current_post_type The post type of current edited element |
||
2965 | * |
||
2966 | * @return string The html output |
||
2967 | */ |
||
2968 | public static function get_attribute_list($entity_id = 0, $list_for = 'product_by_attribute', $current_post_type = '') { |
||
3051 | |||
3052 | /** |
||
3053 | * Retrieve the attribute list into an attribute set section from a given attribute code |
||
3054 | * |
||
3055 | * @param string $attribute_code The attribute code that allows to define the attribute set section to get attribute list for |
||
3056 | * |
||
3057 | * @return object The attribute list as a wordpress database object |
||
3058 | */ |
||
3059 | function get_attribute_list_in_same_set_section( $attribute_code ) { |
||
3080 | |||
3081 | /** |
||
3082 | * Get all attribute available for current |
||
3083 | * @param unknown_type $current_entity_id |
||
3084 | * @return Ambigous <multitype:, multitype:NULL > |
||
3085 | */ |
||
3086 | public static function get_variation_available_attribute( $current_entity_id ) { |
||
3121 | |||
3122 | /** |
||
3123 | * |
||
3124 | * @param integer $current_entity_id The current element edited |
||
3125 | * @return Ambigous <string, string, mixed> |
||
3126 | */ |
||
3127 | public static function get_variation_available_attribute_display( $current_entity_id, $variation_type = 'multiple' ) { |
||
3173 | |||
3174 | /** |
||
3175 | * Get attribute defined as product option specific attribute |
||
3176 | * |
||
3177 | * @param array $variations_attribute_parameters Allows to give some parameters for customize list |
||
3178 | * @return string The output for all specific attribute in each product with option |
||
3179 | */ |
||
3180 | public static function get_variation_attribute( $variations_attribute_parameters ) { |
||
3215 | |||
3216 | public static function get_attribute_user_defined( $use_defined_parameters, $status = "'publish'" ) { |
||
3235 | |||
3236 | /** |
||
3237 | * Define the different field available for bulk edition for entities. Attributes to display are defined by checking box in attribute option |
||
3238 | * |
||
3239 | * @param string $column_name The column name for output type definition |
||
3240 | * @param string $post_type The current |
||
3241 | * |
||
3242 | */ |
||
3243 | function quick_edit( $column_name, $entity ) { |
||
3260 | |||
3261 | /** |
||
3262 | * Define the different field available for bulk edition for entities. Attributes to display are defined by checking box in attribute option |
||
3263 | * |
||
3264 | * @param string $column_name The column name for output type definition |
||
3265 | * @param string $post_type The current |
||
3266 | * |
||
3267 | */ |
||
3268 | public static function bulk_edit( $column_name, $entity ) { |
||
3286 | |||
3287 | } |
||
3288 | |||
3290 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.