public function wps_create_new_free_product() { global $wpdb; $status = false; $output = __('Error at product creation!', 'wpshop'); $new_product_id = -1; $post_title = !empty($_POST['post_title']) ? $_POST['post_title'] : -1; $post_content = !empty($_POST['post_content']) ? $_POST['post_content'] : ''; $attributes = !empty($_POST['attribute']) ? $_POST['attribute'] : -1; if ($post_title != -1) { $new_product_id = wp_insert_post(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'post_status' => 'free_product', 'post_title' => $post_title, 'post_content' => $post_content)); if (!is_object($new_product_id)) { $attribute_set_list = wpshop_attributes_set::get_attribute_set_list_for_entity(wpshop_entities::get_entity_identifier_from_code('wpshop_product')); $id_attribute_set = null; foreach ($attribute_set_list as $attribute_set) { if ($attribute_set->name == 'free_product') { $id_attribute_set = $attribute_set->id; break; } } update_post_meta($new_product_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attribute_set_id', $id_attribute_set); $data_to_save['post_ID'] = $data_to_save['product_id'] = intval($new_product_id); $data_to_save['wpshop_product_attribute'] = !empty($attributes) ? $attributes : array(); $data_to_save['user_ID'] = get_current_user_id(); $data_to_save['action'] = 'editpost'; $status = false; $output = __('Product created partially!', 'wpshop'); if (!empty($new_product_id) && !empty($data_to_save['user_ID'])) { $product_class = new wpshop_products(); $product_class->save_product_custom_informations($new_product_id, $data_to_save); $status = true; $output = __('Product created successfully.', 'wpshop'); } } } echo json_encode(array('status' => $status, 'message' => $output, 'pid' => $new_product_id)); wp_die(); }
/** * Add metaboxes to the custom post types defined by entities */ public static function add_meta_boxes_to_custom_types($post) { global $post, $wpdb; /* * Add a specific metabox for customer */ if ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS) { //add_meta_box($post->post_type . '_customers_purchase', __('Orders', 'wpshop'), array('wpshop_orders', 'display_orders_for_customer'), $post->post_type, 'normal'); //add_meta_box ($post->post_type.'_customer_note', __('Customers Notes' , 'wpshop'), array('wpshop_customer', 'display_notes_for_customer'), $post->post_type, 'side'); } /* * Product are managed from another place */ if ($post->post_type != WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) { /* * Get the attribute set list for current entity */ $attribute_set_list = wpshop_attributes_set::get_attribute_set_list_for_entity(wpshop_entities::get_entity_identifier_from_code($post->post_type)); /* * Check if a attribute set is defined for current entity */ $attribute_set_id = get_post_meta($post->ID, sprintf(WPSHOP_ATTRIBUTE_SET_ID_META_KEY, $post->post_type), true); if (count($attribute_set_list) == 1 || count($attribute_set_list) > 1 && !empty($attribute_set_id)) { if (count($attribute_set_list) == 1 || empty($attribute_set_id)) { $attribute_set_id = $attribute_set_list[0]->id; } /* * Get attribute list for the current entity */ $currentTabContent = wpshop_attributes::entities_attribute_box($attribute_set_id, $post->post_type, $post->ID); $fixed_box_exist = false; /* * Read the different element for building output for current entity */ if (!empty($currentTabContent['box']) && is_array($currentTabContent['box'])) { 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($post->post_type . '_' . $boxIdentifier, __($boxTitle, 'wpshop'), array('wpshop_entities', 'meta_box_content'), $post->post_type, 'normal', 'default', array('currentTabContent' => $currentTabContent['boxContent'][$boxIdentifier])); } else { $fixed_box_exist = true; } } } if ($fixed_box_exist && $post->post_type != WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS) { add_meta_box($post->post_type . '_fixed_tab', __('Informations', 'wpshop'), array('wpshop_entities', 'meta_box_content_datas'), $post->post_type, 'normal', 'high', array('currentTabContent' => $currentTabContent)); } } elseif (count($attribute_set_list) > 1) { $input_def['id'] = $post->post_type . '_attribute_set_id'; $input_def['name'] = $post->post_type . '_attribute_set_id'; $input_def['value'] = ''; $input_def['type'] = 'select'; $input_def['possible_value'] = $attribute_set_list; $input_def['value'] = ''; foreach ($attribute_set_list as $set) { if ($set->default_set == 'yes') { $input_def['value'] = $set->id; } } $currentTabContent = ' <ul class="attribute_set_selector" > <li class="attribute_set_selector_title_select" ><label for="title" >' . sprintf(__('Choose a title for the %s', 'wpshop'), get_the_title(wpshop_entities::get_entity_identifier_from_code($post->post_type))) . '</label></li> <li class="attribute_set_selector_group_selector" ><label for="' . $input_def['id'] . '" >' . sprintf(__('Choose an attribute group for this %s', 'wpshop'), get_the_title(wpshop_entities::get_entity_identifier_from_code($post->post_type))) . '</label> ' . wpshop_form::check_input_type($input_def) . '</li> <li class="attribute_set_selector_save_instruction" >' . sprintf(__('Save the %s with the "Save draft" button on the right side', 'wpshop'), get_the_title(wpshop_entities::get_entity_identifier_from_code($post->post_type))) . '</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($post->post_type . '_attribute_set_selector', sprintf(__('%s attributes', 'wpshop'), get_the_title(wpshop_entities::get_entity_identifier_from_code($post->post_type))), array('wpshop_entities', 'meta_box_content'), $post->post_type, 'normal', 'high', array('currentTabContent' => $currentTabContent)); } } }
/** * 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')); } } } }
<div class="wpshop_cls" > <div class="wpshop_form_label _description_label alignleft" > <label for="attribute_description" ><?php _e('Description', 'wpshop'); ?> </label> </div> <div class="wpshop_form_input_element _description_input alignleft" > <textarea name="post_content" id="post_content" class="wpshop_product_post_content wpshop_attributes_display" rows="2"></textarea> </div> </div> </div> <?php /** Get the attribute set list */ $attribute_set_list = wpshop_attributes_set::get_attribute_set_list_for_entity(wpshop_entities::get_entity_identifier_from_code('wpshop_product')); $default_set = 0; if (1 == count($attribute_set_list)) { $default_set = $attribute_set_list[0]->id; } ?> <?php /** Check if attribute set list is not empty in order to display a dropdown for sélection */ ?> <?php if (!empty($attribute_set_list) && 1 <= count($attribute_set_list)) { ?> <div style=" width:80%; margin: 0 auto 10px auto; " > <?php _e('Product type to create', 'wpshop'); ?>