/** * Variation uniq item creation */ function ajax_add_new_single_variation() { check_ajax_referer('wpshop_variation_management', 'wpshop_ajax_nonce'); $output = ''; $attributes_for_variation = isset($_POST['variation_attr']) ? $_POST['variation_attr'] : null; $wpshop_admin_use_attribute_for_single_variation_checkbox = isset($_POST['wpshop_admin_use_attribute_for_single_variation_checkbox']) ? $_POST['wpshop_admin_use_attribute_for_single_variation_checkbox'] : null; $variation_specific_definition = isset($_POST['wps_pdt_variations']['new']['attribute']) ? $_POST['wps_pdt_variations']['new']['attribute'] : null; $current_post_id = isset($_POST['wpshop_head_product_id']) ? wpshop_tools::varSanitizer($_POST['wpshop_head_product_id']) : null; $attribute_to_use_for_creation = array(); foreach ($attributes_for_variation as $attribute_code => $attribute_value) { if (array_key_exists($attribute_code, $wpshop_admin_use_attribute_for_single_variation_checkbox)) { $attribute_to_use_for_creation[0][$attribute_code] = $attributes_for_variation[$attribute_code]; $attr_def = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); $variation_specific_definition[$attr_def->data_type][$attribute_code] = $attributes_for_variation[$attribute_code]; } } $new_variation_identifier = wpshop_products::creation_variation_callback($attribute_to_use_for_creation, $current_post_id); /* Save variation specific element */ foreach (unserialize(WPSHOP_ATTRIBUTE_PRICES) as $price_attribute_code) { $head_product_price_attribute_value = wpshop_attributes::get_attribute_value_content($price_attribute_code, $current_post_id, wpshop_products::currentPageCode); $price_attr_def = wpshop_attributes::getElement($price_attribute_code, "'valid'", 'code'); if (!empty($price_attr_def) && !empty($price_attr_def->data_type) && (empty($variation_specific_definition[$price_attr_def->data_type]) || !array_key_exists($price_attribute_code, $variation_specific_definition[$price_attr_def->data_type]))) { $variation_specific_definition[$price_attr_def->data_type][$price_attribute_code] = !empty($head_product_price_attribute_value->value) ? $head_product_price_attribute_value->value : 1; } } wpshop_attributes::saveAttributeForEntity($variation_specific_definition, wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $new_variation_identifier, WPSHOP_CURRENT_LOCALE); wpshop_products::calculate_price($new_variation_identifier); $output = wpshop_products::display_variation_admin($current_post_id); echo $output; die; }
/** * Create the different bow for the product management page looking for the attribute set to create the different boxes */ public static function add_meta_boxes() { global $post, $currentTabContent; if (!empty($post->post_type) && ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT || $post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION)) { /* Get the attribute set list for the current entity */ $attributeEntitySetList = wpshop_attributes_set::get_attribute_set_list_for_entity(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode)); /* Check if the meta information of the current product already exists */ $post_attribute_set_id = get_post_meta($post->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true); /* Check if the product has been saved without meta information set */ $attribute_set_id = wpshop_attributes::get_attribute_value_content('product_attribute_set_id', $post->ID, self::currentPageCode); /* Unset 'free_product' from list of attributes set */ foreach ($attributeEntitySetList as $key_attribute_set => $attribute_set) { if ($attribute_set->name == 'free_product') { unset($attributeEntitySetList[$key_attribute_set]); break; } } /* Check if an attribute has already been choosen for the curernt entity or if the user has to choose a entity set before continuing */ if (count($attributeEntitySetList) == 1 || count($attributeEntitySetList) > 1 && ($post_attribute_set_id > 0 || isset($attribute_set_id->value) && $attribute_set_id->value > 0)) { if (count($attributeEntitySetList) == 1 || $post_attribute_set_id <= 0 && $attribute_set_id->value <= 0) { $post_attribute_set_id = $attributeEntitySetList[0]->id; } elseif ($post_attribute_set_id <= 0 && $attribute_set_id->value > 0) { $post_attribute_set_id = $attribute_set_id->value; } $currentTabContent = wpshop_attributes::entities_attribute_box($post_attribute_set_id, self::currentPageCode, $post->ID); $fixed_box_exist = false; /* Get all the other attribute set for hte current entity */ if (isset($currentTabContent['box']) && count($currentTabContent['box']) > 0) { foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) { if (!empty($currentTabContent['box'][$boxIdentifier . '_backend_display_type']) && $currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'movable-tab') { add_meta_box('wpshop_product_' . $boxIdentifier, __($boxTitle, 'wpshop'), array('wpshop_products', 'meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'default', array('boxIdentifier' => $boxIdentifier)); } else { $fixed_box_exist = true; } } } if ($fixed_box_exist) { add_meta_box('wpshop_product_fixed_tab', __('Product data', 'wpshop'), array('wpshop_products', 'product_data_meta_box'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'high', array('currentTabContent' => $currentTabContent)); add_meta_box('wpshop_product_fixed_tab', __('Product data', 'wpshop'), array('wpshop_products', 'product_data_meta_box'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'normal', 'high', array('currentTabContent' => $currentTabContent)); } add_meta_box('wpshop_wpshop_variations', __('Product variation', 'wpshop'), array('wpshop_products', 'meta_box_variations'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'default'); // Actions add_meta_box('wpshop_product_actions', __('Actions', 'wpshop'), array('wpshop_products', 'product_actions_meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'side', 'default'); /** Product option */ add_meta_box('wpshop_product_options', __('Options', 'wpshop'), array('wpshop_products', 'product_options_meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'side', 'default'); } else { if (count($attributeEntitySetList) > 1) { $input_def['id'] = 'product_attribute_set_id'; $input_def['name'] = 'product_attribute_set_id'; $input_def['value'] = ''; $input_def['type'] = 'select'; $input_def['possible_value'] = $attributeEntitySetList; $input_def['value'] = ''; foreach ($attributeEntitySetList as $set) { if ($set->default_set == 'yes') { $input_def['value'] = $set->id; } } $currentTabContent['boxContent']['attribute_set_selector'] = ' <ul class="attribute_set_selector" > <li class="attribute_set_selector_title_select" ><label for="title" >' . __('Choose a title for your product', 'wpshop') . '</label></li> <li class="attribute_set_selector_group_selector" ><label for="' . $input_def['id'] . '" >' . __('Choose an attribute group for this product', 'wpshop') . '</label> ' . wpshop_form::check_input_type($input_def, self::currentPageCode . '_attribute[integer]') . '</li> <li class="attribute_set_selector_save_instruction" >' . __('Save the product with the "Save draft" button on the right side', 'wpshop') . '</li> <li class="attribute_set_selector_after_save_instruction" >' . __('Once the group chosen, the different attribute will be displayed here', 'wpshop') . '</li> </ul>'; add_meta_box('wpshop_product_attribute_set_selector', __('Product attributes', 'wpshop'), array('wpshop_products', 'meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'high', array('boxIdentifier' => 'attribute_set_selector')); } } } }