/**
     *
     * @param unknown_type $attributeSetId
     * @param unknown_type $currentPageCode
     * @param unknown_type $itemToEdit
     * @param unknown_type $outputType
     * @return Ambigous <multitype:, string>
     */
    public static function entities_attribute_box($attributeSetId, $currentPageCode, $itemToEdit, $outputType = 'box')
    {
        $box = $box['box'] = $box['boxContent'] = $box['generalTabContent'] = array();
        /*	Get the attribute set details in order to build the product interface	*/
        $productAttributeSetDetails = wpshop_attributes_set::getAttributeSetDetails($attributeSetId, "'valid'");
        $attribute_specification = array('page_code' => $currentPageCode, 'element_identifier' => $itemToEdit, 'field_id' => $currentPageCode . '_' . $itemToEdit . '_');
        if (count($productAttributeSetDetails) > 0) {
            /*	Read the attribute list in order to output	*/
            $shortcodes_attr = '';
            $shortcodes_to_display = false;
            $attribute_set_id_is_present = false;
            foreach ($productAttributeSetDetails as $productAttributeSetDetail) {
                $shortcodes = $currentTabContent = '';
                $output_nb = 0;
                if (count($productAttributeSetDetail['attribut']) >= 1) {
                    foreach ($productAttributeSetDetail['attribut'] as $attribute) {
                        if (!empty($attribute->id)) {
                            if ($attribute->code == 'product_attribute_set_id') {
                                $attribute_set_id_is_present = true;
                            }
                            /** Generic part for attribute field output	*/
                            $value = wpshop_attributes::getAttributeValueForEntityInSet($attribute->data_type, $attribute->id, wpshop_entities::get_entity_identifier_from_code($currentPageCode), $itemToEdit, array('intrinsic' => $attribute->is_intrinsic, 'backend_input' => $attribute->backend_input));
                            $product_meta = get_post_meta($itemToEdit, '_wpshop_product_metadata', true);
                            /**	Check if value is empty and get value in meta if not empty	*/
                            $value = empty($value) && !empty($product_meta[$attribute->code]) ? $product_meta[$attribute->code] : (!empty($value) ? $value : null);
                            /*	Manage specific field as the attribute_set_id in product form	*/
                            if ($attribute->code == 'product_attribute_set_id') {
                                $value = empty($value) ? $attributeSetId : $value;
                            }
                            $attribute_specification['current_value'] = $value;
                            $attribute_output_def = wpshop_attributes::display_attribute($attribute->code, 'admin', $attribute_specification);
                            if ($attribute_output_def['field_definition']['type'] != 'hidden' && $attribute->code != 'product_attribute_set_id') {
                                $currentTabContent .= $attribute_output_def['field'];
                                $shortcode_code_def = array();
                                $shortcode_code_def['attribute_' . str_replace('-', '_', sanitize_title($attribute_output_def['field_definition']['label']))]['main_code'] = 'wpshop_att_val';
                                $shortcode_code_def['attribute_' . str_replace('-', '_', sanitize_title($attribute_output_def['field_definition']['label']))]['attrs_exemple']['type'] = $attribute->data_type;
                                $shortcode_code_def['attribute_' . str_replace('-', '_', sanitize_title($attribute_output_def['field_definition']['label']))]['attrs_exemple']['attid'] = $attribute->id;
                                $shortcode_code_def['attribute_' . str_replace('-', '_', sanitize_title($attribute_output_def['field_definition']['label']))]['attrs_exemple']['pid'] = $itemToEdit;
                                ob_start();
                                wps_shortcodes_ctr::output_shortcode('attribute_' . str_replace('-', '_', sanitize_title($attribute_output_def['field_definition']['label'])), $shortcode_code_def, 'wpshop_product_shortcode_display wpshop_product_attribute_shortcode_display wpshop_product_attribute_shortcode_display_' . str_replace('-', '_', sanitize_title($attribute_output_def['field_definition']['label'])) . ' wpshop_cls');
                                $shortcodes .= '<li class="wpshop_cls" >' . sprintf(__('Insertion code for the attribute %s for this product', 'wpshop'), '<span>' . __($attribute_output_def['field_definition']['label'], 'wpshop') . '</span>') . ob_get_contents() . '</li>';
                                ob_end_clean();
                            } else {
                                if ($attribute->code == 'product_attribute_set_id') {
                                    $attribute_output_def['field_definition']['type'] = 'hidden';
                                }
                                $currentTabContent .= wpshop_form::check_input_type($attribute_output_def['field_definition'], $attribute_output_def['field_definition']['input_domain']);
                            }
                            $output_nb++;
                        }
                    }
                    $shortcode_code['attributes_set']['main_code'] = 'wpshop_att_group';
                    $shortcode_code['attributes_set']['attrs_exemple']['pid'] = $itemToEdit;
                    $shortcode_code['attributes_set']['attrs_exemple']['sid'] = $productAttributeSetDetail['id'];
                    ob_start();
                    wps_shortcodes_ctr::output_shortcode('attributes_set', $shortcode_code, 'wpshop_product_shortcode_display wpshop_product_attribute_group_shortcode_display wpshop_product_attribute_group_shortcode_display_' . str_replace('-', '_', sanitize_title($productAttributeSetDetail['name'])) . ' cls');
                    $attribute_group_display = sprintf(__('Insertion code for attribute group %s for this product', 'wpshop'), '<span>' . $productAttributeSetDetail['name'] . '</span>') . ob_get_contents() . '<ul class="" >' . $shortcodes . '</ul>';
                    ob_end_clean();
                    if (WPSHOP_PRODUCT_SHORTCODE_DISPLAY_TYPE == 'each-box') {
                        $currentTabContent .= '<div class="wpshop_cls" ><strong>' . __('Shortcodes', 'wpshop') . '</strong> - <a href="#" class="show-hide-shortcodes">' . __('Display', 'wpshop') . '</a><div class="wpshop_product_shortcode_display wpshop_product_shortcode_display_container wpshopHide" >' . $attribute_group_display . '</div></div>';
                    } else {
                        $shortcodes_attr .= $attribute_group_display;
                    }
                    if ($output_nb <= 0) {
                        $currentTabContent = __('Nothing avaiblable here. You can go in attribute management interface in order to add content here.', 'wpshop');
                    }
                }
                if ($output_nb > 0) {
                    $shortcodes_to_display = true;
                    if ($outputType == 'box') {
                        $box['box'][$productAttributeSetDetail['code']] = $productAttributeSetDetail['name'];
                        $box['box'][$productAttributeSetDetail['code'] . '_backend_display_type'] = $productAttributeSetDetail['backend_display_type'];
                        $box['boxContent'][$productAttributeSetDetail['code']] = '
			<div id="wpshop_' . $currentPageCode . '_' . wpshop_tools::slugify($productAttributeSetDetail['code'], array('noAccent')) . '_form" >' . $currentTabContent . '
							</div><div class="wpshop_cls" ></div>';
                    } else {
                        if ($outputType == 'column') {
                            $currentTabContent = str_replace('wpshop_form_input_element', 'wpshop_form_input_column', $currentTabContent);
                            $currentTabContent = str_replace('wpshop_form_label', 'wpshop_form_label_column', $currentTabContent);
                            $box['columnTitle'][$productAttributeSetDetail['code']] = __($productAttributeSetDetail['name'], 'wpshop');
                            $box['columnContent'][$productAttributeSetDetail['code']] = $currentTabContent;
                        }
                    }
                }
            }
            if (!$attribute_set_id_is_present) {
                /*	Get attribute definition	*/
                $attribute_def = wpshop_attributes::getElement('product_attribute_set_id', "'valid'", 'code');
                /*	Get attribute input definition	*/
                $input = wpshop_attributes::get_attribute_field_definition($attribute_def, $attributeSetId, array_merge($attribute_specification, array('input_class' => ' wpshop_attributes_display', 'from' => 'admin')));
                $input['type'] = 'hidden';
                $box['boxMore'] = wpshop_form::check_input_type($input, $input['input_domain']);
            }
            /*	Ajout de la boite permettant d'ajouter des valeurs aux attributs de type liste deroulante a la volee	*/
            $dialog_title = __('New value for attribute', 'wpshop');
            $dialog_identifier = 'wpshop_new_attribute_option_value_add';
            $dialog_input_identifier = 'wpshop_new_attribute_option_value';
            ob_start();
            include WPSHOP_TEMPLATES_DIR . 'admin/add_new_element_dialog.tpl.php';
            $box['boxMore'] .= ob_get_contents();
            ob_end_clean();
            $box['boxMore'] .= '<input type="hidden" name="wpshop_attribute_type_select_code" value="" id="wpshop_attribute_type_select_code" />';
            if ($shortcodes_to_display) {
                switch (WPSHOP_PRODUCT_SHORTCODE_DISPLAY_TYPE) {
                    case 'fixed-tab':
                    case 'movable-tab':
                        if ($outputType == 'box') {
                            $box['box']['shortcode'] = __('Product Shortcodes', 'wpshop');
                            $box['boxContent']['shortcode'] = $shortcodes_attr;
                            $box['box']['shortcode_backend_display_type'] = WPSHOP_PRODUCT_SHORTCODE_DISPLAY_TYPE;
                        } else {
                            $box['columnTitle']['shortcode'] = __('Product Shortcodes', 'wpshop');
                            $box['columnContent']['shortcode'] = $shortcodes_attr;
                        }
                        break;
                }
            }
        }
        return $box;
    }
示例#2
0
function ajax_wpshop_reload_attribute_for_quick_add()
{
    $output = '';
    if (!empty($_POST['attribute_to_reload'])) {
        foreach ($_POST['attribute_to_reload'] as $attribute_code) {
            $attr_field = wpshop_attributes::display_attribute($attribute_code, 'frontend');
            $output[$attribute_code]['result'] = $attr_field['field_definition']['output'] . $attr_field['field_definition']['options'];
        }
    }
    echo json_encode(array($output));
    die;
}
	<input type="hidden" name="wps-customer-account-set-id" value="wps-customer-quick-add" />

	<?php 
if (!empty($customer_attributes)) {
    ?>
		<?php 
    foreach ($customer_attributes as $customer_attribute_group) {
        ?>
	<div class="wps-boxed">
		<span class="wps-h5"><?php 
        echo stripslashes($customer_attribute_group['name']);
        ?>
</span>
<?php 
        foreach ($customer_attribute_group['attribut'] as $attribute) {
            $output = wpshop_attributes::display_attribute($attribute->code);
            echo $output['field'];
        }
        ?>
	</div>
		<?php 
    }
    ?>
	<?php 
}
?>

	<button class="wps-bton-first-mini-rounded alignRight" ><?php 
_e('Add customer', 'wpshop');
?>
</button>
 /**
  * Display a form allowing to create an entity from frontend with a shortcode
  * @param array $shortcode_args The different parameters for the shortocde: the field list for the form, different parameters for the entity to create
  */
 public static function wpshop_entities_shortcode($shortcode_args)
 {
     global $wpshop_account, $wpdb;
     $output = $form_content = '';
     if (get_current_user_id() > 0) {
         if (!empty($_POST['quick_entity_add_button'])) {
             $attributes = array();
             foreach ($_POST['attribute'] as $attribute_type => $attribute) {
                 foreach ($attribute as $attribute_code => $attribute_value) {
                     $attributes[$attribute_code] = $attribute_value;
                 }
             }
             $result = wpshop_products::addProduct($_POST['wp_fields']['post_title'], '', $attributes, 'complete');
         }
         if (empty($shortcode_args['attribute_set_id']) || empty($shortcode_args['post_type'])) {
             $output = __('This form page is invalid because no set or type or content is defined. Please contact administrator with this error message', 'wpshop');
         } else {
             $entity_identifier = wpshop_entities::get_entity_identifier_from_code($shortcode_args['post_type']);
             $attribute_set_def = wpshop_attributes_set::getElement($shortcode_args['attribute_set_id'], "'valid'");
             if (empty($entity_identifier) || empty($attribute_set_def) || $entity_identifier != $attribute_set_def->entity_id) {
                 $output = __('This form page is invalid because type and set are not linked. Please contact administrator with this error message', 'wpshop');
             } else {
                 /** Display wordpress fields */
                 foreach (explode(', ', $shortcode_args['fields']) as $field_name) {
                     $label = '';
                     switch ($field_name) {
                         case 'post_title':
                             switch ($shortcode_args['post_type']) {
                                 case WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT:
                                     $label = __('Product title', 'wpshop');
                                     break;
                                 default:
                                     $label = __('Name', 'wpshop');
                                     break;
                             }
                             $field_type = 'text';
                             break;
                         case 'post_thumbnail':
                             switch ($shortcode_args['post_type']) {
                                 case WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT:
                                     $label = __('Product picture', 'wpshop');
                                     break;
                                 default:
                                     $label = __('Default picture', 'wpshop');
                                     break;
                             }
                             $field_type = 'file';
                             break;
                     }
                     if (!empty($label)) {
                         $template_part = 'quick_entity_wp_internal_field_' . $field_type;
                         $tpl_component = array();
                         $tpl_component['WP_FIELD_NAME'] = $field_name;
                         $tpl_component['WP_FIELD_VALUE'] = '';
                         $input = wpshop_display::display_template_element($template_part, $tpl_component);
                         unset($tpl_component);
                         $template_part = 'quick_entity_wp_internal_field_output';
                         $tpl_component = array();
                         $tpl_component['ENTITY_TYPE_TO_CREATE'] = $shortcode_args['post_type'];
                         $tpl_component['WP_FIELD_NAME'] = $field_name;
                         $tpl_component['WP_FIELD_LABEL'] = $label;
                         $tpl_component['WP_FIELD_INPUT'] = $input;
                         $form_content .= wpshop_display::display_template_element($template_part, $tpl_component);
                         unset($tpl_component);
                     }
                 }
                 /** Display attributes fields	*/
                 $query = $wpdb->prepare("\nSELECT ATT.code\nFROM " . WPSHOP_DBT_ATTRIBUTE . " AS ATT\n\tINNER JOIN " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " AS ATTR_DET ON ((ATTR_DET.status = 'valid') AND (ATTR_DET.attribute_id = ATT.id) AND (ATTR_DET.entity_type_id = ATT.entity_id))\n\tINNER JOIN " . WPSHOP_DBT_ATTRIBUTE_GROUP . " AS ATT_GROUP ON ((ATT_GROUP.status = 'valid') AND (ATT_GROUP.attribute_set_id = ATTR_DET.attribute_set_id) AND (ATT_GROUP.id = ATTR_DET.attribute_group_id))\nWHERE ATT.is_used_in_quick_add_form = %s\n\tAND ATT.status= %s\n\tAND ATT.entity_id = %d\n\tAND ATTR_DET.attribute_set_id = %d\nGROUP BY ATT.code\nORDER BY ATT_GROUP.position, ATTR_DET.position", 'yes', 'valid', wpshop_entities::get_entity_identifier_from_code($shortcode_args['post_type']), $shortcode_args['attribute_set_id']);
                 $attribute_for_creation = $wpdb->get_results($query);
                 foreach ($attribute_for_creation as $attribute) {
                     $attr_field = wpshop_attributes::display_attribute($attribute->code, 'frontend');
                     $form_content .= $attr_field['field'];
                 }
                 /**	Check if there are extra parameters	*/
                 if (!empty($shortcode_args['extra_element'])) {
                     $extra_element = explode(', ', $shortcode_args['extra_element']);
                     foreach ($extra_element as $element) {
                         $element_def = explode('!#wps#!', $element);
                         $element_type = $element_def[0];
                         $element_id = $element_def[1];
                         if ($element_type == WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS) {
                             $form_content .= '<div class="wpshop_entity_address_container">';
                             // 								$form_content .= $wpshop_account->display_form_fields($element_id, null, 'not');
                             $form_content .= '</div><div class="wpshop_cls"></div>';
                         }
                     }
                 }
             }
         }
         $template_part = 'quick_entity_add_form';
         $tpl_component = array();
         $tpl_component['ENTITY_TYPE'] = $shortcode_args['post_type'];
         $tpl_component['ENTITY_ATTRIBUTE_SET_ID'] = !empty($shortcode_args['attribute_set_id']) ? $shortcode_args['attribute_set_id'] : 0;
         $tpl_component['NEW_ENTITY_FORM_DETAILS'] = $form_content;
         $tpl_component['ENTITY_QUICK_ADDING_FORM_NONCE'] = wp_create_nonce("wpshop_add_new_entity_ajax_nonce");
         $tpl_component['ENTITY_QUICK_ADD_BUTTON_TEXT'] = __($shortcode_args['button_text'], 'wpshop');
         /*	Ajout de la boite permettant d'ajouter des valeurs aux attributs de type liste deroulante a la volee	*/
         $dialog_title = __('New value', 'wpshop');
         $dialog_identifier = 'new_value_for_entity';
         $dialog_input_identifier = 'wpshop_new_attribute_option_value';
         ob_start();
         include WPSHOP_TEMPLATES_DIR . 'admin/add_new_element_dialog.tpl.php';
         $tpl_component['DIALOG_BOX'] = ob_get_contents();
         ob_end_clean();
         $tpl_component['DIALOG_BOX'] .= '<input type="hidden" name="wpshop_attribute_type_select_code" value="" id="wpshop_attribute_type_select_code" />';
         $tpl_component['DIALOG_BOX'] = '';
         $output = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'wpshop');
         echo $output;
     } else {
         echo $wpshop_account->display_login_form();
     }
 }
	</td>*/
?>
	
	<?php 
if (!empty($quick_add_form_attributes)) {
    $i = 0;
    ?>
		<?php 
    foreach ($quick_add_form_attributes as $attribute_id => $att_def) {
        $att = null;
        $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_set_id = %d AND attribute_id = %d AND status = %s', $default, $attribute_id, 'valid');
        $checking_display_att = $wpdb->get_results($query);
        if (!empty($checking_display_att)) {
            $current_value = wpshop_attributes::getAttributeValueForEntityInSet($att_def['data_type'], $attribute_id, $product_entity_id, $product['post_datas']->ID);
            $output_specs = array('page_code' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'element_identifier' => $product['post_datas']->ID, 'field_id' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_' . $product['post_datas']->ID . '_', 'current_value' => !empty($current_value->value) ? $current_value->value : '');
            $att = wpshop_attributes::display_attribute($att_def['code'], 'admin', $output_specs);
        }
        ?>
			<td class="wps_mass_interface_line">
				<div class="wps-form-group">
					<?php 
        /*<label><?php  _e( $att['field_definition']['label'], 'wpshop' ); ?></label>*/
        ?>
					<div class="wps-form"><?php 
        echo str_replace('name="wpshop_product_attribute', 'name="wpshop_product_attribute[' . $product['post_datas']->ID . ']', $att['field_definition']['output']);
        ?>
</div>
				</div>
			</td>
		<?php 
        $i++;