/** * Display Discount Chip * @param array $args * @return string */ function display_discount_chip($args) { $output = ''; if (!empty($args) && !empty($args['pid'])) { $wps_price = new wpshop_prices(); $discount_data = wpshop_prices::check_discount_for_product($args['pid']); if (!empty($discount_data)) { ob_start(); require wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "frontend", "product_discount_chip"); $output = ob_get_contents(); ob_end_clean(); } } return $output; }
/** * Define the different message and action after an action is send through the element interface */ function elementAction() { global $wpdb, $initialEavData; $pageMessage = $actionResult = ''; $attribute_undeletable = unserialize(WPSHOP_ATTRIBUTE_UNDELETABLE); /* Start definition of output message when action is doing on another page */ /************ CHANGE THE FIELD NAME TO TAKE TO DISPLAY *************/ /****************************************************************************/ $action = isset($_REQUEST['action']) ? wpshop_tools::varSanitizer($_REQUEST['action']) : 'add'; $saveditem = isset($_REQUEST['saveditem']) ? wpshop_tools::varSanitizer($_REQUEST['saveditem']) : ''; $set_section = !empty($_REQUEST[self::getDbTable()]['set_section']) ? wpshop_tools::varSanitizer($_REQUEST[self::getDbTable()]['set_section']) : ''; if (!empty($_REQUEST[self::getDbTable()]['set_section'])) { unset($_REQUEST[self::getDbTable()]['set_section']); } if (!empty($action) && $action == 'activate' && !empty($_REQUEST['id'])) { $query = $wpdb->update(self::getDbTable(), array('status' => 'moderated'), array('id' => $_REQUEST['id'])); wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . self::getListingSlug() . "&action=edit&id=" . $_REQUEST['id'])); } if ($action != '' && $action == 'saveok' && $saveditem > 0) { $editedElement = self::getElement($saveditem); $pageMessage = '<img src="' . WPSHOP_SUCCES_ICON . '" alt="action success" class="wpshopPageMessage_Icon" />' . sprintf(__('%s succesfully saved', 'wpshop'), '<span class="bold" >' . $editedElement->code . '</span>'); } elseif ($action != '' && $action == 'deleteok' && $saveditem > 0) { $editedElement = self::getElement($saveditem, "'deleted'"); $pageMessage = '<img src="' . WPSHOP_SUCCES_ICON . '" alt="action success" class="wpshopPageMessage_Icon" />' . sprintf(__('%s succesfully deleted', 'wpshop'), '<span class="bold" >' . $editedElement->code . '</span>'); } $wpshop_attribute_combo_values_list_order_def = !empty($_REQUEST[self::getDbTable()]['wpshop_attribute_combo_values_list_order_def']) ? $_REQUEST[self::getDbTable()]['wpshop_attribute_combo_values_list_order_def'] : array(); unset($_REQUEST[self::getDbTable()]['wpshop_attribute_combo_values_list_order_def']); if (!isset($_REQUEST[self::getDbTable()]['status'])) { $_REQUEST[self::getDbTable()]['status'] = 'moderated'; } if (!isset($_REQUEST[self::getDbTable()]['is_historisable'])) { $_REQUEST[self::getDbTable()]['is_historisable'] = 'no'; } if (!isset($_REQUEST[self::getDbTable()]['is_required'])) { $_REQUEST[self::getDbTable()]['is_required'] = 'no'; } if (!isset($_REQUEST[self::getDbTable()]['is_used_in_admin_listing_column'])) { $_REQUEST[self::getDbTable()]['is_used_in_admin_listing_column'] = 'no'; } if (!isset($_REQUEST[self::getDbTable()]['is_used_in_quick_add_form'])) { $_REQUEST[self::getDbTable()]['is_used_in_quick_add_form'] = 'no'; } if (!isset($_REQUEST[self::getDbTable()]['is_intrinsic'])) { $_REQUEST[self::getDbTable()]['is_intrinsic'] = 'no'; } if (!isset($_REQUEST[self::getDbTable()]['is_requiring_unit'])) { $_REQUEST[self::getDbTable()]['is_requiring_unit'] = 'no'; } if (!isset($_REQUEST[self::getDbTable()]['is_visible_in_front'])) { $_REQUEST[self::getDbTable()]['is_visible_in_front'] = 'no'; } if (!isset($_REQUEST[self::getDbTable()]['is_visible_in_front_listing'])) { $_REQUEST[self::getDbTable()]['is_visible_in_front_listing'] = 'no'; } if (!isset($_REQUEST[self::getDbTable()]['is_used_for_sort_by'])) { $_REQUEST[self::getDbTable()]['is_used_for_sort_by'] = 'no'; } if (!isset($_REQUEST[self::getDbTable()]['is_visible_in_advanced_search'])) { $_REQUEST[self::getDbTable()]['is_visible_in_advanced_search'] = 'no'; } if (!isset($_REQUEST[self::getDbTable()]['is_searchable'])) { $_REQUEST[self::getDbTable()]['is_searchable'] = 'no'; } if (!isset($_REQUEST[self::getDbTable()]['is_used_for_variation'])) { $_REQUEST[self::getDbTable()]['is_used_for_variation'] = 'no'; } if (!isset($_REQUEST[self::getDbTable()]['is_used_in_variation'])) { $_REQUEST[self::getDbTable()]['is_used_in_variation'] = 'no'; } if (!isset($_REQUEST[self::getDbTable()]['is_user_defined'])) { $_REQUEST[self::getDbTable()]['is_user_defined'] = 'no'; } if (!isset($_REQUEST[self::getDbTable()]['_display_informations_about_value'])) { $_REQUEST[self::getDbTable()]['_display_informations_about_value'] = 'no'; } /* Check frontend input and data type */ if (!empty($_REQUEST[self::getDbTable()]['frontend_input'])) { switch ($_REQUEST[self::getDbTable()]['frontend_input']) { case 'short_text': $_REQUEST[self::getDbTable()]['frontend_input'] = 'text'; if (empty($_REQUEST[self::getDbTable()]['backend_input'])) { $_REQUEST[self::getDbTable()]['backend_input'] = 'text'; } $_REQUEST[self::getDbTable()]['data_type'] = 'varchar'; break; case 'date_field': $_REQUEST[self::getDbTable()]['frontend_input'] = 'text'; if (empty($_REQUEST[self::getDbTable()]['backend_input'])) { $_REQUEST[self::getDbTable()]['backend_input'] = 'text'; } $_REQUEST[self::getDbTable()]['data_type'] = 'datetime'; break; case 'float_field': $_REQUEST[self::getDbTable()]['frontend_input'] = 'text'; if (empty($_REQUEST[self::getDbTable()]['backend_input'])) { $_REQUEST[self::getDbTable()]['backend_input'] = 'text'; } $_REQUEST[self::getDbTable()]['data_type'] = 'decimal'; break; case 'hidden_field': $_REQUEST[self::getDbTable()]['frontend_input'] = 'hidden'; if (empty($_REQUEST[self::getDbTable()]['backend_input'])) { $_REQUEST[self::getDbTable()]['backend_input'] = 'text'; } $_REQUEST[self::getDbTable()]['data_type'] = 'varchar'; break; case 'pass_field': $_REQUEST[self::getDbTable()]['frontend_input'] = 'password'; if (empty($_REQUEST[self::getDbTable()]['backend_input'])) { $_REQUEST[self::getDbTable()]['backend_input'] = 'text'; } $_REQUEST[self::getDbTable()]['data_type'] = 'varchar'; break; case 'select': $_REQUEST[self::getDbTable()]['frontend_input'] = 'select'; if (empty($_REQUEST[self::getDbTable()]['backend_input']) || empty($_REQUEST['id'])) { $_REQUEST[self::getDbTable()]['backend_input'] = 'multiple-select'; } $_REQUEST[self::getDbTable()]['data_type'] = 'integer'; break; case 'multiple-select': $_REQUEST[self::getDbTable()]['frontend_input'] = 'multiple-select'; if (empty($_REQUEST[self::getDbTable()]['backend_input']) || empty($_REQUEST['id'])) { $_REQUEST[self::getDbTable()]['backend_input'] = 'multiple-select'; } $_REQUEST[self::getDbTable()]['data_type'] = 'integer'; break; case 'radio': $_REQUEST[self::getDbTable()]['frontend_input'] = 'radio'; if (empty($_REQUEST[self::getDbTable()]['backend_input']) || empty($_REQUEST['id'])) { $_REQUEST[self::getDbTable()]['backend_input'] = 'multiple-select'; } $_REQUEST[self::getDbTable()]['data_type'] = 'integer'; break; case 'checkbox': $_REQUEST[self::getDbTable()]['frontend_input'] = 'checkbox'; if (empty($_REQUEST[self::getDbTable()]['backend_input']) || empty($_REQUEST['id'])) { $_REQUEST[self::getDbTable()]['backend_input'] = 'multiple-select'; } $_REQUEST[self::getDbTable()]['data_type'] = 'integer'; break; case 'textarea': $_REQUEST[self::getDbTable()]['frontend_input'] = 'textarea'; if (empty($_REQUEST[self::getDbTable()]['backend_input']) || empty($_REQUEST['id'])) { $_REQUEST[self::getDbTable()]['backend_input'] = 'textarea'; } $_REQUEST[self::getDbTable()]['data_type'] = 'text'; break; } } else { $_REQUEST[self::getDbTable()]['frontend_input'] = 'text'; if (empty($_REQUEST[self::getDbTable()]['backend_input'])) { $_REQUEST[self::getDbTable()]['backend_input'] = 'text'; } $_REQUEST[self::getDbTable()]['data_type'] = 'varchar'; } /* Check if the checkbox for ajax activation is checked for data update */ // if(!isset($_REQUEST[self::getDbTable()]['use_ajax_for_filling_field']) || empty($_REQUEST[self::getDbTable()]['use_ajax_for_filling_field'])){ // $_REQUEST[self::getDbTable()]['use_ajax_for_filling_field']='no'; // } $_REQUEST[self::getDbTable()]['use_ajax_for_filling_field'] = 'yes'; /* Define the database operation type from action launched by the user */ $_REQUEST[self::getDbTable()]['default_value'] = !empty($_REQUEST[self::getDbTable()]['default_value']) && is_array($_REQUEST[self::getDbTable()]['default_value']) ? serialize($_REQUEST[self::getDbTable()]['default_value']) : (isset($_REQUEST[self::getDbTable()]['default_value']) ? str_replace('"', "'", $_REQUEST[self::getDbTable()]['default_value']) : ''); if ($_REQUEST[self::getDbTable()]['data_type'] == 'datetime') { $date_default_value_trasform_into_config = array('default_value' => $_REQUEST[self::getDbTable()]['default_value'], 'field_options' => !empty($_POST[self::getDbTable() . '_options']) ? $_POST[self::getDbTable() . '_options'] : null); $_REQUEST[self::getDbTable()]['default_value'] = serialize($date_default_value_trasform_into_config); } /***************************** GENERIC **************************/ /*************************************************************************/ $pageAction = !empty($_REQUEST[self::getDbTable()]['frontend_label']) && isset($_REQUEST[self::getDbTable() . '_action']) ? wpshop_tools::varSanitizer($_REQUEST[self::getDbTable() . '_action']) : (!empty($_GET['action']) && $_GET['action'] == 'delete' ? $_GET['action'] : ''); $id = isset($_REQUEST[self::getDbTable()]['id']) ? wpshop_tools::varSanitizer($_REQUEST[self::getDbTable()]['id']) : (!empty($_GET['id']) ? $_GET['id'] : ''); if ($pageAction != '' && ($pageAction == 'edit' || $pageAction == 'editandcontinue')) { if (current_user_can('wpshop_edit_attributes')) { $_REQUEST[self::getDbTable()]['last_update_date'] = date('Y-m-d H:i:s'); if ($pageAction == 'delete') { $attribute_code = $_REQUEST[self::getDbTable()]['code']; if (!isset($_REQUEST[self::getDbTable()]['code']) || $_REQUEST[self::getDbTable()]['code'] == '') { $attribute = self::getElement($id, "'valid', 'moderated', 'notused'", 'id'); $attribute_code = $attribute->code; } if (!in_array($attribute_code, $attribute_undeletable)) { if (current_user_can('wpshop_delete_attributes')) { $_REQUEST[self::getDbTable()]['status'] = 'deleted'; } else { $actionResult = 'userNotAllowedForActionDelete'; } } else { $actionResult = 'unDeletableAtribute'; } } $actionResult = wpshop_database::update($_REQUEST[self::getDbTable()], $id, self::getDbTable()); } else { $actionResult = 'userNotAllowedForActionEdit'; } } elseif ($pageAction != '' && $pageAction == 'delete') { $attribute_code = ''; if (empty($_REQUEST[self::getDbTable()]['code'])) { $attribute = self::getElement($id, "'valid', 'moderated', 'notused', 'deleted'", 'id'); $attribute_code = $attribute->code; } if (!in_array($attribute_code, $attribute_undeletable)) { if (current_user_can('wpshop_delete_attributes')) { $_REQUEST[self::getDbTable()]['last_update_date'] = current_time('mysql', 0); $_REQUEST[self::getDbTable()]['status'] = 'deleted'; $actionResult = wpshop_database::update($_REQUEST[self::getDbTable()], $id, self::getDbTable()); } else { $actionResult = 'userNotAllowedForActionDelete'; } } else { $actionResult = 'unDeletableAtribute'; } } elseif ($pageAction != '' && ($pageAction == 'save' || $pageAction == 'saveandcontinue' || $pageAction == 'add')) { if (current_user_can('wpshop_add_attributes')) { $_REQUEST[self::getDbTable()]['creation_date'] = current_time('mysql', 0); if (trim($_REQUEST[self::getDbTable()]['code']) == '') { $_REQUEST[self::getDbTable()]['code'] = $_REQUEST[self::getDbTable()]['frontend_label']; } $_REQUEST[self::getDbTable()]['code'] = wpshop_tools::slugify(str_replace("\\'", "_", str_replace('\\"', "_", $_REQUEST[self::getDbTable()]['code'])), array('noAccent', 'noSpaces', 'lowerCase', 'noPunctuation')); $code_exists = self::getElement($_REQUEST[self::getDbTable()]['code'], "'valid', 'moderated', 'deleted'", 'code'); if ((is_object($code_exists) || is_array($code_exists)) && count($code_exists) > 0) { $_REQUEST[self::getDbTable()]['code'] = $_REQUEST[self::getDbTable()]['code'] . '_' . (count($code_exists) + rand()); } $actionResult = wpshop_database::save($_REQUEST[self::getDbTable()], self::getDbTable()); $id = $wpdb->insert_id; } else { $actionResult = 'userNotAllowedForActionAdd'; } } /* When an action is launched and there is a result message */ /************ CHANGE THE FIELD NAME TO TAKE TO DISPLAY *************/ /************ CHANGE ERROR MESSAGE FOR SPECIFIC CASE *************/ /****************************************************************************/ if ($actionResult != '') { $elementIdentifierForMessage = __('the attribute', 'wpshop'); if (!empty($_REQUEST[self::getDbTable()]['name'])) { $elementIdentifierForMessage = '<span class="bold" >' . $_REQUEST[self::getDbTable()]['frontend_label'] . '</span>'; } if ($actionResult == 'error') { /* CHANGE HERE FOR SPECIFIC CASE */ $pageMessage .= '<img src="' . WPSHOP_ERROR_ICON . '" alt="action error" class="wpshopPageMessage_Icon" />' . sprintf(__('An error occured while saving %s', 'wpshop'), $elementIdentifierForMessage, ' -> ' . $wpdb->last_error); } else { if ($actionResult == 'done' || $actionResult == 'nothingToUpdate') { /* CHANGE HERE FOR SPECIFIC CASE */ /*****************************************************************************************************************/ /************************* CHANGE FOR SPECIFIC ACTION FOR CURRENT ELEMENT ****************************/ /*****************************************************************************************************************/ /* Add the different option for the attribute that are set to combo box for frontend input */ $done_options_value = array(); $default_value = $_REQUEST[self::getDbTable()]['default_value']; $i = 1; if (!empty($_REQUEST['optionsUpdate'])) { /** * Check if there is an attribute code into sended request or if we have to get the code from database (Bug fix) */ if (empty($_REQUEST[self::getDbTable()]['code'])) { $attribute = self::getElement($id, "'valid', 'moderated', 'notused'", 'id'); $attribute_code = $attribute->code; } else { $attribute_code = $_REQUEST[self::getDbTable()]['code']; } foreach ($_REQUEST['optionsUpdate'] as $option_key => $option_label) { $option_value = !empty($_REQUEST['optionsUpdateValue'][$option_key]) ? str_replace(",", ".", $_REQUEST['optionsUpdateValue'][$option_key]) : ''; if (empty($option_value) || !in_array($option_value, $done_options_value)) { /* Update an existing value only if the value does not exist into existing list */ $label = $option_label != '' ? $option_label : str_replace(",", ".", $option_value); $value = str_replace(",", ".", $option_value); if (!WPSHOP_DISPLAY_VALUE_FOR_ATTRIBUTE_SELECT) { $label = $option_label; $value = str_replace(",", ".", $label); } $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)); $done_options_value[] = str_replace(",", ".", $option_value); /* Check if this value is used for price calculation and make update on the different product using this value */ if ($attribute_code == WPSHOP_PRODUCT_PRICE_TAX) { $action = wpshop_prices::mass_update_prices(); } } if ($default_value == $option_key) { /* Update an existing a only if the value does not exist into existing list */ $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('last_update_date' => current_time('mysql', 0), 'default_value' => $option_key), array('id' => $id)); $done_options_value[] = str_replace(",", ".", $option_value); } $i++; } } if (!empty($_REQUEST['options'])) { foreach ($_REQUEST['options'] as $option_key => $option_label) { $option_value = !empty($_REQUEST['optionsValue'][$option_key]) ? str_replace(",", ".", $_REQUEST['optionsValue'][$option_key]) : sanitize_title($option_label); /* Check what value to use for the new values */ $label = !empty($option_label) ? $option_label : str_replace(",", ".", $option_value); if (!WPSHOP_DISPLAY_VALUE_FOR_ATTRIBUTE_SELECT && empty($option_value)) { $label = $option_label; $option_value = sanitize_title($label); } // If the optionsUpdateValue is empty, set it a empty array to avoid error calling the in_array() function $_REQUEST['optionsUpdateValue'] = !empty($_REQUEST['optionsUpdateValue']) ? $_REQUEST['optionsUpdateValue'] : array(); if (!in_array($option_value, $done_options_value) && !in_array($option_value, $_REQUEST['optionsUpdateValue'])) { $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))); $done_options_value[] = str_replace(",", ".", $option_value); $last_insert_id = $wpdb->insert_id; if (empty($default_value)) { /* Update an existing a only if the value does not exist into existing list */ $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('last_update_date' => current_time('mysql', 0), 'default_value' => $last_insert_id), array('id' => $id)); $done_options_value[] = str_replace(",", ".", $option_value); } } $i++; } } // If the is_used_for_sort_by is mark as yes, we have to get out some attributes and save it separately if (!empty($_REQUEST[self::getDbTable()]['is_used_for_sort_by']) && $_REQUEST[self::getDbTable()]['is_used_for_sort_by'] == 'yes' || !empty($_REQUEST[self::getDbTable()]['is_filterable']) && $_REQUEST[self::getDbTable()]['is_filterable'] == 'yes' || !empty($_REQUEST[self::getDbTable()]['is_searchable']) && $_REQUEST[self::getDbTable()]['is_searchable'] == 'yes') { $attribute_code = $_REQUEST[self::getDbTable()]['code']; if (!isset($_REQUEST[self::getDbTable()]['code']) || $_REQUEST[self::getDbTable()]['code'] == '') { $attribute = self::getElement($id, "'valid', 'moderated', 'notused'", 'id'); $attribute_code = $attribute->code; } $count_products = wp_count_posts(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); for ($i = 0; $i <= $count_products->publish; $i += 20) { $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'); $products = $wpdb->get_results($query); if (!empty($products)) { foreach ($products as $product) { $query = $wpdb->prepare("SELECT value FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . $_REQUEST[self::getDbTable()]['data_type'] . " WHERE attribute_id = %d AND entity_type_id = %d AND entity_id = %d AND value != '' ORDER BY creation_date_value DESC", $id, $_REQUEST[self::getDbTable()]['entity_id'], $product->ID); $value = $wpdb->get_var($query); update_post_meta($product->ID, '_' . $attribute_code, $value); } } } wp_reset_query(); } if ($pageAction != 'delete') { /* Add the new attribute in the additionnal informations attribute group */ if (!empty($set_section)) { $choosen_set_section = explode('_', $set_section); $set_id = $choosen_set_section[0]; $group_id = $choosen_set_section[1]; } else { $attribute_current_attribute_set = 0; $query = $wpdb->prepare("\r\n\t\t\t\t\t\t\t\tSELECT id\r\n\t\t\t\t\t\t\t\tFROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " AS ATTRIBUTE_SET_DETAILS\r\n\t\t\t\t\t\t\t\tWHERE ATTRIBUTE_SET_DETAILS.status = 'valid'\r\n\t\t\t\t\t\t\t\t\tAND ATTRIBUTE_SET_DETAILS.attribute_id = %d\r\n\t\t\t\t\t\t\t\t\tAND ATTRIBUTE_SET_DETAILS.entity_type_id = %d", $id, $_REQUEST[self::getDbTable()]['entity_id']); $attribute_current_attribute_set = $wpdb->get_results($query); if (empty($attribute_current_attribute_set)) { $query = $wpdb->prepare("\r\n\t\t\t\t\t\t\t\tSELECT\r\n\t\t\t\t\t\t\t\t\t(\r\n\t\t\t\t\t\t\t\t\t\tSELECT ATTRIBUTE_SET.id\r\n\t\t\t\t\t\t\t\t\t\tFROM " . WPSHOP_DBT_ATTRIBUTE_SET . " AS ATTRIBUTE_SET\r\n\t\t\t\t\t\t\t\t\t\tWHERE ATTRIBUTE_SET.entity_id = %d\r\n\t\t\t\t\t\t\t\t\t\t\tAND ATTRIBUTE_SET.default_set = 'yes'\r\n\t\t\t\t\t\t\t\t\t) AS attribute_set_id,\r\n\t\t\t\t\t\t\t\t\t(\r\n\t\t\t\t\t\t\t\t\t\tSELECT ATTRIBUTE_GROUP.id\r\n\t\t\t\t\t\t\t\t\t\tFROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " AS ATTRIBUTE_GROUP\r\n\t\t\t\t\t\t\t\t\t\tINNER JOIN " . WPSHOP_DBT_ATTRIBUTE_SET . " AS ATTRIBUTE_SET ON ((ATTRIBUTE_SET.id = ATTRIBUTE_GROUP.attribute_set_id) AND (ATTRIBUTE_SET.entity_id = %d))\r\n\t\t\t\t\t\t\t\t\t\tWHERE ATTRIBUTE_GROUP.default_group = 'yes'\r\n\t\t\t\t\t\t\t\t\t\t\tAND ATTRIBUTE_GROUP.status = 'valid'\r\n\t\t\t\t\t\t\t\t\t) AS attribute_group_id", $_REQUEST[self::getDbTable()]['entity_id'], $_REQUEST[self::getDbTable()]['entity_id'], $_REQUEST[self::getDbTable()]['entity_id'], $_REQUEST[self::getDbTable()]['entity_id']); $wpshop_default_group = $wpdb->get_row($query); $set_id = $wpshop_default_group->attribute_set_id; $default_group_id = !empty($wpshop_default_group->default_attribute_group_id) ? $wpshop_default_group->default_attribute_group_id : ''; $group_id = !empty($default_group_id) ? $default_group_id : $wpshop_default_group->attribute_group_id; } } if (!empty($set_id) && !empty($group_id)) { $query = $wpdb->prepare("SELECT (MAX(position) + 1) AS position\r\n\t\t\t\t\t\t\t\tFROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . "\r\n\t\t\t\t\t\t\t\tWHERE attribute_set_id = %s\r\n\t\t\t\t\t\t\t\tAND attribute_group_id = %s\r\n\t\t\t\t\t\t\t\tAND entity_type_id = %s ", $set_id, $group_id, $_REQUEST[self::getDbTable()]['entity_id']); $wpshopAttributePosition = $wpdb->get_var($query); if ($wpshopAttributePosition == 0) { $wpshopAttributePosition = 1; } $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $_REQUEST[self::getDbTable()]['entity_id'], 'attribute_set_id' => $set_id, 'attribute_group_id' => $group_id, 'attribute_id' => $id, 'position' => $wpshopAttributePosition)); } } if (!empty($wpshop_attribute_combo_values_list_order_def)) { $post_order = explode(',', $wpshop_attribute_combo_values_list_order_def); $position = 1; foreach ($post_order as $post_id) { $wpdb->update($wpdb->posts, array('menu_order' => $position), array('ID' => str_replace('post_', '', $post_id))); $position++; } } /************************* GENERIC ****************************/ /*************************************************************************/ $pageMessage .= '<img src="' . WPSHOP_SUCCES_ICON . '" alt="action success" class="wpshopPageMessage_Icon" />' . sprintf(__('%s succesfully saved', 'wpshop'), $elementIdentifierForMessage); /* if(($pageAction == 'edit') || ($pageAction == 'save')){ wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . self::getListingSlug() . "&action=saveok&saveditem=" . $id)); } else */ if ($pageAction == 'add') { wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . self::getListingSlug() . "&action=edit&id=" . $id)); } elseif ($pageAction == 'delete') { wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . self::getListingSlug() . "&action=deleteok&saveditem=" . $id)); } } elseif ($actionResult == 'userNotAllowedForActionEdit' || $actionResult == 'userNotAllowedForActionAdd' || $actionResult == 'userNotAllowedForActionDelete') { $pageMessage .= '<img src="' . WPSHOP_ERROR_ICON . '" alt="action error" class="wpshopPageMessage_Icon" />' . __('You are not allowed to do this action', 'wpshop'); } elseif ($actionResult == 'unDeletableAtribute') { $pageMessage .= '<img src="' . WPSHOP_ERROR_ICON . '" alt="action error" class="wpshopPageMessage_Icon" />' . __('This attribute could not be deleted due to configuration', 'wpshop'); } } if (empty($_REQUEST[self::getDbTable()]['frontend_label']) && $pageAction != 'delete') { $pageMessage .= __('Please enter an label for the attribut', 'wpshop'); } } self::setMessage($pageMessage); }
function wps_update_products_prices() { $action = wpshop_prices::mass_update_prices(); $response = array('status' => $action[0], 'response' => $action[1]); echo json_encode($response); die; }
/** * Build an array with the different items to add to an order * * @param array $products The item list to add to the order * * @return array $item_list The item to add to order */ function add_product_to_order($product) { global $wpdb; if (!empty($product) && empty($product['price_ttc_before_discount']) && empty($product['price_ht_before_discount'])) { $price_infos = wpshop_prices::check_product_price($product, true); $product['price_ht'] = !empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist'] ? $price_infos['discount']['discount_et_price'] : $price_infos['et']; $product['product_price'] = !empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist'] ? $price_infos['discount']['discount_ati_price'] : $price_infos['ati']; $product['tva'] = !empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist'] ? $price_infos['discount']['discount_tva'] : $price_infos['tva']; } $price_piloting = get_option('wpshop_shop_price_piloting'); if (!empty($price_piloting) && $price_piloting == 'HT') { $total_ht = $product['price_ht'] * $product['product_qty']; $tva_total_amount = $total_ht * ($product['tx_tva'] / 100); $total_ttc = $total_ht + $tva_total_amount; } else { $total_ttc = $product['product_price'] * $product['product_qty']; $total_ht = $total_ttc / (1 + $product['tx_tva'] / 100); $tva_total_amount = $total_ttc - $total_ht; } $tva = !empty($product[WPSHOP_PRODUCT_PRICE_TAX]) ? $product[WPSHOP_PRODUCT_PRICE_TAX] : null; $item_discount_type = $item_discount_value = $item_discount_amount = 0; $d_amount = !empty($product) && !empty($product['discount_amount']) ? wpshop_tools::formate_number($product['discount_amount']) : null; $d_rate = !empty($product) && !empty($product['discount_rate']) ? wpshop_tools::formate_number($product['discount_rate']) : null; $d_special = !empty($product) && !empty($product['special_price']) ? wpshop_tools::formate_number($product['special_price']) : null; if (!empty($d_amount)) { $item_discount_type = 'discount_amount'; $item_discount_amount = $product['discount_amount']; $item_discount_value = $product['discount_amount']; } elseif (!empty($d_rate)) { $item_discount_type = 'discount_rate'; $item_discount_amount = $product['discount_rate']; $item_discount_value = $product['discount_rate']; } elseif (!empty($d_special)) { $item_discount_type = 'special_price'; $item_discount_amount = $product['special_price']; $item_discount_value = $product['special_price']; } $item = array('item_id' => $product['product_id'], 'item_ref' => !empty($product['product_reference']) ? $product['product_reference'] : null, 'item_name' => !empty($product['product_name']) ? $product['product_name'] : 'wpshop_product_' . $product['product_id'], 'item_qty' => $product['product_qty'], 'item_pu_ht' => $product['price_ht'], 'item_pu_ttc' => $product['product_price'], 'item_ecotaxe_ht' => 0, 'item_ecotaxe_tva' => 19.6, 'item_ecotaxe_ttc' => 0, 'item_discount_type' => $item_discount_type, 'item_discount_value' => $item_discount_value, 'item_discount_amount' => $item_discount_amount, 'item_tva_rate' => $tva, 'item_tva_amount' => $product['tva'], 'item_total_ht' => $total_ht, 'item_tva_total_amount' => $tva_total_amount, 'item_total_ttc' => $total_ttc, 'item_meta' => !empty($product['item_meta']) ? $product['item_meta'] : array()); $array_not_to_do = array(WPSHOP_PRODUCT_PRICE_HT, WPSHOP_PRODUCT_PRICE_TTC, WPSHOP_PRODUCT_PRICE_TAX_AMOUNT, 'product_qty', WPSHOP_PRODUCT_PRICE_TAX, 'product_id', 'product_reference', 'product_name', 'variations'); if (!empty($product['item_meta'])) { foreach ($product['item_meta'] as $key => $value) { if (!isset($item['item_' . $key]) && !in_array($key, $array_not_to_do) && !empty($product[$key])) { $item['item_' . $key] = $product[$key]; } } } /** Check if it's a variation product **/ if (!empty($product) && !empty($product['item_meta']) && !empty($product['item_meta']['variations'])) { foreach ($product['item_meta']['variations'] as $k => $variation) { $product_variation_def = get_post_meta($k, '_wpshop_variations_attribute_def', true); if (!empty($product_variation_def)) { foreach ($product_variation_def as $attribute_code => $variation_id) { $variation_attribute_def = wpshop_attributes::getElement($attribute_code, '"valid"', 'code'); if (!empty($variation_attribute_def)) { $item['item_meta']['variation_definition'][$attribute_code]['NAME'] = $variation_attribute_def->frontend_label; if ($variation_attribute_def->data_type_to_use == 'custom') { $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id=%d', $variation_id); $variation_name = $wpdb->get_var($query); } else { $variation_post = get_post($variation_id); $variation_name = $variation_post->post_title; } $item['item_meta']['variation_definition'][$attribute_code]['UNSTYLED_VALUE'] = $variation_name; $item['item_meta']['variation_definition'][$attribute_code]['VALUE'] = $variation_name; } } } } } else { /** Check if it's product with one variation **/ $product_variation_def = get_post_meta($product['product_id'], '_wpshop_variations_attribute_def', true); if (!empty($product_variation_def)) { foreach ($product_variation_def as $attribute_code => $variation_id) { $variation_attribute_def = wpshop_attributes::getElement($attribute_code, '"valid"', 'code'); if (!empty($variation_attribute_def)) { $item['item_meta']['variation_definition'][$attribute_code]['NAME'] = $variation_attribute_def->frontend_label; if ($variation_attribute_def->data_type_to_use == 'custom') { $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id=%d', $variation_id); $variation_name = $wpdb->get_var($query); } else { $variation_post = get_post($variation_id); $variation_name = $variation_post->post_title; } $item['item_meta']['variation_definition'][$attribute_code]['UNSTYLED_VALUE'] = $variation_name; $item['item_meta']['variation_definition'][$attribute_code]['VALUE'] = $variation_name; } } } } return $item; }
/** * Define custom columns content display in post_type page for wpshop entities * * @param string $columns The default column for the post_type given in second parameter * @param integer $post_id The current post identifier to get information for display */ public static function custom_columns_content($column, $post_id) { $post_type = get_post_type($post_id); switch ($post_type) { case WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT: $column_content = '<strong>-</strong>'; $product = wpshop_products::get_product_data($post_id); switch ($column) { case 'picture': $column_content = get_the_post_thumbnail($post_id, 'thumbnail'); break; case "product_stock": if (!empty($product['product_stock'])) { $column_content = (int) $product['product_stock'] . ' ' . __('unit(s)', 'wpshop'); } break; case "product_price": if (!empty($product['product_price'])) { $column_content = wpshop_prices::get_product_price($product, 'price_display', 'complete_sheet'); } break; case "tx_tva": if (!empty($product['product_price'])) { $column_content = number_format($product[$column], 2, '.', ' ') . ' %'; } break; default: if (!empty($product[$column])) { $attribute_prices = unserialize(WPSHOP_ATTRIBUTE_PRICES); if (in_array($column, $attribute_prices)) { $column_content = number_format($product[$column], 2, '.', ' ') . ' ' . wpshop_tools::wpshop_get_currency(); } else { $column_content = $product[$column]; } } break; } break; default: $column_content = ''; break; } echo $column_content; }
/** * Manage special operation on wpshop plugin update */ public static function make_specific_operation_on_update($version) { global $wpdb, $wp_rewrite; $wpshop_shop_type = get_option('wpshop_shop_type', WPSHOP_DEFAULT_SHOP_TYPE); switch ($version) { case 3: case 6: self::wpshop_insert_default_pages($wpshop_shop_type); wp_cache_flush(); return true; break; case 8: /** Change metaboxes order for product in case it already exists */ $query = $wpdb->prepare("SELECT umeta_id, meta_value FROM {$wpdb->usermeta} WHERE meta_key = %s", 'meta-box-order_wpshop_product'); $customer_metaboxes_order = $wpdb->get_results($query); if (!empty($customer_metaboxes_order)) { foreach ($customer_metaboxes_order as $customer_metabox_order) { $do_changes = false; $current_order = unserialize($customer_metabox_order->meta_value); if (array_key_exists('normal', $current_order) && false !== strpos('wpshop_product_important_datas', $current_order['normal'])) { str_replace('wpshop_product_important_datas,', '', $current_order['normal']); $do_changes = true; } if (array_key_exists('side', $current_order)) { str_replace('wpshop_product_important_datas,', '', $current_order['side']); str_replace('submitdiv,', 'submitdiv,wpshop_product_important_datas,', $current_order['side']); $do_changes = true; } if (true === $do_changes) { $wpdb->update($wpdb->usermeta, array('meta_value' => serialize($current_order)), array('umeta_id' => $customer_metabox_order->umeta_id)); } } } else { $users = get_users(array('role' => 'administrator')); if (!empty($users)) { foreach ($users as $user) { $user_meta = array('side' => 'submitdiv,formatdiv,wpshop_product_important_datas,wpshop_product_categorydiv,pageparentdiv,wps_barcode_product,wpshop_product_actions,wpshop_product_options,postimagediv', 'normal' => 'wpshop_product_fixed_tab,postexcerpt,trackbacksdiv,postcustom,commentstatusdiv,slugdiv,authordiv,wpshop_wpshop_variations,wps_media_manager,wpshop_product_order_historic', 'advanced' => ''); update_user_meta($user->ID, 'meta-box-order_wpshop_product', $user_meta); } } } /* Update the product prices into database */ $query = $wpdb->prepare("\nSELECT\n(SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s) AS product_price,\n(SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s) AS price_ht,\n(SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s) AS tx_tva,\n(SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s) AS tva", 'product_price', 'price_ht', 'tx_tva', 'tva'); $product_prices = $wpdb->get_row($query); $tax_id = $wpdb->get_var($wpdb->prepare("SELECT ATT_OPT.id FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " AS ATT_OPT WHERE attribute_id = %d AND value = '20'", $product_prices->tx_tva)); $query = $wpdb->prepare("SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL . " WHERE attribute_id = %d", $product_prices->product_price); $price_list = $wpdb->get_results($query); foreach ($price_list as $existing_ttc_price) { $tax_rate = 1.2; $price_ht = $existing_ttc_price->value / $tax_rate; $tax_amount = $existing_ttc_price->value - $price_ht; $wpdb->replace(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('entity_type_id' => $existing_ttc_price->entity_type_id, 'attribute_id' => $product_prices->price_ht, 'entity_id' => $existing_ttc_price->entity_id, 'unit_id' => $existing_ttc_price->unit_id, 'user_id' => $existing_ttc_price->user_id, 'language' => $existing_ttc_price->language, 'value' => $price_ht, 'creation_date_value' => current_time('mysql', 0))); $wpdb->replace(WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER, array('entity_type_id' => $existing_ttc_price->entity_type_id, 'attribute_id' => $product_prices->tx_tva, 'entity_id' => $existing_ttc_price->entity_id, 'unit_id' => $existing_ttc_price->unit_id, 'user_id' => $existing_ttc_price->user_id, 'language' => $existing_ttc_price->language, 'value' => $tax_id, 'creation_date_value' => current_time('mysql', 0))); $wpdb->replace(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('entity_type_id' => $existing_ttc_price->entity_type_id, 'attribute_id' => $product_prices->tva, 'entity_id' => $existing_ttc_price->entity_id, 'unit_id' => $existing_ttc_price->unit_id, 'user_id' => $existing_ttc_price->user_id, 'language' => $existing_ttc_price->language, 'value' => $tax_amount, 'creation_date_value' => current_time('mysql', 0))); } /* Update orders structure into database */ $orders_id = $wpdb->get_results('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = "' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER . '"'); foreach ($orders_id as $o) { $myorder = get_post_meta($o->ID, '_order_postmeta', true); $neworder = array(); $items = array(); if (!isset($myorder['order_tva'])) { $order_total_ht = 0; $order_total_ttc = 0; $order_tva = array('20' => 0); foreach ($myorder['order_items'] as $item) { /* item */ $pu_ht = $item['cost'] / 1.2; $pu_tva = $item['cost'] - $pu_ht; $total_ht = $pu_ht * $item['qty']; $tva_total_amount = $pu_tva * $item['qty']; $total_ttc = $item['cost'] * $item['qty']; /* item */ $order_total_ht += $total_ht; $order_total_ttc += $total_ttc; $order_tva['20'] += $tva_total_amount; $items[] = array('item_id' => $item['id'], 'item_ref' => 'Nc', 'item_name' => $item['name'], 'item_qty' => $item['qty'], 'item_pu_ht' => number_format($pu_ht, 2, '.', ''), 'item_pu_ttc' => number_format($item['cost'], 2, '.', ''), 'item_ecotaxe_ht' => number_format(0, 2, '.', ''), 'item_ecotaxe_tva' => 20, 'item_ecotaxe_ttc' => number_format(0, 2, '.', ''), 'item_discount_type' => 0, 'item_discount_value' => 0, 'item_discount_amount' => number_format(0, 2, '.', ''), 'item_tva_rate' => 20, 'item_tva_amount' => number_format($pu_tva, 2, '.', ''), 'item_total_ht' => number_format($total_ht, 2, '.', ''), 'item_tva_total_amount' => number_format($tva_total_amount, 2, '.', ''), 'item_total_ttc' => number_format($total_ttc, 2, '.', '')); } $neworder = array('order_key' => $myorder['order_key'], 'customer_id' => $myorder['customer_id'], 'order_status' => $myorder['order_status'], 'order_date' => $myorder['order_date'], 'order_payment_date' => $myorder['order_payment_date'], 'order_shipping_date' => $myorder['order_shipping_date'], 'payment_method' => $myorder['payment_method'], 'order_invoice_ref' => '', 'order_currency' => $myorder['order_currency'], 'order_total_ht' => $order_total_ht, 'order_total_ttc' => $order_total_ttc, 'order_grand_total' => $order_total_ttc, 'order_shipping_cost' => number_format(0, 2, '.', ''), 'order_tva' => array_map(array('wpshop_tools', 'number_format_hack'), $order_tva), 'order_items' => $items); /* Update the order postmeta */ update_post_meta($o->ID, '_order_postmeta', $neworder); } } self::wpshop_insert_default_pages($wpshop_shop_type); wp_cache_flush(); return true; break; case 12: $query = "SELECT ID FROM " . $wpdb->users; $user_list = $wpdb->get_results($query); foreach ($user_list as $user) { $user_first_name = get_user_meta($user->ID, 'first_name', true); $user_last_name = get_user_meta($user->ID, 'last_name', true); $shipping_info = get_user_meta($user->ID, 'shipping_info', true); if ($user_first_name == '' && !empty($shipping_info['first_name'])) { update_user_meta($user->ID, 'first_name', $shipping_info['first_name']); } if ($user_last_name == '' && !empty($shipping_info['last_name'])) { update_user_meta($user->ID, 'last_name', $shipping_info['last_name']); } } /* Update orders structure into database */ $orders_id = $wpdb->get_results('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = "' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER . '"'); foreach ($orders_id as $o) { $myorder = get_post_meta($o->ID, '_order_postmeta', true); if (!empty($myorder)) { $new_items = array(); foreach ($myorder['order_items'] as $item) { $new_items = $item; $new_items['item_discount_type'] = !empty($item['item_discount_rate']) ? $item['item_discount_rate'] : 'amount'; // unset($new_items['item_discount_rate']); $new_items['item_discount_value'] = 0; } $myorder['order_items'] = $new_items; /* Update the order postmeta */ update_post_meta($o->ID, '_order_postmeta', $myorder); } } /* Delete useless database table */ $query = "DROP TABLE " . WPSHOP_DBT_CART; $wpdb->query($query); $query = "DROP TABLE " . WPSHOP_DBT_CART_CONTENTS; $wpdb->query($query); return true; break; case 13: $attribute_used_for_sort_by = wpshop_attributes::getElement('yes', "'valid', 'moderated', 'notused'", 'is_used_for_sort_by', true); foreach ($attribute_used_for_sort_by as $attribute) { $data = query_posts(array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT)); foreach ($data as $post) { $postmeta = get_post_meta($post->ID, '_wpshop_product_metadata', true); if (!empty($postmeta[$attribute->code])) { update_post_meta($post->ID, '_' . $attribute->code, $postmeta[$attribute->code]); } } wp_reset_query(); } return true; break; case 17: $products = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT)); $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE default_set = %s", 'yes'); $default_attribute_set = $wpdb->get_var($query); foreach ($products as $product) { $p_att_set_id = get_post_meta($product->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true); if (empty($p_att_set_id)) { /* Update the attribute set id for the current product */ update_post_meta($product->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, $default_attribute_set); } wp_reset_query(); } self::wpshop_insert_default_pages($wpshop_shop_type); wp_cache_flush(); return true; break; case 18: self::wpshop_insert_default_pages($wpshop_shop_type); wp_cache_flush(); return true; break; case 19: $wp_rewrite->flush_rules(); return true; break; case 21: /** * Correction des valeurs pour l'attributs "gestion du stock" qui n'�taient pas cr�es automatiquement */ $query = $wpdb->prepare("SELECT ATTR_OPT.id, ATTR_OPT.value, ATTR_OPT.label, ATTR_OPT.position, ATTR_OPT.attribute_id FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " AS ATTR_OPT INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATTR ON (ATTR.id = ATTR_OPT.attribute_id) WHERE ATTR_OPT.status=%s AND ATTR.code=%s", 'valid', 'manage_stock'); $manage_stock_option = $wpdb->get_results($query); if (!empty($manage_stock_option)) { $no_is_present = false; $attribute_id = $manage_stock_option[0]->attribute_id; foreach ($manage_stock_option as $manage_definition) { if (strtolower(__($manage_definition->value, 'wpshop')) == strtolower(__('no', 'wpshop'))) { $no_is_present = true; } } if (!$no_is_present) { $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'last_update_date' => current_time('mysql', 0), 'attribute_id' => $attribute_id, 'value' => 'no', 'label' => __('No', 'wpshop'))); } } /** Change price attribute set section order for default set */ $price_tab = unserialize(WPSHOP_ATTRIBUTE_PRICES); unset($price_tab[array_search(WPSHOP_COST_OF_POSTAGE, $price_tab)]); $query = "SELECT GROUP_CONCAT(id) FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code IN ('" . implode("','", $price_tab) . "')"; $attribute_ids = $wpdb->get_var($query); $query = $wpdb->prepare("\nSELECT ATTR_DET.attribute_group_id\nFROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " AS ATTR_DET\n\tINNER JOIN " . WPSHOP_DBT_ATTRIBUTE_GROUP . " AS ATTR_GROUP ON ((ATTR_GROUP.id = ATTR_DET.attribute_group_id) AND (ATTR_GROUP.code = %s))\n\tINNER JOIN " . WPSHOP_DBT_ATTRIBUTE_SET . " AS ATTR_SET ON ((ATTR_SET.id = ATTR_GROUP.attribute_set_id) AND (ATTR_SET.name = %s))\nWHERE ATTR_DET.attribute_id IN (" . $attribute_ids . ")", 'prices', __('default', 'wpshop')); $list = $wpdb->get_results($query); if (!empty($list)) { $change_order = true; $old_value = $list[0]->attribute_group_id; unset($list[0]); if (!empty($list)) { foreach ($list as $data) { if ($old_value != $data->attribute_group_id) { $change_order = false; } } if ($change_order) { foreach ($price_tab as $price_code) { $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s", $price_code); $attribute_id = $wpdb->get_var($query); switch ($price_code) { case WPSHOP_PRODUCT_PRICE_HT: $position = WPSHOP_PRODUCT_PRICE_PILOT == 'HT' ? 1 : 3; break; case WPSHOP_PRODUCT_PRICE_TAX: $position = 2; break; case WPSHOP_PRODUCT_PRICE_TTC: $position = WPSHOP_PRODUCT_PRICE_PILOT == 'HT' ? 3 : 1; break; case WPSHOP_PRODUCT_PRICE_TAX_AMOUNT: $position = 4; break; } $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'last_update_date' => current_time('mysql', 0), 'position' => $position), array('attribute_group_id' => $old_value, 'attribute_id' => $attribute_id)); } } } } return true; break; case 22: $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_name = %s", WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); $product_entity_id = $wpdb->get_var($query); if (empty($product_entityd_id) || $product_entity_id <= 0 || !$product_entity_id) { /* Create the product entity into post table */ $product_entity = array('post_title' => __('Products', 'wpshop'), 'post_name' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'post_content' => __('Define the entity allowing to manage product on your store. If you delete this entity you won\'t be able to manage your store', 'wpshop'), 'post_status' => 'publish', 'post_author' => 1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES); $product_entity_id = wp_insert_post($product_entity); } /* Update eav table with the new entity id for product */ $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('entity_id' => $product_entity_id), array('entity_id' => 1)); $wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, array('entity_id' => $product_entity_id), array('entity_id' => 1)); $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1)); $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DATETIME, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1)); $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1)); $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1)); $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1)); $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1)); $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1)); /* Create an element of customer entity for each existing user */ $user_list = get_users(); foreach ($user_list as $user) { wps_customer_ctr::create_entity_customer_when_user_is_created($user->ID); } return true; break; case 23: /* Delete duplicate entities */ $query = "SELECT ID FROM " . $wpdb->posts . " WHERE post_name LIKE '%" . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . "%' "; $product_entity_list = $wpdb->get_results($query); if (count($product_entity_list) > 1) { $i = 0; foreach ($product_entity_list as $product_entity) { if ($i > 0) { wp_delete_post($product_entity->ID); } } } return true; break; case 24: /* Update the link status for disabled attribute set */ $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE status = %s", 'deleted'); $deleted_attribute_group = $wpdb->get_results($query); if (!empty($deleted_attribute_group)) { foreach ($deleted_attribute_group as $group) { $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'deleted', 'last_update_date' => current_time('mysql', 0)), array('attribute_group_id' => $group->id)); } } /* Update entities meta management */ $entities = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES)); if (!empty($entities)) { foreach ($entities as $entity) { $support = get_post_meta($entity->ID, '_wpshop_entity_support', true); $rewrite = get_post_meta($entity->ID, '_wpshop_entity_rewrite', true); update_post_meta($entity->ID, '_wpshop_entity_params', array('support' => $support, 'rewrite' => array('slug' => $rewrite))); } } wp_reset_query(); return true; break; case 25: /* Get the first entities of product and customer */ $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_name=%s AND post_type=%s ORDER BY ID ASC LIMIT 1", WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES); $product_entity_id = $wpdb->get_var($query); /* Update attributes that are not linked with entities */ $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('entity_id' => $product_entity_id), array('entity_id' => 0)); /* Get entities that have been created a lot of time and delete them */ $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE (post_name LIKE '%%" . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . "-%%' OR post_name LIKE '%%" . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . "-%%') AND post_type=%s", WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES); $entities_to_delete = $wpdb->get_results($query); if (!empty($entities_to_delete) && is_array($entities_to_delete)) { foreach ($entities_to_delete as $entity) { wp_delete_post($entity->ID, true); } } /* Get post list that are children of entities created a lot of time */ $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_type LIKE %s", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . "-%"); $entities_to_update = $wpdb->get_results($query); if (!empty($entities_to_update) && is_array($entities_to_update)) { foreach ($entities_to_update as $entity) { wp_update_post(array('ID' => $entity->ID, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS)); } } $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_type LIKE %s", WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . "-%"); $entities_to_update = $wpdb->get_results($query); if (!empty($entities_to_update) && is_array($entities_to_update)) { foreach ($entities_to_update as $entity) { wp_update_post(array('ID' => $entity->ID, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT)); } } /* Change addons managament */ $wpshop_addons_options = get_option('wpshop_addons_state', array()); if (!empty($wpshop_addons_options)) { foreach ($wpshop_addons_options as $addon_name => $addon_state) { $options_args = array(); $options_args[$addon_name]['activate'] = $addon_state; $options_args[$addon_name]['activation_date'] = current_time('mysql', 0); if (!$addon_state) { $options_args[$addon_name]['deactivation_date'] = current_time('mysql', 0); } add_option(WPSHOP_ADDONS_OPTION_NAME, $options_args); } delete_option('wpshop_addons_state'); } /* Update the different entities id into attribute set details table */ $query = "UPDATE " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " AS ATT_DET INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON (ATT.id = ATT_DET.attribute_id) SET ATT_DET.entity_type_id = ATT.entity_id"; $wpdb->query($query); return true; break; case 26: $query = "SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = '_order_postmeta' "; $results = $wpdb->get_results($query); foreach ($results as $result) { $order_info = unserialize($result->meta_value); update_post_meta($result->post_id, '_wpshop_order_customer_id', $order_info['customer_id']); update_post_meta($result->post_id, '_wpshop_order_shipping_date', $order_info['order_shipping_date']); update_post_meta($result->post_id, '_wpshop_order_status', $order_info['order_status']); } /* Update the different entities id into attribute set details table */ $query = "UPDATE " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " AS ATT_DET INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON (ATT.id = ATT_DET.attribute_id) SET ATT_DET.entity_type_id = ATT.entity_id"; $wpdb->query($query); return true; break; case 29: $billing_title = __('Billing address', 'wpshop'); $shipping_title = __('Shipping address', 'wpshop'); //UPDATE USERS ADDRESSES $billing_address_set_id_query = 'SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE name = "' . $billing_title . '"'; $shipping_address_set_id_query = 'SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE name = "' . $shipping_title . '"'; $billing_address_set_id = $wpdb->get_var($billing_address_set_id_query); $shipping_address_set_id = $wpdb->get_var($shipping_address_set_id_query); //Add Address & Google Map API KEY options add_option('wpshop_billing_address', array('choice' => $billing_address_set_id), '', 'yes'); add_option('wpshop_shipping_address_choice', array('activate' => 'on', 'choice' => $shipping_address_set_id), '', 'yes'); add_option('wpshop_google_map_api_key', '', '', 'yes'); $query = 'SELECT * FROM ' . $wpdb->users . ''; $results = $wpdb->get_results($query); foreach ($results as $result) { $billing_infos = get_user_meta($result->ID, 'billing_info', true); $shipping_infos = get_user_meta($result->ID, 'shipping_info', true); if (!empty($billing_infos)) { //Save Billing Infos $billing_address = array(); if (!empty($billing_infos['civility'])) { switch ($billing_infos['civility']) { case 1: $civility = $mister_id; break; case 2: $civility = $madam_id; break; case 3: $civility = $miss_id; break; } } else { $civility = $mister_id; } $billing_address = array('address_title' => $billing_title, 'address_last_name' => !empty($billing_infos['last_name']) ? $billing_infos['last_name'] : '', 'address_first_name' => !empty($billing_infos['first_name']) ? $billing_infos['first_name'] : '', 'company' => !empty($billing_infos['company']) ? $billing_infos['company'] : '', 'address' => !empty($billing_infos['address']) ? $billing_infos['address'] : '', 'postcode' => !empty($billing_infos['postcode']) ? $billing_infos['postcode'] : '', 'city' => !empty($billing_infos['city']) ? $billing_infos['city'] : '', 'state' => !empty($billing_infos['state']) ? $billing_infos['state'] : '', 'country' => !empty($billing_infos['country']) ? $billing_infos['country'] : '', 'address_user_email' => !empty($billing_infos['email']) ? $billing_infos['email'] : '', 'phone' => !empty($billing_infos['phone']) ? $billing_infos['phone'] : '', 'tva_intra' => !empty($billing_infos['company_tva_intra']) ? $billing_infos['company_tva_intra'] : '', 'civility' => $civility); //Create the post and post_meta for the billing address $post_address = array('post_author' => $result->ID, 'post_title' => $billing_title, 'post_status' => 'publish', 'post_name' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, 'post_parent' => $result->ID); $post_address_id = wp_insert_post($post_address); //Create the post_meta with the address infos update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_metadata', $billing_address); update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_attribute_set_id', $billing_address_set_id); } if (!empty($shipping_infos)) { //Save Shipping Infos if (!empty($shipping_infos['civility'])) { switch ($shipping_infos['civility']) { case 1: $civility = $mister_id; break; case 2: $civility = $madam_id; break; case 3: $civility = $miss_id; break; } } else { $civility = $mister_id; } $shipping_address = array(); $shipping_address = array('address_title' => $shipping_title, 'address_last_name' => !empty($shipping_infos['last_name']) ? $shipping_infos['last_name'] : '', 'address_first_name' => !empty($shipping_infos['first_name']) ? $shipping_infos['first_name'] : '', 'company' => !empty($shipping_infos['company']) ? $shipping_infos['company'] : '', 'address' => !empty($shipping_infos['address']) ? $shipping_infos['address'] : '', 'postcode' => !empty($shipping_infos['postcode']) ? $shipping_infos['postcode'] : '', 'city' => !empty($shipping_infos['city']) ? $shipping_infos['city'] : '', 'state' => !empty($shipping_infos['state']) ? $shipping_infos['state'] : '', 'country' => !empty($shipping_infos['country']) ? $shipping_infos['country'] : '', 'civility' => $civility); //Create the post and post_meta for the billing address $post_address = array('post_author' => $result->ID, 'post_title' => $shipping_title, 'post_status' => 'publish', 'post_name' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, 'post_parent' => $result->ID); $post_address_id = wp_insert_post($post_address); //Create the post_meta with the address infos update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_metadata', $shipping_address); update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_attribute_set_id', $shipping_address_set_id); } } // FORMATE THE ORDER ADDRESSES INFOS $results = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'posts_per_page' => -1)); foreach ($results as $result) { $address = get_post_meta($result->ID, '_order_info', true); $billing_address = array(); if (!empty($address['billing'])) { if (!empty($address['billing']['civility'])) { switch ($address['billing']['civility']) { case 1: $civility = $mister_id; break; case 2: $civility = $madam_id; break; case 3: $civility = $miss_id; break; default: $civility = $mister_id; break; } } else { $civility = $mister_id; } $billing_address = array('address_title' => $billing_title, 'address_last_name' => !empty($address['billing']['last_name']) ? $address['billing']['last_name'] : '', 'address_first_name' => !empty($address['billing']['first_name']) ? $address['billing']['first_name'] : '', 'company' => !empty($address['billing']['company']) ? $address['billing']['company'] : '', 'address' => !empty($address['billing']['address']) ? $address['billing']['address'] : '', 'postcode' => !empty($address['billing']['postcode']) ? $address['billing']['postcode'] : '', 'city' => !empty($address['billing']['city']) ? $address['billing']['city'] : '', 'state' => !empty($address['billing']['state']) ? $address['billing']['state'] : '', 'country' => !empty($address['billing']['country']) ? $address['billing']['country'] : '', 'address_user_email' => !empty($address['billing']['email']) ? $address['billing']['email'] : '', 'phone' => !empty($address['billing']['phone']) ? $address['billing']['phone'] : '', 'tva_intra' => !empty($address['billing']['company_tva_intra']) ? $address['billing']['company_tva_intra'] : '', 'civility' => $civility); } $shipping_address = array(); if (!empty($address['shipping'])) { if (!empty($address['shipping']['civility'])) { switch ($address['shipping']['civility']) { case 1: $civility = $mister_id; break; case 2: $civility = $madam_id; break; case 3: $civility = $miss_id; break; } } else { $civility = $mister_id; } $shipping_address = array('address_title' => $shipping_title, 'address_last_name' => !empty($address['shipping']['last_name']) ? $address['shipping']['last_name'] : '', 'address_first_name' => !empty($address['shipping']['first_name']) ? $address['shipping']['first_name'] : '', 'company' => !empty($address['shipping']['company']) ? $address['shipping']['company'] : '', 'address' => !empty($address['shipping']['address']) ? $address['shipping']['address'] : '', 'postcode' => !empty($address['shipping']['postcode']) ? $address['shipping']['postcode'] : '', 'city' => !empty($address['shipping']['city']) ? $address['shipping']['city'] : '', 'state' => !empty($address['shipping']['state']) ? $address['shipping']['state'] : '', 'country' => !empty($address['shipping']['country']) ? $address['shipping']['country'] : '', 'civility' => $civility); } $billing_array_content = array('id' => $billing_address_set_id, 'address' => $billing_address); $shipping_array_content = array('id' => $shipping_address_set_id, 'address' => $shipping_address); $array_new_format = array('billing' => $billing_array_content, 'shipping' => $shipping_array_content); //Update the post meta update_post_meta($result->ID, '_order_info', $array_new_format); } /* Update entities meta management */ $entities = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, 'posts_per_page' => -1)); if (!empty($entities)) { foreach ($entities as $entity) { $params = get_post_meta($entity->ID, '_wpshop_entity_params', true); $support = !empty($params['support']) ? $params['support'] : ''; $rewrite = !empty($params['rewrite']) ? $params['rewrite'] : ''; $display_admin_menu = 'on'; update_post_meta($entity->ID, '_wpshop_entity_params', array('support' => $support, 'rewrite' => $rewrite, 'display_admin_menu' => $display_admin_menu)); } } wp_reset_query(); // Default Weight unity and Currency Options add_option('wpshop_shop_weight_group', 3, '', 'yes'); add_option('wpshop_shop_default_weight_unity', 6, '', 'yes'); add_option('wpshop_shop_currency_group', 4, '', 'yes'); $default_currency = get_option('wpshop_shop_default_currency'); foreach (unserialize(WPSHOP_SHOP_CURRENCIES) as $k => $v) { if ($default_currency == $k) { $symbol = $v; } } if (!empty($symbol)) { $query = 'SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE name = "' . html_entity_decode($symbol, ENT_QUOTES, 'UTF-8') . '"'; $currency = $wpdb->get_row($query); if (!empty($currency)) { update_option('wpshop_shop_default_currency', $currency->id); // Update the change rate of the default currency $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('change_rate' => 1), array('id' => $currency->id)); } } // Update the field for variation and user definition field $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_for_variation' => 'yes'), array('is_user_defined' => 'yes')); // Update field type for frontend output selection $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'text'), array()); $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'textarea'), array('backend_input' => 'textarea')); $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'select'), array('backend_input' => 'multiple-select')); $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'select'), array('backend_input' => 'select')); add_option('wpshop_cart_option', array('product_added_to_cart' => array('dialog_msg'), 'product_added_to_quotation' => array('cart_page'))); return true; break; case '30': /** Update the current price piloting field for using it into variation specific attributes */ $price_piloting_attribute = constant('WPSHOP_PRODUCT_PRICE_' . WPSHOP_PRODUCT_PRICE_PILOT); $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => $price_piloting_attribute)); /** Update the product reference field for using it into variation specific attributes */ $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'product_reference')); /** Insert new message for admin when a customer make an order */ $admin_new_order_message = get_option('WPSHOP_NEW_ORDER_ADMIN_MESSAGE'); if (empty($admin_new_order_message)) { wps_message_ctr::createMessage('WPSHOP_NEW_ORDER_ADMIN_MESSAGE'); } /** Update all amount for paypal orders */ $query = $wpdb->prepare("SELECT post_id FROM " . $wpdb->postmeta . " WHERE meta_key = %s AND meta_value = %s ", '_wpshop_payment_method', 'paypal'); $paypal_payment_list = $wpdb->get_results($query); if (!empty($paypal_payment_list)) { foreach ($paypal_payment_list as $post) { $order_meta = get_post_meta($post->post_id, '_order_postmeta', true); $order_payment_meta = get_post_meta($post->post_id, 'wpshop_payment_return_data', true); if (!empty($order_meta['order_status']) && $order_meta['order_status'] == 'incorrect_amount') { if (!empty($order_meta['order_grand_total']) && !empty($order_payment_meta['mc_gross'])) { $order_amount_to_pay = number_format($order_meta['order_grand_total'], 5); $order_amount_payed = number_format(floatval($order_payment_meta['mc_gross']), 5); if ($order_amount_payed == $order_amount_to_pay) { wpshop_payment::setOrderPaymentStatus($order_id, 'completed'); } } } } } /** Save existing orders address information */ $billing_title = __('Billing address', 'wpshop'); $shipping_title = __('Shipping address', 'wpshop'); $results = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'posts_per_page' => -1)); foreach ($results as $result) { $address = get_post_meta($result->ID, '_order_info', true); $address_format = array(); $billing_address = array(); if (!empty($address['billing']) && empty($address['billing']['id'])) { if (!empty($address['billing']['civility'])) { switch ($address['billing']['civility']) { case 1: $civility = $mister_id; break; case 2: $civility = $madam_id; break; case 3: $civility = $miss_id; break; default: $civility = $mister_id; break; } } else { $civility = $mister_id; } $billing_address = array('address_title' => $billing_title, 'address_last_name' => !empty($address['billing']['last_name']) ? $address['billing']['last_name'] : '', 'address_first_name' => !empty($address['billing']['first_name']) ? $address['billing']['first_name'] : '', 'company' => !empty($address['billing']['company']) ? $address['billing']['company'] : '', 'address' => !empty($address['billing']['address']) ? $address['billing']['address'] : '', 'postcode' => !empty($address['billing']['postcode']) ? $address['billing']['postcode'] : '', 'city' => !empty($address['billing']['city']) ? $address['billing']['city'] : '', 'state' => !empty($address['billing']['state']) ? $address['billing']['state'] : '', 'country' => !empty($address['billing']['country']) ? $address['billing']['country'] : '', 'address_user_email' => !empty($address['billing']['email']) ? $address['billing']['email'] : '', 'phone' => !empty($address['billing']['phone']) ? $address['billing']['phone'] : '', 'tva_intra' => !empty($address['billing']['company_tva_intra']) ? $address['billing']['company_tva_intra'] : '', 'civility' => $civility); $billing_address_option = get_option('wpshop_billing_address'); $address_format['billing']['id'] = $billing_address_option['choice']; $address_format['billing']['address'] = $shipping_address; } $shipping_address = array(); if (!empty($address['shipping']) && empty($address['shipping']['id'])) { if (!empty($address['shipping']['civility'])) { switch ($address['shipping']['civility']) { case 1: $civility = $mister_id; break; case 2: $civility = $madam_id; break; case 3: $civility = $miss_id; break; } } else { $civility = $mister_id; } $shipping_address = array('address_title' => $shipping_title, 'address_last_name' => !empty($address['shipping']['last_name']) ? $address['shipping']['last_name'] : '', 'address_first_name' => !empty($address['shipping']['first_name']) ? $address['shipping']['first_name'] : '', 'company' => !empty($address['shipping']['company']) ? $address['shipping']['company'] : '', 'address' => !empty($address['shipping']['address']) ? $address['shipping']['address'] : '', 'postcode' => !empty($address['shipping']['postcode']) ? $address['shipping']['postcode'] : '', 'city' => !empty($address['shipping']['city']) ? $address['shipping']['city'] : '', 'state' => !empty($address['shipping']['state']) ? $address['shipping']['state'] : '', 'country' => !empty($address['shipping']['country']) ? $address['shipping']['country'] : '', 'civility' => $civility); $shipping_address_options = get_option('wpshop_shipping_address_choice'); $address_format['shipping']['id'] = $shipping_address_options['choice']; $address_format['shipping']['address'] = $shipping_address; } if (!empty($address_format)) { update_post_meta($result->ID, '_order_info', $address_format); } } /** Delete username from frontend form */ $attribute_login = wpshop_attributes::getElement('user_login', "'valid'", 'code'); if (!empty($attribute_login)) { $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'deleted', 'last_update_date' => current_time('mysql', 0), 'position' => 0), array('attribute_id' => $attribute_login->id)); } $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('last_update_date' => current_time('mysql', 0), 'position' => 0), array('status' => 'deleted')); return true; break; case '31': /** Change order structure in order to support several payment */ $existing_orders = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'posts_per_page' => -1, 'post_status' => array('draft', 'trash', 'publish'))); if (!empty($existing_orders)) { foreach ($existing_orders as $order_main_informations) { /** Transfer payment return data form old meta to new */ $order_payment_return_data = get_post_meta($order_main_informations->ID, 'wpshop_payment_return_data', true); update_post_meta($order_main_informations->ID, '_wpshop_payment_return_data', $order_payment_return_data); delete_post_meta($order_main_informations->ID, 'wpshop_payment_return_data'); /** Transfer old payment storage method to new storage method */ $order_meta = get_post_meta($order_main_informations->ID, '_order_postmeta', true); if (!empty($order_meta['order_status'])) { $order_meta['order_payment']['customer_choice'] = array('method' => !empty($order_meta['payment_method']) ? $order_meta['payment_method'] : (!empty($order_meta['order_payment']['customer_choice']) ? $order_meta['order_payment']['customer_choice'] : '')); unset($order_meta['payment_method']); $order_meta['order_payment']['received'][0]['waited_amount'] = !empty($order_meta['order_grand_total']) ? $order_meta['order_grand_total'] : 0; $order_meta['order_payment']['received'][0]['method'] = $order_meta['order_payment']['customer_choice']['method']; $order_meta['order_payment']['received'][0]['date'] = $order_meta['order_date']; $order_meta['order_payment']['received'][0]['status'] = 'waiting_payment'; $order_meta['order_payment']['received'][0]['comment'] = ''; $order_meta['order_payment']['received'][0]['author'] = $order_meta['order_payment']['customer_choice'] == 'check' ? 1 : $order_meta['customer_id']; if (in_array($order_meta['order_status'], array('completed', 'shipped'))) { $order_meta['order_payment']['received'][0]['received_amount'] = $order_meta['order_grand_total']; $order_meta['order_payment']['received'][0]['payment_reference'] = wpshop_payment::get_payment_transaction_number_old_way($order_main_informations->ID); $order_meta['order_payment']['received'][0]['date'] = $order_meta['order_payment_date']; $order_meta['order_payment']['received'][0]['status'] = 'payment_received'; $order_meta['order_payment']['received'][0]['comment'] = ''; $order_meta['order_payment']['received'][0]['author'] = $order_meta['order_payment']['customer_choice'] == 'check' ? 1 : $order_meta['customer_id']; $order_meta['order_payment']['received'][0]['invoice_ref'] = $order_meta['order_invoice_ref']; } update_post_meta($order_main_informations->ID, '_order_postmeta', $order_meta); if (!empty($order_meta['order_payment']['customer_choice'])) { switch ($order_meta['order_payment']['customer_choice']) { case 'check': delete_post_meta($order_main_informations->ID, '_order_check_number', get_post_meta($order_main_informations->ID, '_order_check_number', true)); break; case 'paypal': delete_post_meta($order_main_informations->ID, '_order_paypal_txn_id', get_post_meta($order_main_informations->ID, '_order_paypal_txn_id', true)); break; case 'cic': delete_post_meta($order_main_informations->ID, '_order_cic_txn_id', get_post_meta($order_main_informations->ID, '_order_cic_txn_id', true)); break; } } } } } $wps_messages = new wps_message_ctr(); $wps_messages->wpshop_messages_historic_correction(); wp_reset_query(); $default_currency = get_option('wpshop_shop_default_currency'); foreach (unserialize(WPSHOP_SHOP_CURRENCIES) as $k => $v) { if ($default_currency == $k) { $symbol = $v; } } if (!empty($symbol)) { $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE name = "' . html_entity_decode($symbol, ENT_QUOTES, 'UTF-8') . '"', ''); $currency = $wpdb->get_row($query); if (!empty($currency)) { update_option('wpshop_shop_default_currency', $currency->id); // Update the change rate of the default currency $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('change_rate' => 1), array('id' => $currency->id)); } } $shipping_confirmation_message = get_option('WPSHOP_SHIPPING_CONFIRMATION_MESSAGE'); if (!empty($shipping_confirmation_message)) { $message = __('Hello [customer_first_name] [customer_last_name], this email confirms that your order ([order_key]) has just been shipped (order date : [order_date], tracking number : [order_trackingNumber]). Thank you for your loyalty. Have a good day.', 'wpshop'); $post = array('ID' => $shipping_confirmation_message, 'post_content' => $message); wp_update_post($post); } return true; break; case '32': /** Update product set id that are null */ $query = $wpdb->prepare("UPDATE " . $wpdb->postmeta . " SET meta_value = (SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE default_set = 'yes' AND entity_id = '" . wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) . "') WHERE meta_key = %s AND ((meta_value = '') OR (meta_value = null))", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attribute_set_id'); $wpdb->query($query); $addons_options = get_option(WPSHOP_ADDONS_OPTION_NAME); if (!empty($addons_options) && !empty($addons_options['WPSHOP_ADDONS_QUOTATION']) && !empty($addons_options['WPSHOP_ADDONS_QUOTATION']['activate']) && $addons_options['WPSHOP_ADDONS_QUOTATION']['activate']) { $admin_new_quotation_message = get_option('WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE'); if (empty($admin_new_quotation_message)) { wps_message_ctr::createMessage('WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE'); } $admin_new_quotation_confirm_message = get_option('WPSHOP_QUOTATION_CONFIRMATION_MESSAGE'); if (empty($admin_new_quotation_confirm_message)) { wps_message_ctr::createMessage('WPSHOP_QUOTATION_CONFIRMATION_MESSAGE'); } } /** Allows the administrator to manage a little bit more the catalog rewrite parameters */ $options = get_option('wpshop_catalog_product_option'); $options['wpshop_catalog_product_slug_with_category'] = empty($options['wpshop_catalog_product_slug_with_category']) ? 'yes' : $options['wpshop_catalog_product_slug_with_category']; update_option('wpshop_catalog_product_option', $options); /** Create a new page for unsuccessfull payment return */ self::wpshop_insert_default_pages($wpshop_shop_type); wp_cache_flush(); /** Update the iso code of currencies */ $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('code_iso' => 'EUR'), array('name' => 'euro')); $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('code_iso' => 'USD'), array('name' => 'dollar')); /** Update VAT Rate*/ $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s OR code = %s', 'tx_tva', 'eco_taxe_rate_tva'); $attribute_ids = $wpdb->get_results($query); foreach ($attribute_ids as $attribute_id) { $query = $wpdb->prepare('UPDATE ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' SET value = replace(value, "-", ".") WHERE attribute_id = %d', $attribute_id->id); $wpdb->query($query); } return true; break; case '33': /** Update the user_mail for the new system of log in/register */ $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "user_email"'); /** Put discount attributes in price attribute set section*/ $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE code = %s', 'prices'); $prices_section_id = $wpdb->get_var($query); $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s OR code = %s', 'discount_rate', 'discount_amount'); $attributes = $wpdb->get_results($query); if (!empty($attributes) && !empty($prices_section_id)) { foreach ($attributes as $attribute) { $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' SET attribute_group_id = ' . $prices_section_id . ' WHERE attribute_id = ' . $attribute->id); } } return true; break; case '34': $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE code = %s', 'prices'); $prices_section_id = $wpdb->get_var($query); $query = $wpdb->prepare('SELECT MAX(position) AS max_position FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_group_id = %d', $prices_section_id); $last_position_id = $wpdb->get_var($query); $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_group_id = %d AND position = %d', $prices_section_id, $last_position_id); $attribute_example = $wpdb->get_row($query); $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s OR code = %s', 'special_from', 'special_to'); $attributes = $wpdb->get_results($query); $i = 1; if (!empty($attributes) && !empty($prices_section_id)) { foreach ($attributes as $attribute) { $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('attribute_group_id' => $prices_section_id), array('attribute_id' => $attribute->id)); $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $attribute_example->entity_type_id, 'attribute_set_id' => $attribute_example->attribute_set_id, 'attribute_group_id' => $prices_section_id, 'attribute_id' => $attribute->id, 'position' => $last_position_id + $i)); $i++; } } $discount_options = get_option('wpshop_catalog_product_option'); $status = !empty($discount_options) && !empty($discount_options['discount']) ? 'valid' : 'notused'; $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_label' => __('Discount from', 'wpshop'), 'status' => $status), array('code' => 'special_from')); $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_label' => __('Discount to', 'wpshop'), 'status' => $status), array('code' => 'special_to')); return true; break; case '35': $wpdb->update($wpdb->posts, array('post_status' => 'draft'), array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS)); return true; break; case '36': wpshop_entities::create_cpt_attributes_from_csv_file(WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS); @set_time_limit(900); /** Change the path for old categories pictures */ @chmod(WPSHOP_UPLOAD_DIR . 'wpshop_product_category', 0755); $query = 'SELECT * FROM ' . $wpdb->terms; $terms = $wpdb->get_results($query); if (!empty($terms)) { foreach ($terms as $term) { @chmod(WPSHOP_UPLOAD_DIR . 'wpshop_product_category/' . $term->term_id, 0755); /** Check if a picture exists **/ $term_option = get_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $term->term_id); if (!empty($term_option) && !empty($term_option['wpshop_category_picture']) && is_file(WPSHOP_UPLOAD_DIR . $term_option['wpshop_category_picture'])) { $wp_upload_dir = wp_upload_dir(); $img_path = WPSHOP_UPLOAD_DIR . $term_option['wpshop_category_picture']; $img_basename = basename($img_path); $wp_filetype = wp_check_filetype($img_basename, null); /** Check if there is an image with the same name, if yes we add a rand number to image's name **/ $rand_name = is_file($wp_upload_dir['path'] . '/' . $img_basename) ? rand() : ''; $img_basename = !empty($rand_name) ? $rand_name . '_' . $img_basename : $img_basename; if (copy($img_path, $wp_upload_dir['path'] . '/' . $img_basename)) { $attachment = array('guid' => $wp_upload_dir['url'] . '/' . $img_basename, 'post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', $img_basename), 'post_content' => '', 'post_status' => 'inherit'); $attach_id = wp_insert_attachment($attachment, $wp_upload_dir['path'] . '/' . $img_basename); /** Generate differnts sizes for this image **/ require_once ABSPATH . 'wp-admin/includes/image.php'; $attach_data = wp_generate_attachment_metadata($attach_id, $wp_upload_dir['path'] . '/' . $img_basename); wp_update_attachment_metadata($attach_id, $attach_data); /** Update option picture **/ $term_option['wpshop_category_picture'] = $attach_id; update_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $term->term_id, $term_option); } } } } /** Change metabox Hidden Nav Menu Definition to display WPShop categories' metabox **/ $query = $wpdb->prepare('SELECT * FROM ' . $wpdb->usermeta . ' WHERE meta_key = %s', 'metaboxhidden_nav-menus'); $meta_keys = $wpdb->get_results($query); if (!empty($meta_keys) && is_array($meta_keys)) { foreach ($meta_keys as $meta_key) { $user_id = $meta_key->user_id; $meta_value = unserialize($meta_key->meta_value); if (!empty($meta_value) && is_array($meta_value)) { $data_to_delete = array_search('add-wpshop_product_category', $meta_value); if ($data_to_delete !== false) { unset($meta_value[$data_to_delete]); } } update_user_meta($user_id, 'metaboxhidden_nav-menus', $meta_value); } } return true; break; case '37': @set_time_limit(900); /** Change the path for old categories pictures */ @chmod(WPSHOP_UPLOAD_DIR . 'wpshop/wpshop_product_category', 0755); /** Read all categories folders **/ $categories_main_dir = WPSHOP_UPLOAD_DIR . 'wpshop/wpshop_product_category'; if (file_exists($categories_main_dir)) { $main_folder_content = scandir($categories_main_dir); /** For each category folder **/ foreach ($main_folder_content as $category_folder) { if ($category_folder && substr($category_folder, 0, 1) != '.') { $category_id = $category_folder; @chmod(WPSHOP_UPLOAD_DIR . 'wpshop/wpshop_product_category/' . $category_id, 0755); $scan_category_folder = opendir($categories_main_dir . '/' . $category_folder); /** For each Picture of category **/ $file_time = 0; $save_this_picture = false; while (false !== ($fichier = readdir($scan_category_folder))) { if ($fichier && substr($fichier, 0, 1) != '.') { if ($file_time < filemtime($categories_main_dir . '/' . $category_id . '/' . $fichier)) { $save_this_picture = true; $file_time = filemtime($categories_main_dir . '/' . $category_id . '/' . $fichier); } /** Select category option **/ $term_option = get_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $category_id); $wp_upload_dir = wp_upload_dir(); $img_path = $categories_main_dir . '/' . $category_id . '/' . $fichier; $img_basename = basename($img_path); $wp_filetype = wp_check_filetype($img_basename, null); /** Check if there is an image with the same name, if yes we add a rand number to image's name **/ $rand_name = is_file($wp_upload_dir['path'] . '/' . $img_basename) ? rand() : ''; $img_basename = !empty($rand_name) ? $rand_name . '_' . $img_basename : $img_basename; if (copy($img_path, $wp_upload_dir['path'] . '/' . $img_basename)) { $attachment = array('guid' => $wp_upload_dir['url'] . '/' . $img_basename, 'post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', $img_basename), 'post_content' => '', 'post_status' => 'inherit'); $attach_id = wp_insert_attachment($attachment, $wp_upload_dir['path'] . '/' . $img_basename); /** Generate differnts sizes for this image **/ require_once ABSPATH . 'wp-admin/includes/image.php'; $attach_data = wp_generate_attachment_metadata($attach_id, $wp_upload_dir['path'] . '/' . $img_basename); wp_update_attachment_metadata($attach_id, $attach_data); /** Update option picture **/ $term_option['wpshop_category_picture'] = $attach_id; if ($save_this_picture) { update_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $category_id, $term_option); } $save_this_picture = false; } } } } } } return true; break; case '38': wps_message_ctr::createMessage('WPSHOP_QUOTATION_UPDATE_MESSAGE'); return true; break; case '39': $attribute_def = wpshop_attributes::getElement('tx_tva', "'valid'", 'code'); /** Check if the 7% VAT Rate is not already created **/ $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d AND value = %s', $attribute_def->id, '7'); $exist_vat_rate = $wpdb->get_results($query); if (empty($exist_vat_rate)) { /** Get Max Position **/ $query = $wpdb->prepare('SELECT MAX(position) as max_position FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d', $attribute_def->id); $max_position = $wpdb->get_var($query); if (!empty($attribute_def) && !empty($attribute_def->id)) { $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'attribute_id' => $attribute_def->id, 'position' => (int) $max_position + 1, 'value' => '7', 'label' => '7')); } } /** Filter Search optimization **/ @set_time_limit(900); $query = $wpdb->prepare('SELECT term_id FROM ' . $wpdb->term_taxonomy . ' WHERE taxonomy = %s ', WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES); $categories = $wpdb->get_results($query); $cats = array(); if (!empty($categories)) { foreach ($categories as $category) { $cats[] = $category->term_id; } $wpshop_filter_search = new wps_filter_search(); $wpshop_filter_search->stock_values_for_attribute($cats); } return true; break; case '40': /** Store watt in puissance unit group */ $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s", __('puissance', 'wpshop')); $puissance_unit_group_id = $wpdb->get_var($query); $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $puissance_unit_group_id), array('unit' => 'watt')); /** Store day/week/year in duration unit group */ $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s", __('duration', 'wpshop')); $duration_unit_group_id = $wpdb->get_var($query); $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $duration_unit_group_id), array('unit' => 'day')); $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $duration_unit_group_id), array('unit' => 'week')); $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $duration_unit_group_id), array('unit' => 'year')); /** Store day/week/year in duration unit group */ $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s", __('length', 'wpshop')); $length_unit_group_id = $wpdb->get_var($query); $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $length_unit_group_id), array('unit' => 'cm')); return true; break; case '41': /** Get distinct attribute set and delete doublons */ $query = "SELECT DISTINCT( name ) AS name, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " GROUP BY name HAVING COUNT(id) > 1"; $list_of_set = $wpdb->get_results($query); foreach ($list_of_set as $set_infos) { $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE name = %s AND id != %d", $set_infos->name, $set_infos->min_id); $wpdb->query($query); } $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_SET); /** Get and delete attribute set section */ $query = "DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE attribute_set_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " )"; $wpdb->query($query); $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_GROUP); /** Get and delete attribute set details */ $query = "DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE attribute_set_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " ) OR attribute_group_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " )"; $wpdb->query($query); $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_DETAILS); $query = "SELECT attribute_set_id, attribute_group_id, attribute_id, MIN(id) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " GROUP BY attribute_set_id, attribute_group_id, attribute_id HAVING COUNT(id) > 1"; $affectation_list = $wpdb->get_results($query); foreach ($affectation_list as $affectation_to_treat) { $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE attribute_set_id = %d AND attribute_group_id = %d AND attribute_id = %d AND id != %d", $affectation_to_treat->attribute_set_id, $affectation_to_treat->attribute_group_id, $affectation_to_treat->attribute_id, $affectation_to_treat->min_id); $wpdb->query($query); } $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_DETAILS); /** Get and delete double unit */ $query = "SELECT DISTINCT( unit ) AS unit, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT . " GROUP BY unit HAVING COUNT(id) > 1"; $list_of_set = $wpdb->get_results($query); foreach ($list_of_set as $set_infos) { $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT . " WHERE unit = %s AND id != %d", $set_infos->unit, $set_infos->min_id); $wpdb->query($query); } $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_UNIT); $query = "SELECT DISTINCT( name ) AS name, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " GROUP BY name HAVING COUNT(id) > 1"; $list_of_set = $wpdb->get_results($query); foreach ($list_of_set as $set_infos) { $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s AND id != %d", $set_infos->name, $set_infos->min_id); $wpdb->query($query); } $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP); /** Get and delete attribute set details */ $query = "DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE attribute_set_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " ) OR attribute_group_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " )"; $wpdb->query($query); $query = "SELECT GROUP_CONCAT( id ) AS list_id, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " GROUP BY attribute_set_id, attribute_group_id, attribute_id HAVING COUNT(id) > 1"; $affectation_list = $wpdb->get_results($query); foreach ($affectation_list as $list) { $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE id IN (" . (substr($list->list_id, -1) == ',' ? substr($list->list_id, 0, -1) : $list->list_id) . ") AND id != %d", $list->min_id, ''); $wpdb->query($query); } $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_DETAILS); return true; break; case '42': $available_downloadable_product = get_option('WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE'); if (empty($available_downloadable_product)) { wps_message_ctr::createMessage('WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE'); } return true; break; case '43': $available_downloadable_product = get_option('WPSHOP_ORDER_IS_CANCELED'); if (empty($available_downloadable_product)) { wps_message_ctr::createMessage('WPSHOP_ORDER_IS_CANCELED'); } return true; break; case '44': $display_option = get_option('wpshop_display_option'); if (!empty($display_option) && empty($display_option['latest_products_ordered'])) { $display_option['latest_products_ordered'] = 3; update_option('wpshop_display_option', $display_option); } /** Check messages for customization **/ $messages = array('WPSHOP_SIGNUP_MESSAGE' => WPSHOP_SIGNUP_MESSAGE, 'WPSHOP_PAYPAL_PAYMENT_CONFIRMATION_MESSAGE' => WPSHOP_PAYPAL_PAYMENT_CONFIRMATION_MESSAGE, 'WPSHOP_OTHERS_PAYMENT_CONFIRMATION_MESSAGE' => WPSHOP_OTHERS_PAYMENT_CONFIRMATION_MESSAGE, 'WPSHOP_SHIPPING_CONFIRMATION_MESSAGE' => WPSHOP_SHIPPING_CONFIRMATION_MESSAGE, 'WPSHOP_ORDER_UPDATE_MESSAGE' => WPSHOP_ORDER_UPDATE_MESSAGE, 'WPSHOP_ORDER_UPDATE_PRIVATE_MESSAGE' => WPSHOP_ORDER_UPDATE_PRIVATE_MESSAGE, 'WPSHOP_NEW_ORDER_ADMIN_MESSAGE' => WPSHOP_NEW_ORDER_ADMIN_MESSAGE, 'WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE' => WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE, 'WPSHOP_QUOTATION_CONFIRMATION_MESSAGE' => WPSHOP_QUOTATION_CONFIRMATION_MESSAGE, 'WPSHOP_QUOTATION_UPDATE_MESSAGE' => WPSHOP_QUOTATION_UPDATE_MESSAGE, 'WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE' => WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE, 'WPSHOP_ORDER_IS_CANCELED' => WPSHOP_ORDER_IS_CANCELED); if (!empty($messages)) { foreach ($messages as $key => $message) { $message_option = get_option($key); if (!empty($message_option)) { $post_message = get_post($message_option); $original_message = !empty($post_message) && !empty($post_message->post_content) ? $post_message->post_content : ''; $tags = array('<p>', '</p>'); if (str_replace($tags, '', $original_message) == str_replace($tags, '', __($message, 'wpshop'))) { wp_update_post(array('ID' => $message_option, 'post_content' => wps_message_ctr::customize_message($original_message))); } } } } return true; break; case '45': $shipping_mode_ctr = new wps_shipping_mode_ctr(); $shipping_mode_ctr->migrate_default_shipping_mode(); return true; break; case '46': wps_message_ctr::createMessage('WPSHOP_FORGOT_PASSWORD_MESSAGE'); wps_message_ctr::customize_message(WPSHOP_FORGOT_PASSWORD_MESSAGE); return true; break; case '47': wps_payment_mode::migrate_payment_modes(); return true; break; case '48': @ini_set('max_execution_time', '500'); $count_products = wp_count_posts(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); $output_type_option = get_option('wpshop_display_option'); $output_type = $output_type_option['wpshop_display_list_type']; for ($i = 0; $i <= $count_products->publish; $i += 20) { $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'); $products = $wpdb->get_results($query); if (!empty($products)) { foreach ($products as $product) { $p = wpshop_products::get_product_data($product->ID); $price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', $output_type)); update_post_meta($product->ID, '_wps_price_infos', $price); } } } return true; break; case '49': update_option('wpshop_send_invoice', true); return true; break; case '50': $price_display_option = get_option('wpshop_catalog_product_option'); $price_display_option['price_display']['text_from'] = 'on'; $price_display_option['price_display']['lower_price'] = 'on'; update_option('wpshop_catalog_product_option', $price_display_option); self::wpshop_insert_default_pages(); return true; break; case '51': /** Insert new message for direct payment link */ $direct_payment_link_message = get_option('WPSHOP_DIRECT_PAYMENT_LINK_MESSAGE'); if (empty($direct_payment_link_message)) { wps_message_ctr::createMessage('WPSHOP_DIRECT_PAYMENT_LINK_MESSAGE'); } return true; break; case '52': $account_page_option = get_option('wpshop_myaccount_page_id'); if (!empty($account_page_option)) { $page_account = get_post($account_page_option); $page_content = !empty($page_account) && !empty($page_account->post_content) ? str_replace('[wpshop_myaccount]', '[wps_account_dashboard]', $page_account->post_content) : '[wps_account_dashboard]'; wp_update_post(array('ID' => $account_page_option, 'post_content' => $page_content)); } return true; break; case '53': $payment_modes_option = get_option('wps_payment_mode'); if (!empty($payment_modes_option) && !empty($payment_modes_option['mode'])) { $payment_modes_option['mode']['cash_on_delivery'] = array('name' => __('Cash on delivery', 'wpshop'), 'logo' => WPSHOP_TEMPLATES_URL . 'wpshop/cheque.png', 'description' => __('Pay your order on delivery', 'wpshop')); update_option('wps_payment_mode', $payment_modes_option); } // Mass action on products to add a flag on variation definition $products = get_posts(array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT)); if (!empty($products)) { foreach ($products as $p) { $post_id = $p->ID; $check_product_have_variations = wpshop_products::get_variation($post_id); if (!empty($check_product_have_variations)) { $variation_flag = wpshop_products::check_variation_type($post_id); $variation_defining = get_post_meta($post_id, '_wpshop_variation_defining', true); $variation_defining['variation_type'] = $variation_flag; update_post_meta($post_id, '_wpshop_variation_defining', $variation_defining); } } } return true; break; case '54': // Change shortcode of sign up page $signup_page_id = get_option('wpshop_signup_page_id'); if (!empty($signup_page_id)) { $signup_page = get_post($signup_page_id); $signup_page_content = !empty($signup_page) && !empty($signup_page->post_content) ? str_replace('[wpshop_signup]', '[wps_account_dashboard]', $signup_page->post_content) : '[wps_account_dashboard]'; wp_update_post(array('ID' => $signup_page_id, 'post_content' => $signup_page_content)); } // Change Terms of sale default content $terms_page_id = get_option('wpshop_terms_of_sale_page_id'); if (!empty($terms_page_id)) { $terms_sale_page = get_post($terms_page_id); if (!empty($terms_sale_page) && !empty($terms_sale_page->post_content) && $terms_sale_page->post_content == '[wpshop_terms_of_sale]') { $data = '<h1>' . __('Your terms of sale', 'wpshop') . '</h1>'; $data .= '<h3>' . __('Rule', 'wpshop') . ' 1</h3>'; $data .= '<p>Ut enim quisque sibi plurimum confidit et ut quisque maxime virtute et sapientia sic munitus est, ut nullo egeat suaque omnia in se ipso posita iudicet, ita in amicitiis expetendis colendisque maxime excellit.</p>'; $data .= '<h3>' . __('Rule', 'wpshop') . ' 2</h3>'; $data .= '<p>Ut enim quisque sibi plurimum confidit et ut quisque maxime virtute et sapientia sic munitus est, ut nullo egeat suaque omnia in se ipso posita iudicet, ita in amicitiis expetendis colendisque maxime excellit.</p>'; $data .= '<h3>' . __('Rule', 'wpshop') . ' 3</h3>'; $data .= '<p>Ut enim quisque sibi plurimum confidit et ut quisque maxime virtute et sapientia sic munitus est, ut nullo egeat suaque omnia in se ipso posita iudicet, ita in amicitiis expetendis colendisque maxime excellit.</p>'; $data .= '<h3>' . __('Credits', 'wpshop') . '</h3>'; $data .= sprintf(__('%s uses <a href="http://www.wpshop.fr/" target="_blank" title="%s uses WPShop e-commerce plug-in for Wordpress">WPShop e-commerce for Wordpress</a>', 'wpshop'), get_bloginfo('name'), get_bloginfo('name')); wp_update_post(array('ID' => $terms_page_id, 'post_content' => $data)); } } return true; break; case '55': $checkout_page_id = get_option('wpshop_checkout_page_id'); $checkout_page = get_post($checkout_page_id); $checkout_page_content = !empty($checkout_page) && !empty($checkout_page->post_content) ? str_replace('[wpshop_checkout]', '[wps_checkout]', $checkout_page->post_content) : '[wps_checkout]'; wp_update_post(array('ID' => $checkout_page_id, 'post_content' => $checkout_page_content)); // Update cart page id update_option('wpshop_cart_page_id', $checkout_page_id); return true; break; case '56': $wps_entities = new wpshop_entities(); $customer_entity_id = $wps_entities->get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d ORDER BY id LIMIT 1', $customer_entity_id); $set = $wpdb->get_row($query); if (!empty($set)) { $wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, array('default_set' => 'yes'), array('id' => $set->id)); } // Update Opinions activation option update_option('wps_opinion', array('active' => 'on')); return true; break; case '57': $wpshop_cart_option = get_option('wpshop_cart_option'); $wpshop_cart_option['display_newsletter']['site_subscription'][] = 'yes'; $wpshop_cart_option['display_newsletter']['partner_subscription'][] = 'yes'; update_option('wpshop_cart_option', $wpshop_cart_option); return true; break; case '58': /** Turn customers publish into draft **/ $query = $wpdb->prepare("UPDATE {$wpdb->posts} SET post_status = %s WHERE post_type = %s", "draft", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); $wpdb->query($query); $attribute_def = wpshop_attributes::getElement('tx_tva', "'valid'", 'code'); /** Check if the 0% VAT Rate is not already created **/ $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d AND value = %s', $attribute_def->id, '0'); $exist_vat_rate = $wpdb->get_results($query); if (empty($exist_vat_rate)) { /** Get Max Position **/ $query = $wpdb->prepare('SELECT MAX(position) as max_position FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d', $attribute_def->id); $max_position = $wpdb->get_var($query); if (!empty($attribute_def) && !empty($attribute_def->id)) { $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'attribute_id' => $attribute_def->id, 'position' => (int) $max_position + 1, 'value' => '0', 'label' => '0')); } } return true; break; case '59': /** Move old images gallery to the new gallery, and remove old links **/ $allowed = get_allowed_mime_types(); $args = array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'post_status' => array('publish', 'draft', 'trash')); $posts = get_posts($args); $result = array(); foreach ($posts as $post) { $array = array(); $array['Post'] = $post; $array['PrincipalThumbnailID'] = get_post_meta($post->ID, '_thumbnail_id', true); $array['Attachments'] = get_attached_media($allowed, $post->ID); $array['TrueAttachmentsString'] = get_post_meta($post->ID, '_wps_product_media', true); if (!empty($array['TrueAttachmentsString'])) { $TrueAttachments_id = explode(',', $array['TrueAttachmentsString']); } $array['OldAttachmentsString'] = ''; foreach ($array['Attachments'] as $attachment) { $filename = basename(get_attached_file($attachment->ID)); $pos_ext = strrpos($filename, '.'); $filename_no_ext = substr($filename, 0, $pos_ext); if ((empty($TrueAttachments_id) || !in_array($attachment->ID, $TrueAttachments_id)) && !preg_match('#' . $filename_no_ext . '#', $post->post_content) && (empty($array['PrincipalThumbnailID']) || $attachment->ID != $array['PrincipalThumbnailID'])) { $array['OldAttachmentsString'] .= $attachment->ID . ','; } } unset($TrueAttachments_id); $result[$post->ID] = $array['TrueAttachmentsString'] . $array['OldAttachmentsString']; update_post_meta($post->ID, '_wps_product_media', $result[$post->ID]); } return true; break; case '60': /* Create default emails */ wps_message_ctr::create_default_message(); /** Update entries for quick add */ $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_required = "yes", is_used_in_quick_add_form = "yes" WHERE code = "barcode"'); $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "product_stock"'); $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "manage_stock"'); switch (WPSHOP_PRODUCT_PRICE_PILOT) { case 'HT': $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes", is_used_in_variation = "yes" WHERE code = "price_ht"'); $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "no" WHERE code = "tx_tva"'); $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "no", is_used_in_variation = "no" WHERE code = "product_price"'); break; default: $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes", is_used_in_variation = "yes" WHERE code = "product_price"'); $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "tx_tva"'); $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "no", is_used_in_variation = "no" WHERE code = "price_ht"'); break; } /* Default country with WP language */ $wpshop_country_default_choice_option = get_option('wpshop_country_default_choice'); if (empty($wpshop_country_default_choice_option)) { update_option('wpshop_country_default_choice', substr(get_bloginfo('language'), 3)); } return true; break; case '61': /** Import the xml for guided tour */ wpsBubble_ctr::import_xml(); /* Hide admin bar */ $wpshop_display_option = get_option('wpshop_display_option'); if (!empty($wpshop_display_option) && empty($wpshop_display_option['wpshop_hide_admin_bar'])) { $wpshop_display_option['wpshop_hide_admin_bar'] = 'on'; update_option('wpshop_display_option', $wpshop_display_option); } return true; break; case '62': /** Install user default for POS */ wps_pos_addon::action_to_do_on_activation(); return true; break; case '63': $data = get_option('wps_shipping_mode'); if (empty($data['modes']['default_shipping_mode_for_pos'])) { $data['modes']['default_shipping_mode_for_pos']['name'] = __('No Delivery', 'wpshop'); $data['modes']['default_shipping_mode_for_pos']['explanation'] = __('Delivery method for point of sale.', 'wpshop'); update_option('wps_shipping_mode', $data); } return true; break; case '64': $options = get_option('wpshop_catalog_product_option'); if (!empty($options['wpshop_catalog_product_slug_with_category'])) { unset($options['wpshop_catalog_product_slug_with_category']); update_option('wpshop_catalog_product_option', $options); } return true; break; /* Always add specific case before this bloc */ /* Always add specific case before this bloc */ case 'dev': wp_cache_flush(); // Newsletters options $wp_rewrite->flush_rules(); return true; break; default: return true; break; } }
/** * Add a product to the cart * @param string product_id contains the id of the product to add to the cart * @param string quantity contains the quantity of the item to add */ function add_to_cart($product_list, $quantity, $type = 'normal', $extra_params = array(), $from_admin = '', $order_meta = '', $order_id = '') { global $wpdb; /** Check if a cart already exist. If there is already a cart that is not the same type (could be a cart or a quotation) */ if (empty($from_admin)) { if (isset($_SESSION['cart']['cart_type']) && $type != $_SESSION['cart']['cart_type']) { return __('You have another element type into your cart. Please finalize it by going to cart page.', 'wpshop'); } else { $_SESSION['cart']['cart_type'] = $type; } $order_meta = $_SESSION['cart']; } $order_items = array(); foreach ($product_list as $pid => $product_more_content) { if (count($product_list) == 1) { if (!isset($quantity[$pid])) { $quantity[$pid] = 1; } $product = wpshop_products::get_product_data($product_more_content['id']); /** Check if the selected product exist */ if ($product === false) { return __('This product does not exist', 'wpshop'); } /** Get information about the product price */ $product_price_check = wpshop_prices::get_product_price($product, 'check_only'); if ($product_price_check !== true) { return $product_price_check; } $the_quantity = 1; if (!empty($product_more_content['defined_variation_priority']) && $product_more_content['defined_variation_priority'] == 'combined' && !empty($product_more_content['variations']) && !empty($product_more_content['variations'][0])) { /** Get the asked quantity for each product and check if there is enough stock */ $the_quantity = $quantity[$pid]; } else { /** Get the asked quantity for each product and check if there is enough stock */ $the_quantity = $quantity[$pid]; } $quantity[$pid] = $the_quantity; $variation_id = 0; if (!empty($product_more_content) && !empty($product_more_content['variations']) && !empty($product_more_content['variations'][0]) && !empty($product_more_content['defined_variation_priority']) && $product_more_content['defined_variation_priority'] == 'combined') { $variation_id = $product_more_content['variations'][0]; } $quantity_to_check = !empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) && !empty($_SESSION['cart']['order_items'][$pid]) && !empty($_SESSION['cart']['order_items'][$pid]['item_qty']) ? $_SESSION['cart']['order_items'][$pid]['item_qty'] + $the_quantity : $the_quantity; $wps_product_ctr = new wps_product_ctr(); $product_stock = $wps_product_ctr->check_stock($product_more_content['id'], $quantity_to_check, $variation_id); if ($product_stock !== true) { return $product_stock; } } $order_items[$pid]['product_id'] = $product_more_content['id']; $order_items[$pid]['product_qty'] = $quantity[$pid]; /** For product with variation */ $order_items[$pid]['product_variation_type'] = !empty($product_more_content['variation_priority']) ? $product_more_content['variation_priority'] : ''; $order_items[$pid]['free_variation'] = !empty($product_more_content['free_variation']) ? $product_more_content['free_variation'] : ''; $order_items[$pid]['product_variation'] = ''; if (!empty($product_more_content['variations'])) { foreach ($product_more_content['variations'] as $variation_id) { $order_items[$pid]['product_variation'][] = $variation_id; } } } $current_cart = !empty($order_meta) ? $order_meta : array(); $order = $this->calcul_cart_information($order_items, $extra_params, $current_cart); if (empty($from_admin)) { self::store_cart_in_session($order); /** Store the cart into database for connected user */ if (get_current_user_id()) { $this->persistent_cart_update(); } } else { update_post_meta($order_id, '_order_postmeta', $order); } return 'success'; }
" > <td>#<?php echo $product['ID']; ?> - <?php echo $product['product_name']; ?> <br/><?php _e('Barcode', 'wps-pos-i18n'); ?> : <?php echo $product['product_barcode']; ?> </td> <td class="wpshop_pos_addon_price"><?php echo wpshop_prices::get_product_price($product_data, 'price_display', 'complete_sheet'); ?> </td> <td> <!-- <a class="wps-pos-product-edition-link" target="wps_pos_product_edition" title="<?php _e('Edit this product', 'wps-pos-i18n'); ?> " href="<?php echo admin_url('post.php?post=' . $product['ID'] . '&action=edit'); ?> " ><i class="dashicons dashicons-edit" ></i></a> --> <button class="wps-bton-first-rounded wps-pos-add-to-cart-button" type="button" data-type="product" data-subtype="<?php echo !empty($product_variation_definition) ? 'variations' : 'simple'; ?> " data-id="<?php echo $product['ID'];
public static function get_variation_price_behaviour($product_into_cart, $product_variations, $head_product_id, $variations_options) { global $wpdb; if (!empty($product_variations)) { // Initialize variations total price datas $variations_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0); $variations_discount_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0); $vat_rate = 0; $discount_amount = $discount_rate = $special_price = 0; // Recover Head product metadata $head_product_metadata = get_post_meta($head_product_id, '_wpshop_product_metadata', true); $tva_rate_id = !empty($head_product_metadata['tx_tva']) ? $head_product_metadata['tx_tva'] : 0; if (!empty($tva_rate_id)) { // Recover VAT Rate of product $query = $wpdb->prepare('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $tva_rate_id); $vat_rate = $wpdb->get_var($query); } $price_piloting = get_option('wpshop_shop_price_piloting'); foreach ($product_variations as $product_variation) { $variation_metadata['product_price'] = 0; $variation_metadata = get_post_meta($product_variation, '_wpshop_product_metadata', true); if (!empty($variation_metadata)) { $p_et = empty($price_piloting) || $price_piloting == 'TTC' ? (!empty($variation_metadata['product_price']) ? $variation_metadata['product_price'] : 0) / (1 + $vat_rate / 100) : $variation_metadata['price_ht']; $p_ati = empty($price_piloting) || $price_piloting == 'TTC' ? !empty($variation_metadata['product_price']) ? $variation_metadata['product_price'] : 0 : $variation_metadata['price_ht'] * (1 + $vat_rate / 100); $variations_total_price['price_et'] += $p_et; $variations_total_price['price_ati'] += $p_ati; $variations_total_price['vat_amount'] += $p_ati - $p_et; $variation_metadata['tx_tva'] = $product_into_cart['tx_tva'] = $vat_rate; // Check discount $discount_config = wpshop_prices::check_discount_for_product($product_variation); if (!empty($discount_config) && !empty($discount_config['value'])) { $variation_discount_prices = wpshop_prices::calcul_discounted_price($variation_metadata, $discount_config); $variations_discount_total_price['price_et'] += $variation_discount_prices['price_ht']; $variations_discount_total_price['price_ati'] += $variation_discount_prices['product_price']; $variations_discount_total_price['vat_amount'] += $variation_discount_prices['tva']; if (!empty($discount_config['type']) && $discount_config['type'] == 'discount_amount') { $product_into_cart['discount_amount'] = $discount_amount + $product_into_cart['discount_amount']; } elseif (!empty($discount_config['type']) && $discount_config['type'] == 'discount_rate') { $product_into_cart['discount_rate'] = $discount_rate + $discount_config['value']; } elseif (!empty($discount_config['type']) && $discount_config['type'] == 'special_price') { $product_into_cart['special_price'] = $special_price + $discount_config['value']; } } $product_variation_def = wpshop_products::get_product_data($product_variation, true); $product_into_cart['item_meta']['variations'][$product_variation] = $product_variation_def; } } // Check if add or replace variation price to head product $product_variation_defining = get_post_meta($head_product_id, '_wpshop_variation_defining', true); if (empty($product_variation_defining) || !empty($product_variation_defining) && empty($product_variation_defining['options']) || !empty($product_variation_defining) && !empty($product_variation_defining['options']) && !empty($product_variation_defining['options']['price_behaviour']) && !empty($product_variation_defining['options']['price_behaviour'][0]) && $product_variation_defining['options']['price_behaviour'][0] == 'replacement') { //Replace the product price if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) { $product_into_cart['price_ttc_before_discount'] = $variations_total_price['price_ati']; $product_into_cart['price_ht_before_discount'] = $variations_total_price['price_et']; $product_into_cart['product_price'] = $variations_discount_total_price['price_ati']; $product_into_cart['price_ht'] = $variations_discount_total_price['price_et']; $product_into_cart['tva'] = $variations_discount_total_price['vat_amount']; } else { $product_into_cart['product_price'] = $variations_total_price['price_ati']; $product_into_cart['price_ht'] = $variations_total_price['price_et']; $product_into_cart['tva'] = $variations_total_price['vat_amount']; } } else { // Add variations price to product price if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) { $product_into_cart['price_ttc_before_discount'] = $product_into_cart['product_price'] + $variations_total_price['price_ati']; $product_into_cart['price_ht_before_discount'] = $product_into_cart['price_ht'] + $variations_total_price['price_et']; $product_into_cart['product_price'] += $variations_discount_total_price['price_ati']; $product_into_cart['price_ht'] += $variations_discount_total_price['price_et']; $product_into_cart['tva'] += $variations_discount_total_price['vat_amount']; } else { $product_into_cart['product_price'] += $variations_total_price['price_ati']; $product_into_cart['price_ht'] += $variations_total_price['price_et']; $product_into_cart['tva'] += $variations_total_price['vat_amount']; } // Check parent discount $parent_discount_config = wpshop_prices::check_discount_for_product($head_product_id); if (!empty($parent_discount_config)) { $product_into_cart['price_ttc_before_discount'] = !empty($product_into_cart['price_ttc_before_discount']) ? $product_into_cart['price_ttc_before_discount'] : $product_into_cart['product_price']; $product_into_cart['price_ht_before_discount'] = !empty($product_into_cart['price_ht_before_discount']) ? $product_into_cart['price_ht_before_discount'] : $product_into_cart['price_ht']; $product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $parent_discount_config); if (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_amount') { $product_into_cart['discount_amount'] = $discount_amount + $parent_discount_config['value']; } elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_rate') { $product_into_cart['discount_rate'] = $discount_rate + $parent_discount_config['value']; } elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'special_price') { $product_into_cart['special_price'] = $special_price + $parent_discount_config['value']; } } } } else { // If product have just Free variations $discount_config = wpshop_prices::check_discount_for_product($head_product_id); if (!empty($discount_config)) { $product_into_cart['price_ttc_before_discount'] = !empty($product_into_cart['price_ttc_before_discount']) ? $product_into_cart['price_ttc_before_discount'] : $product_into_cart['product_price']; $product_into_cart['price_ht_before_discount'] = !empty($product_into_cart['price_ht_before_discount']) ? $product_into_cart['price_ht_before_discount'] : $product_into_cart['price_ht']; $product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $discount_config); } } // Text From indicator if (!empty($variations_options) && !empty($variations_options['text_from'])) { $product_into_cart['text_from'] = $variations_options['text_from']; } return $product_into_cart; }
<div class="wps-table-cell wps-cart-item-img"><?php echo get_the_post_thumbnail($product->ID, 'thumbnail'); ?> </div> <div class="wps-table-cell"><?php echo !empty($product_metadata) && $product_metadata['product_reference'] ? $product_metadata['product_reference'] : ''; ?> </div> <div class="wps-table-cell"><?php echo $product->post_title; ?> </div> <div class="wps-table-cell"> <?php $product = wpshop_products::get_product_data($product->ID); echo wpshop_prices::get_product_price($product, 'price_display', array('mini_output', 'grid')); ?> </div> <?php if ('completed' != $order_post_meta) { ?> <div class="wps-table-cell"> <a class="wps-bton-icon-minus-small wps-cart-reduce-product-qty" href=""></a> <input id="wps-cart-product-qty-<?php echo $pid; ?> " class="wps-cart-product-qty" type="text" value="1" name="french-hens" size="3" style="text-align : center"> <a class="wps-bton-icon-plus-small wps-cart-add-product-qty" href=""></a> </div> <div class="wps-table-cell"> <a href="#" class="wps-bton-first-mini-rounded wps-order-add-product" id="wps-order-add-product-<?php
/** Recalculate prices in mass **/ function mass_update_prices() { global $wpdb; $status = false; $result = ''; @ini_set('max_execution_time', '500'); $price_piloting_option = get_option('wpshop_shop_price_piloting'); $output_type_option = get_option('wpshop_display_option'); $output_type = $output_type_option['wpshop_display_list_type']; /** Get tx_tva attribute_id **/ $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s', 'tx_tva'); $tx_tva_attribute_id = $wpdb->get_var($query); /** Product entity Definition **/ $product_entity = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); /** Attributes def **/ $tva_attribute_def = wpshop_attributes::getElement('tva', "'valid'", 'code'); $product_price_attribute_def = wpshop_attributes::getElement('product_price', "'valid'", 'code'); $price_ht_attribute_def = wpshop_attributes::getElement('price_ht', "'valid'", 'code'); if (!empty($tx_tva_attribute_id)) { $query = $wpdb->prepare('SELECT id, value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d', $tx_tva_attribute_id, 'valid'); $tx_tva = $wpdb->get_results($query); $tva_array = array(); /** Transform array to easy teatment **/ foreach ($tx_tva as $t) { $tva_array[$t->id] = $t->value; } if (!empty($tx_tva)) { $count_products = wp_count_posts(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); for ($i = 0; $i <= $count_products->publish; $i += 100) { $query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_status = %s ORDER BY ID DESC LIMIT ' . $i . ', 150', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'publish'); $products = $wpdb->get_results($query); if (!empty($products)) { foreach ($products as $product) { $product_data = get_post_meta($product->ID, '_wpshop_product_metadata', true); if (!empty($product_data)) { if (!empty($product_data['tx_tva']) && array_key_exists($product_data['tx_tva'], $tva_array)) { if (!empty($price_piloting_option) && $price_piloting_option == 'HT') { /** Update post meta **/ $product_data['price_ht'] = (double) str_replace(',', '.', $product_data['price_ht']); $product_data['product_price'] = $product_data['price_ht'] * (1 + $tva_array[$product_data['tx_tva']] / 100); $product_data['tva'] = $product_data['price_ht'] * ($tva_array[$product_data['tx_tva']] / 100); update_post_meta($product->ID, '_wpshop_product_metadata', $product_data); /** Update attributes values **/ $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => (double) $product_data['price_ht']), array('entity_type_id' => $product_entity, 'attribute_id' => $price_ht_attribute_def->id, 'entity_id' => $product->ID)); $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => (double) $product_data['product_price']), array('entity_type_id' => $product_entity, 'attribute_id' => $product_price_attribute_def->id, 'entity_id' => $product->ID)); $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => (double) $product_data['tva']), array('entity_type_id' => $product_entity, 'attribute_id' => $tva_attribute_def->id, 'entity_id' => $product->ID)); /** Update Display price meta **/ $p = wpshop_products::get_product_data($product->ID); $price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', $output_type)); update_post_meta($product->ID, '_wps_price_infos', $price); } else { /** Update post meta **/ $product_data['product_price'] = (double) str_replace(',', '.', $product_data['product_price']); $product_data['price_ht'] = $product_data['product_price'] / (1 + $tva_array[$product_data['tx_tva']] / 100); $product_data['tva'] = $product_data['price_ht'] * ($tva_array[$product_data['tx_tva']] / 100); update_post_meta($product->ID, '_wpshop_product_metadata', $product_data); /** Update attributes values **/ $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['price_ht']), array('entity_type_id' => $product_entity, 'attribute_id' => $price_ht_attribute_def->id, 'entity_id' => $product->ID)); $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['tva']), array('entity_type_id' => $product_entity, 'attribute_id' => $tva_attribute_def->id, 'entity_id' => $product->ID)); $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['product_price']), array('entity_type_id' => $product_entity, 'attribute_id' => $product_price_attribute_def->id, 'entity_id' => $product->ID)); /** Update Display price meta **/ $p = wpshop_products::get_product_data($product->ID); $price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', $output_type)); update_post_meta($product->ID, '_wps_price_infos', $price); } } } } } } unset($products); $count_variations = wp_count_posts(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION); for ($i = 0; $i <= $count_variations->publish; $i += 100) { $query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_status = %s ORDER BY ID DESC LIMIT ' . $i . ', 100', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'publish'); $product_variations = $wpdb->get_results($query); /** Update Products Variations **/ if (!empty($product_variations)) { foreach ($product_variations as $product_variation) { $product_data = get_post_meta($product_variation->ID, '_wpshop_product_metadata', true); if (!empty($product_data)) { if (!empty($product_data['tx_tva']) && array_key_exists($product_data['tx_tva'], $tva_array)) { if (!empty($price_piloting_option) && $price_piloting_option == 'HT') { /** Update post meta **/ $product_data['price_ht'] = (double) str_replace(',', '.', $product_data['price_ht']); $product_data['product_price'] = $product_data['price_ht'] * (1 + $tva_array[$product_data['tx_tva']] / 100); $product_data['tva'] = $product_data['price_ht'] * ($tva_array[$product_data['tx_tva']] / 100); update_post_meta($product_variation->ID, '_wpshop_product_metadata', $product_data); /** Update attributes values **/ $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['price_ht']), array('entity_type_id' => $product_entity, 'attribute_id' => $price_ht_attribute_def->id, 'entity_id' => $product_variation->ID)); $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['product_price']), array('entity_type_id' => $product_entity, 'attribute_id' => $product_price_attribute_def->id, 'entity_id' => $product_variation->ID)); $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['tva']), array('entity_type_id' => $product_entity, 'attribute_id' => $tva_attribute_def->id, 'entity_id' => $product_variation->ID)); } else { /** Update post meta **/ $product_data['product_price'] = (double) str_replace(',', '.', $product_data['product_price']); $product_data['price_ht'] = $product_data['product_price'] / (1 + $tva_array[$product_data['tx_tva']] / 100); $product_data['tva'] = $product_data['price_ht'] * ($tva_array[$product_data['tx_tva']] / 100); update_post_meta($product_variation->ID, '_wpshop_product_metadata', $product_data); /** Update attributes values **/ $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['price_ht']), array('entity_type_id' => $product_entity, 'attribute_id' => $price_ht_attribute_def->id, 'entity_id' => $product_variation->ID)); $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['tva']), array('entity_type_id' => $product_entity, 'attribute_id' => $tva_attribute_def->id, 'entity_id' => $product_variation->ID)); $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('value' => $product_data['product_price']), array('entity_type_id' => $product_entity, 'attribute_id' => $product_price_attribute_def->id, 'entity_id' => $product_variation->ID)); } } } } } } $result = __('Prices updated', 'wpshop'); $status = true; } else { $result = __('No VAT rates was found', 'wpshop'); } } else { $result = __('VAT rate attribute was not found', 'wpshop'); } return array($status, $result); }
/** * Save the price which is displayed on website */ function save_displayed_price_meta() { if (!empty($_POST) && !empty($_POST['ID']) && !empty($_POST['post_type']) && $_POST['post_type'] == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) { $price_piloting = get_option('wpshop_shop_price_piloting'); $product_data = wpshop_products::get_product_data($_POST['ID']); $price_infos = wpshop_prices::check_product_price($product_data); if (!empty($price_infos)) { if (!empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist'])) { $displayed_price = !empty($price_piloting) && $price_piloting == 'HT' ? $price_infos['discount']['discount_et_price'] : $price_infos['discount']['discount_ati_price']; } else { if (!empty($price_infos['fork_price']) && !empty($price_infos['fork_price']['have_fork_price'])) { $displayed_price = $price_infos['fork_price']['min_product_price']; } else { $displayed_price = !empty($price_piloting) && $price_piloting == 'HT' ? $price_infos['et'] : $price_infos['ati']; } } update_post_meta($_POST['ID'], '_wpshop_displayed_price', number_format($displayed_price, 2, '.', '')); } } }