/**
     * Build the output for an attribute field
     *
     * @param object $attribute The complete definition for an attribute
     * @param string $attribute_value Optionnal The current value for the attribute
     * @param array $specific_argument Optionnal The different parameters used for filter output
     * @return array The definition for the field used to display an attribute
     */
    public static function get_attribute_field_definition($attribute, $attribute_value = '', $specific_argument = array())
    {
        global $wpdb;
        $wpshop_price_attributes = unserialize(WPSHOP_ATTRIBUTE_PRICES);
        $wpshop_weight_attributes = unserialize(WPSHOP_ATTRIBUTE_WEIGHT);
        $input_def = array();
        $input_def['option'] = $input_def['field_container_class'] = '';
        $attributeInputDomain = !empty($specific_argument['field_custom_name_prefix']) || !empty($specific_argument['field_custom_name_prefix']) && $specific_argument['field_custom_name_prefix'] == 'empty' ? $specific_argument['field_custom_name_prefix'] : (!empty($specific_argument['page_code']) ? $specific_argument['page_code'] . '_' : '') . 'attribute[' . $attribute->data_type . ']';
        $input_def['input_domain'] = $attributeInputDomain;
        $input_def['id'] = (!empty($specific_argument) && !empty($specific_argument['field_id']) ? $specific_argument['field_id'] . '_' : '') . 'attribute_' . $attribute->id;
        $input_def['intrinsec'] = $attribute->is_intrinsic;
        $input_def['name'] = $attribute->code;
        $input_def['type'] = wpshop_tools::defineFieldType($attribute->data_type, $attribute->frontend_input, $attribute->frontend_verification);
        $input_def['label'] = $attribute->frontend_label;
        $attribute_default_value = stripslashes($attribute->default_value);
        $input_def['value'] = $attribute_default_value;
        $input_def['default_value'] = $attribute_default_value;
        $input_def['is_unique'] = $attribute->is_unique;
        $input_def['_need_verification'] = $attribute->_need_verification;
        $input_def['required'] = $attribute->is_required;
        $input_def['frontend_verification'] = $attribute->frontend_verification;
        $input_def['data_type'] = $attribute->data_type;
        $input_def['data_type_to_use'] = $attribute->data_type_to_use;
        $input_def['backend_type'] = $attribute->backend_input;
        $input_def['frontend_type'] = $attribute->frontend_input;
        $input_def['is_used_in_quick_add_form'] = $attribute->is_used_in_quick_add_form;
        if (!empty($attribute_value) && !is_object($attribute_value)) {
            $input_def['value'] = $attribute_value;
        } else {
            if (!empty($attribute_value->value)) {
                $input_def['value'] = stripslashes($attribute_value->value);
            } else {
                if (!empty($specific_argument['element_identifier']) && empty($attribute_value) && get_post_status($specific_argument['element_identifier']) != 'auto-draft') {
                    $input_def['value'] = '';
                }
            }
        }
        $input_def['options'] = '';
        $input_more_class = !empty($specific_argument['input_class']) ? $specific_argument['input_class'] : '';
        if ($attribute->data_type == 'datetime') {
            $date_config = unserialize($attribute->default_value);
            if (($date_config['default_value'] == '' || $date_config['default_value'] == 'date_of_current_day') && $date_config['default_value'] == 'date_of_current_day') {
                $input_def['value'] = date('Y-m-d');
            } else {
                /**	Modification due to a message on eoxia forum: http://www.eoxia.com/forums/topic/bug-attribut-de-type-date-dans-fiche-produit-admin/	*/
                $input_def['value'] = !empty($attribute_value->value) && is_string($attribute_value->value) ? str_replace(" 00:00:00", "", $attribute_value->value) : (!empty($attribute_value) && is_string($attribute_value) ? str_replace(" 00:00:00", "", $attribute_value) : '');
            }
            $input_more_class .= ' wpshop_input_datetime ';
            $field_script = '<script type="text/javascript" >
	jQuery(document).ready(function(){
		wpshop("#' . $input_def['id'] . '").datepicker();
		wpshop("#' . $input_def['id'] . '").datepicker("option", "dateFormat", "yy-mm-dd");
		wpshop("#' . $input_def['id'] . '").datepicker("option", "changeMonth", true);
		wpshop("#' . $input_def['id'] . '").datepicker("option", "changeYear", true);
		wpshop("#' . $input_def['id'] . '").datepicker("option", "yearRange", "-90:+10");
		wpshop("#' . $input_def['id'] . '").datepicker("option", "navigationAsDateFormat", true);
		wpshop("#' . $input_def['id'] . '").val("' . str_replace(" 00:00:00", "", $input_def['value']) . '");';
            if (!empty($date_config['field_options']['attribute_type_date_options_available_date_past_futur'])) {
                if (!empty($date_config['field_options']['attribute_type_date_options_available_date_past_futur']['minDate'][0])) {
                    $field_script .= '
		wpshop("#' . $input_def['id'] . '").datepicker("option", "minDate", "' . $date_config['field_options']['attribute_type_date_options_available_date_past_futur']['minDate'][0] . '");';
                }
                if (!empty($date_config['field_options']['attribute_type_date_options_available_date_past_futur']['maxDate'][0])) {
                    $field_script .= '
		wpshop("#' . $input_def['id'] . '").datepicker("option", "maxDate", "' . $date_config['field_options']['attribute_type_date_options_available_date_past_futur']['maxDate'][0] . '");';
                }
            }
            $script_options = $script_options_params = array();
            if (!empty($date_config['field_options']['attribute_type_date_options_day_to_show'])) {
                $day_to_show_list = '    ';
                foreach ($date_config['field_options']['attribute_type_date_options_day_to_show'] as $day_to_show) {
                    $day_to_show_list .= '(date.getDay() == ' . $day_to_show . ') || ';
                }
                $script_options[] = '( ' . substr($day_to_show_list, 0, -4) . ' )';
            }
            if (!empty($date_config['field_options']['attribute_type_date_options_available_date_type'][0])) {
                if (!empty($date_config['field_options']['attribute_type_date_options_available_date'])) {
                    $available_date = ' ';
                    foreach ($date_config['field_options']['attribute_type_date_options_available_date'] as $avalaible_date_list) {
                        if (!empty($avalaible_date_list)) {
                            $available_date .= '"' . $avalaible_date_list . '",';
                        }
                    }
                    $script_options_params[] = 'var dates = [' . substr($available_date, 0, -1) . ']';
                    $script_options[] = '(jQuery.inArray(dmy, dates) ' . ($date_config['field_options']['attribute_type_date_options_available_date_type'][0] == 'available' ? '!=' : '==') . ' -1)';
                }
            }
            if (!empty($script_options)) {
                $field_script .= '
		wpshop("#' . $input_def['id'] . '").datepicker("option", "beforeShowDay", function(date){
			' . implode(' ', $script_options_params) . ';
			var Y = date.getFullYear();
			var M = (date.getMonth()+1);
			if( M < 10) {
				M = "0" + M;
			}
			var D = date.getDate();
			if( D < 10) {
				D = "0" + D;
			}
			dmy = Y + "-" + M + "-" + D;
			if ( ' . implode(' && ', $script_options) . ' ) {
				return [true, ""];
		  	}
			else {
		   		return [false,""];
		  	}
		});';
            }
            $field_script .= '
	});
</script>';
            $input_def['options'] .= $field_script;
        }
        if (in_array($attribute->backend_input, array('multiple-select', 'select', 'radio', 'checkbox'))) {
            $input_more_class .= !empty($specific_argument['no_chosen']) ? '' : ' chosen_select ';
            $input_def['type'] = !empty($specific_argument['from']) && $specific_argument['from'] == 'frontend' || !is_admin() && empty($specific_argument['from']) ? $attribute->frontend_input : $attribute->backend_input;
            $input_def['valueToPut'] = 'index';
            $select_display = self::get_select_output($attribute, $specific_argument);
            if (empty($input_def['options_label']) && !empty($specific_argument) && (!empty($specific_argument['from']) && $specific_argument['from'] == 'frontend')) {
                $input_def['options_label']['original'] = true;
            }
            $input_def['options'] .= $select_display['more_input'];
            $input_def['possible_value'] = !empty($select_display) && !empty($select_display['possible_value']) ? $select_display['possible_value'] : '';
            if (!is_admin()) {
                $input_def['options'] .= '<input type="hidden" value="' . str_replace("\\", "", $input_def['value']) . '" name="wpshop_product_attribute_' . $attribute->code . '_current_value" id="wpshop_product_attribute_' . $attribute->code . '_current_value" />';
            }
            if (in_array($attribute->backend_input, array('multiple-select', 'checkbox')) && is_admin() && (empty($specific_argument['from']) || $specific_argument['from'] != 'frontend')) {
                $input_def['options'] .= wpshop_display::display_template_element('select_list_multiple_bulk_action', array('CURRENT_ATTRIBUTE_ID' => $input_def['id'], 'CURRENT_ATTRIBUTE_CODE' => $attribute->code), array(), 'admin');
            }
        }
        $input_def['label_pointer'] = 'for="' . $input_def['id'] . '"';
        if ($input_def['type'] == 'radio' || $input_def['type'] == 'checkbox') {
            $input_def['label_pointer'] = '';
        }
        /*
         * Specifc treatment for price attributes
         */
        if (WPSHOP_PRODUCT_PRICE_PILOT == 'HT' && $attribute->code == WPSHOP_PRODUCT_PRICE_TTC) {
            $input_def['option'] .= ' readonly="readonly" ';
            $input_more_class .= ' wpshop_prices_readonly';
        } elseif (WPSHOP_PRODUCT_PRICE_PILOT == 'TTC' && $attribute->code == WPSHOP_PRODUCT_PRICE_HT) {
            $input_def['option'] .= ' readonly="readonly" ';
            $input_more_class .= ' wpshop_prices_readonly';
        }
        if ($attribute->code == WPSHOP_PRODUCT_PRICE_TAX_AMOUNT) {
            $input_def['option'] .= ' readonly="readonly" ';
            $input_more_class .= ' wpshop_prices_readonly';
        }
        $input_def['label'] = str_replace("\\", "", $input_def['label']);
        // 		$input_def['value'] = str_replace("\\", "", $input_def['value']);
        $input_def['option'] .= ' class="wpshop_product_attribute_' . $attribute->code . $input_more_class . ' ' . (is_admin() ? $attribute->backend_css_class : $attribute->frontend_css_class) . (!empty($attribute->frontend_verification) ? ' wps_attr_verification_' . $attribute->frontend_verification : '') . '" ';
        $input_def['title'] = !empty($attribute->frontend_help_message) ? ' title="' . $attribute->frontend_help_message . '" ' : '';
        if ($attribute->is_intrinsic == 'yes' && (!empty($input_def['value']) || $input_def['value'] > 0)) {
            $input_def['option'] .= ' readonly="readonly" ';
        }
        /*
         * Add the unit to the attribute if attribute configuration is set to yes
         */
        if ($attribute->is_requiring_unit == 'yes') {
            if (in_array($attribute->code, $wpshop_price_attributes) || WPSHOP_COST_OF_POSTAGE == $attribute->code) {
                $input_def['options'] .= '&nbsp;<span class="attribute_currency" id="attribute_currency_' . $attribute->id . '" >' . wpshop_tools::wpshop_get_currency() . '</span>';
            } elseif (in_array($attribute->code, $wpshop_weight_attributes)) {
                $weight_defaut_unity_option = get_option('wpshop_shop_default_weight_unity');
                $query = $wpdb->prepare('SELECT name FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id=%d', $weight_defaut_unity_option);
                $unity = $wpdb->get_var($query);
                $input_def['options'] .= '&nbsp;<span class="attribute_weight" id="attribute_weight_' . $attribute->id . '" >' . __($unity, 'wpshop') . '</span>';
            } else {
                unset($unit_input_def);
                $unit_input_def['possible_value'] = wpshop_attributes_unit::get_unit_list_for_group($attribute->_unit_group_id);
                $unit_input_def['type'] = 'select';
                $unit_input_def['option'] = ' class="wpshop_attribute_unit_input chosen_select" ';
                $unit_input_def['id'] = (!empty($specific_argument['page_code']) ? $specific_argument['page_code'] : null) . '_' . (!empty($specific_argument['element_identifier']) ? $specific_argument['element_identifier'] : null) . '_unit_attribute_' . $attribute->id;
                $unit_input_def['name'] = $attribute->code;
                $unit_input_def['value'] = !empty($attribute_value->unit_id) ? $attribute_value->unit_id : '';
                if ($unit_input_def['value'] == '') {
                    if ($attribute->_default_unit > 0) {
                        $unit_input_def['value'] = $attribute->_default_unit;
                    } else {
                        $unit_input_def['value'] = wpshop_attributes_unit::get_default_unit_for_group($attribute->_unit_group_id);
                    }
                }
                $input_def['options'] .= wpshop_form::check_input_type($unit_input_def, $attributeInputDomain . '[unit]');
            }
        }
        /*
         * Add indication on postage cost tax
         */
        if ($attribute->code == WPSHOP_COST_OF_POSTAGE) {
            $input_def['options'] .= ' <span class="attribute_currency" >' . __('ATI', 'wpshop') . '</span>';
        }
        /*
         * Create the field output
         */
        if (is_admin() && $attribute->data_type == 'datetime' && $attribute->is_user_defined == 'yes' && (empty($specific_argument['from']) || $specific_argument['from'] != 'frontend')) {
            $input_def['output'] = sprintf(__('You select this field to be defined by final customer into frontend part. To change this behaviour you have to change attribute option "%s"', 'wpshop'), __('is_user_defined', 'wpshop'));
            $input_def['options'] = '';
            $input_def['label_pointer'] = '';
            $input_def['option'] = substr($input_def['option'], 0, -2) . ' wpshop_attributes_is_user_defined_admin_field "';
            $input_def['field_container_class'] .= 'wpshop_attributes_is_user_defined_admin_container';
        } else {
            $input_def['output'] = wpshop_form::check_input_type($input_def, $attributeInputDomain);
        }
        return $input_def;
    }
 /**
  * Display the current configuration for a given product
  * @param array $shortcode_attribute Some parameters given by the shortcode for display
  */
 function wpshop_product_variations_summary($shortcode_attribute)
 {
     global $wp_query;
     $output = '';
     if ($wp_query->query_vars['post_type'] == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) {
         $output .= wpshop_display::display_template_element('wpshop_product_configuration_summary', array('CURRENCY_SELECTOR' => wpshop_attributes_unit::wpshop_shop_currency_list_field()));
     }
     echo $output;
 }
示例#3
0
/**
 * Load comboBox of unit or group of unit
 */
function wpshop_ajax_load_attribute_unit_list()
{
    check_ajax_referer('wpshop_load_attribute_unit_list', 'wpshop_ajax_nonce');
    $response = '';
    $current_group = isset($_POST['current_group']) && !empty($_POST['current_group']) ? $_POST['current_group'] : null;
    $selected_list = isset($_POST['selected_list']) && !empty($_POST['selected_list']) ? $_POST['selected_list'] : null;
    $group = wpshop_tools::varSanitizer($current_group);
    $selected_list = wpshop_tools::varSanitizer($selected_list);
    if (!empty($group) && !empty($selected_list)) {
        /* Test if we want display the group unit list OR the unit list */
        if ($selected_list == 'group unit') {
            $list = wpshop_attributes_unit::get_unit_group();
        } else {
            $list = wpshop_attributes_unit::get_unit_list_for_group($group);
        }
        foreach ($list as $unit) {
            $response .= '<option value="' . $unit->id . '" ' . ($current_group == $unit->id && $selected_list == 'group unit' ? 'selected="selected"' : '') . '>' . $unit->name . '</option>';
        }
        $result = array(true, $response);
    } else {
        $result = array(false, __('Incorrect order request', 'wpshop'));
    }
    echo json_encode($result);
    die;
}
 /**
  * Fill a template with given element. Replace some code by content before output the html
  *
  * @param string $template_to_fill The complete html code we want to display with element to change
  * @param array $feed The different element to put in place of the code into the tempalte part
  *
  * @return string The html code to display
  */
 public static function feed_template($template_to_fill, $feed)
 {
     /* Add general element	*/
     $feed['CURRENCY'] = wpshop_tools::wpshop_get_currency();
     $feed['CURRENCY_CHOOSEN'] = wpshop_tools::wpshop_get_currency();
     $feed['CURRENCY_SELECTOR'] = wpshop_attributes_unit::wpshop_shop_currency_list_field();
     $feed['CART_LINK'] = get_permalink(wpshop_tools::get_page_id(get_option('wpshop_cart_page_id')));
     $available_key = array();
     foreach ($feed as $element => $value) {
         $available_key[] = '{WPSHOP_' . $element . '}';
         if (!is_array($value)) {
             $template_to_fill = str_replace('{WPSHOP_' . $element . '}', $value, $template_to_fill);
         }
     }
     if (WPSHOP_DISPLAY_AVAILABLE_KEYS_FOR_TEMPLATE) {
         $template_to_fill = '<!-- Available keys : ' . implode(' / ', $available_key) . ' -->' . $template_to_fill;
     }
     return $template_to_fill;
 }
示例#5
0
 /**
  * Return unit sigle
  * @param unknown_type $code
  * @param unknown_type $column_to_return
  */
 public static function wpshop_get_sigle($code, $column_to_return = "unit")
 {
     $tmp_code = (int) $code;
     $key_to_get = 'name';
     if (is_int($tmp_code) && !empty($tmp_code)) {
         $key_to_get = 'id';
     }
     $old_way_currencies = unserialize(WPSHOP_SHOP_CURRENCIES);
     if (array_key_exists($code, $old_way_currencies)) {
         $code = $old_way_currencies[$code];
         $key_to_get = 'name';
     }
     $current_currency = wpshop_attributes_unit::getElement($code, "'valid'", $key_to_get);
     return $current_currency->{$column_to_return};
 }
                if ($attribute['is_visible_in_front'] == 'yes') {
                    ?>
								
								<?php 
                    if (!empty($attribute['value'])) {
                        ?>
									<li>
										<?php 
                        _e($attribute['frontend_label'], 'wpshop');
                        ?>
 : 
										<?php 
                        echo do_shortcode('[wpshop_att_val attid="' . $attribute["id"] . '" pid="' . $args["pid"] . '"]');
                        ?>
										<?php 
                        wpshop_attributes_unit::the_attribute_unit_by_code_for_product($args['pid'], $attribute['code']);
                        ?>
									</li>
								<?php 
                    }
                    ?>
							<?php 
                }
                ?>
						<?php 
            }
            ?>
					</ul>
				</div>
				<?php 
            $i++;
 public static function wpshop_shop_default_currency_field()
 {
     echo wpshop_attributes_unit::wpshop_shop_currency_list_field() . '<a href="#" title="' . __('This is the currency the shop will use', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
 }
示例#8
0
                 $save_message = '<img class="wpshopPageMessage_Icon" alt="action error" src="' . WPSHOP_ERROR_ICON . '" />' . __('An error occured during unit group saving', 'wpshop');
             }
             echo '<script type="text/javascript" >wpshop(document).ready(function(){setTimeout(function(){ wpshop("#wpshopMessage_unit").removeClass("wpshopPageMessage_Updated"); wpshop("#wpshopMessage_unit").html(""); }, 5000);});</script><div class="fade below-h2 wpshopPageMessage wpshopPageMessage_Updated" id="wpshopMessage_unit">' . $save_message . '</div>' . $save_output;
             break;
         case 'delete_attribute_unit_group':
             $unit_id = wpshop_tools::varSanitizer($_REQUEST['elementIdentifier']);
             $save_output = '';
             $attribute_unit_informations['status'] = 'deleted';
             $attribute_unit_informations['last_update_date'] = date('Y-m-d H:i:s');
             $save_unit_result = wpshop_database::update($attribute_unit_informations, $unit_id, WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP);
             if ($save_unit_result == 'done') {
                 $save_message = '<img class="wpshopPageMessage_Icon" alt="action succesful" src="' . WPSHOP_SUCCES_ICON . '" />' . __('The unit group has been deleted succesfully', 'wpshop');
             } else {
                 $save_message = '<img class="wpshopPageMessage_Icon" alt="action error" src="' . WPSHOP_ERROR_ICON . '" />' . __('An error occured during unit group deletion', 'wpshop');
             }
             echo '<script type="text/javascript" >wpshop(document).ready(function(){setTimeout(function(){ wpshop("#wpshopMessage_unit").removeClass("wpshopPageMessage_Updated"); wpshop("#wpshopMessage_unit").html(""); }, 5000);});</script><div class="fade below-h2 wpshopPageMessage wpshopPageMessage_Updated" id="wpshopMessage_unit">' . $save_message . '</div>' . wpshop_attributes_unit::unit_group_list();
             break;
     }
     break;
 case 'products_by_criteria':
     // If a filter by attribute is found, recalcul the products that matching it
     if (!empty($_REQUEST['attr'])) {
         $att = explode(':', $_REQUEST['attr']);
         $products_id = wpshop_products::get_products_matching_attribute($att[0], $att[1]);
     }
     $products_id = !empty($products_id) ? $products_id : $_REQUEST['pid'];
     $page_number = $_REQUEST['page_number'];
     if (!empty($_GET['page_product'])) {
         $page_number = wpshop_tools::varSanitizer($_GET['page_product']);
     }
     $data = wpshop_products::wpshop_get_product_by_criteria($_REQUEST['criteria'], $_REQUEST['cid'], $products_id, $_REQUEST['display_type'], $_REQUEST['order'], $page_number, $_REQUEST['products_per_page']);