/** * Reload address panel */ function reload_addresses_for_customer() { $status = false; $response = ''; $customer_id = !empty($_POST['customer_id']) ? intval($_POST['customer_id']) : ''; $order_id = !empty($_POST['order_id']) ? intval($_POST['order_id']) : ''; if (!empty($customer_id)) { $wps_address = new wps_address(); $response = $wps_address->display_addresses_interface($customer_id, true, $order_id); $status = true; } echo json_encode(array('status' => $status, 'response' => $response)); wp_die(); }
function wpshop_billing_address_validator($input) { global $wpdb; $t = wps_address::get_addresss_form_fields_by_type($input['choice']); $the_code = ''; foreach ($t[$input['choice']] as $group_id => $group_def) { if (!empty($input['integrate_into_register_form_matching_field']) && !empty($input['integrate_into_register_form_matching_field']['user_email']) && array_key_exists($input['integrate_into_register_form_matching_field']['user_email'], $group_def['content'])) { $the_code = $group_def['content'][$input['integrate_into_register_form_matching_field']['user_email']]['name']; continue; } } $the_code; if (!empty($input['integrate_into_register_form']) && $input['integrate_into_register_form'] == 'yes') { if (!empty($input['integrate_into_register_form_matching_field']) && !empty($input['integrate_into_register_form_matching_field']['user_email']) && $the_code == 'address_user_email') { $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('_need_verification' => 'no'), array('code' => $the_code)); } } $billing_option = get_option('wpshop_billing_address'); if (!empty($billing_option) && !empty($billing_option['display_model'])) { $input['display_model'] = $billing_option['display_model']; } return $input; }
/** * Get customers with a term: all, newsletters_site, newsletters_site_partners, date(between 2 dates) or if order is higher than. * @param string $term * @param price/date $dt1 may be null * @param date $dt2 may be null * @return array */ function get_customers($term, $dt1 = null, $dt2 = null) { global $wpdb; $users; switch ($term) { case 'users_all': $query = $wpdb->prepare("SELECT ID AS USER_ID, '' AS POST_ID FROM {$wpdb->users} WHERE %d", 1); $list_users = $wpdb->get_results($query, OBJECT); break; case 'customers_all': $query = $wpdb->prepare("SELECT us.ID AS USER_ID, GROUP_CONCAT( ps.ID ) AS POST_ID FROM {$wpdb->users} us JOIN {$wpdb->posts} ps ON us.ID = ps.post_author AND ps.post_type = %s GROUP BY USER_ID", 'wpshop_shop_order'); $list_users = $wpdb->get_results($query, OBJECT); break; case 'newsletters_site': $query = $wpdb->prepare("SELECT user_id AS USER_ID, GROUP_CONCAT( ID ) AS POST_ID FROM {$wpdb->usermeta} JOIN {$wpdb->posts} ON post_author = user_id AND post_type = %s WHERE meta_key = %s AND ( meta_value LIKE ('%%%s%%') || meta_value LIKE ('%%%s%%') ) GROUP BY USER_ID", 'wpshop_shop_order', 'user_preferences', 's:16:"newsletters_site";i:1;', 's:16:"newsletters_site";b:1;'); $list_users = $wpdb->get_results($query, OBJECT); break; case 'newsletters_site_partners': $query = $wpdb->prepare("SELECT user_id AS USER_ID, GROUP_CONCAT( ID ) AS POST_ID FROM {$wpdb->usermeta} JOIN {$wpdb->posts} ON post_author = user_id AND post_type = %s WHERE meta_key = %s AND ( meta_value LIKE ('%%%s%%') || meta_value LIKE ('%%%s%%') ) GROUP BY USER_ID", 'wpshop_shop_order', 'user_preferences', 's:25:"newsletters_site_partners";i:1;', 's:25:"newsletters_site_partners";b:1;'); $list_users = $wpdb->get_results($query, OBJECT); break; case 'date': $query = $wpdb->prepare("SELECT us.`ID` AS USER_ID, GROUP_CONCAT( ps.`ID` ) AS POST_ID FROM {$wpdb->users} us JOIN {$wpdb->posts} ps ON `post_author` = us.`ID` AND `post_type` = %s WHERE `user_registered` >= %s AND `user_registered` <= %s GROUP BY USER_ID", 'wpshop_shop_order', date("Y-m-j", strtotime($dt1)), date("Y-m-j", strtotime("+1 day", strtotime($dt2)))); $list_users = $wpdb->get_results($query, OBJECT); break; case 'orders': $query = $wpdb->prepare("SELECT us.ID AS USER_ID, GROUP_CONCAT( ps.ID ) AS POST_ID FROM {$wpdb->users} us JOIN {$wpdb->posts} ps ON us.ID = ps.post_author AND ps.post_type = %s GROUP BY USER_ID", 'wpshop_shop_order'); $list_users = $wpdb->get_results($query, OBJECT); break; } $users_array = array(); $users_array[] = array('name' => __('Name', 'wps_export'), 'first_name' => __('First name', 'wps_export'), 'email' => __('Mail', 'wps_export'), 'tel' => __('Phone', 'wps_export'), 'registered' => __('Registered', 'wps_export')); if (!empty($list_users)) { $billing_address_indicator = get_option('wpshop_billing_address'); $billing_address_indicator = $billing_address_indicator['choice']; foreach ($list_users as $user_post) { if ($term == 'orders') { $vuser = false; } $user = get_userdata($user_post->USER_ID); $tmp_array = array(); $last_name = get_user_meta($user->ID, 'last_name', true); $first_name = get_user_meta($user->ID, 'first_name', true); if (empty($last_name)) { $last_name = $user->display_name; } if (empty($first_name)) { $first_name = '-'; } $tmp_array['name'] = $last_name; $tmp_array['first_name'] = $first_name; $tmp_array['email'] = $user->user_email; $tmp_array['tel'] = ''; $result = wps_address::get_addresses_list($user->ID); if (!empty($result) && !empty($result[$billing_address_indicator])) { foreach ($result[$billing_address_indicator] as $address_id => $address_data) { if (!empty($address_data['phone'])) { $tmp_array['tel'] = $address_data['phone']; } } } $tmp_array['registered'] = date('d M Y H:i', strtotime($user->user_registered)); $posts_id = explode(',', $user_post->POST_ID); $orders = get_posts(array('include' => $posts_id, 'post_type' => 'wpshop_shop_order', 'posts_per_page' => -1)); foreach ($orders as $order) { if ($term == 'orders') { $command = get_post_meta($order->ID, '_order_postmeta', true); if (!empty($dt1) && !empty($command['order_grand_total']) && $command['order_grand_total'] >= $dt1 || !empty($dt2) && $dt2 === true && $command['order_payment']['customer_choice']['method'] == 'free') { $vuser = true; } } } if ($term != 'orders') { $users_array[] = $tmp_array; } elseif ($vuser) { $users_array[] = $tmp_array; } } } return $users_array; }
?> <?php } ?> </a> <span class="wps-address-actions-container alignright" > <a href="#" class="wps-address-icon-black wps-address-icon-edit alignleft" id="wps-address-action-edit-for-<?php echo $address_id; ?> " title="<?php _e('Edit address', 'wpeo_geoloc'); ?> " ></a> </span> </div> <div class="wps-address-item-content"<?php if (empty($address_open)) { ?> style="display:none;"<?php } ?> > <div class="alignleft" > <?php echo wps_address::display_an_address($address); ?> </div> <?php do_action('wps-address-display-hook', array('address_id' => $address_id, 'address' => $address)); ?> </div>
</option> <?php } ?> </select> </div> <div> <ul> <?php foreach ($addresses_datas as $address_id => $address_data) { ?> <li class="<?php echo !$first ? 'wpshopHide' : ''; ?> "> <?php echo wps_address::display_an_address($address_data, '', $address_type); ?> </li> <?php $first = false; ?> <?php } ?> </ul> </div> </div> </div>
/** * Display a shipping summary( Choosen Shipping & billing address, choosen shipping mode ) * @return string */ function display_shipping_summary() { $output = ''; $billing_address_id = !empty($_SESSION['billing_address']) ? $_SESSION['billing_address'] : null; $shipping_address_id = !empty($_SESSION['shipping_address']) ? $_SESSION['shipping_address'] : null; $shipping_mode = !empty($_SESSION['shipping_method']) ? $_SESSION['shipping_method'] : null; if (!empty($billing_address_id)) { $billing_infos = get_post_meta($billing_address_id, '_wpshop_address_metadata', true); $billing_content = wps_address::display_an_address($billing_infos, $billing_address_id); if (!empty($shipping_address_id) && !empty($shipping_mode)) { $shipping_infos = get_post_meta($shipping_address_id, '_wpshop_address_metadata', true); $shipping_content = wps_address::display_an_address($shipping_infos, $shipping_address_id); $shipping_mode_option = get_option('wps_shipping_mode'); $shipping_mode = !empty($shipping_mode_option) && !empty($shipping_mode_option['modes']) && !empty($shipping_mode_option['modes'][$shipping_mode]) && !empty($shipping_mode_option['modes'][$shipping_mode]['name']) ? $shipping_mode_option['modes'][$shipping_mode]['name'] : ''; } ob_start(); require wpshop_tools::get_template_part(WPS_SHIPPING_MODE_DIR, $this->template_dir, "frontend", "shipping-infos", "summary"); $output = ob_get_contents(); ob_end_clean(); } return $output; }
/** * AJAX - Valid Checkout Step three */ function wps_checkout_valid_step_three() { $response = ''; $status = true; $shipping_address = !empty($_POST['shipping_address_id']) ? wpshop_tools::varSanitizer($_POST['shipping_address_id']) : null; $billing_address = !empty($_POST['billing_address_id']) ? wpshop_tools::varSanitizer($_POST['billing_address_id']) : null; $user_id = get_current_user_id(); $response = '<div class="wps-alert-error"><ul>'; if ($user_id != 0) { $shipping_option = get_option('wpshop_shipping_address_choice'); $billing_option = get_option('wpshop_billing_address'); $user_addresses = wps_address::get_addresses_list($user_id); if (!empty($shipping_option) && !empty($shipping_option['activate'])) { /** Check Shipping address **/ if (empty($shipping_address)) { $status = false; /** Check if user have already create a shipping address **/ if (!empty($shipping_option['choice']) && !empty($user_addresses) && !empty($user_addresses[$shipping_option['choice']])) { $response .= '<li>' . __('You must select a shipping address', 'wpshop') . '</li>'; } else { $response .= '<li>' . __('You must create a shipping address', 'wpshop') . '</li>'; } } } /** Check Billing address **/ if (empty($billing_address)) { $status = false; if (!empty($billing_option['choice']) && !empty($user_addresses) && !empty($user_addresses[$billing_option['choice']])) { $response .= '<li>' . __('You must select a billing address', 'wpshop') . '</li>'; } else { $response .= '<li>' . __('You must create a billing address', 'wpshop') . '</li>'; } } } else { $status = false; $response .= '<li>' . __('You must be logged to pass to next step', 'wpshop') . '</li>'; } $response .= '</ul></div>'; /** If no error **/ if ($status) { $_SESSION['shipping_address'] = $shipping_address; $_SESSION['billing_address'] = $billing_address; $permalink_option = get_option('permalink_structure'); $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')); /** Checking if no shipping method is required and it is a quotation or a free order **/ $shipping_option = get_option('wps_shipping_mode'); $available_shipping_method = false; if (!empty($shipping_option) && !empty($shipping_option['modes'])) { foreach ($shipping_option['modes'] as $shipping_mode_id => $shipping_mode) { if (!empty($shipping_mode['active']) && $shipping_mode['active'] == 'on') { $available_shipping_method = true; } } } if (!$available_shipping_method) { $_SESSION['shipping_method'] = 'No Shipping method required'; $order_id = !empty($_SESSION['cart']['order_id']) ? wpshop_tools::varSanitizer($_SESSION['cart']['order_id']) : 0; if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['cart_type']) && $_SESSION['cart']['cart_type'] == 'quotation') { $status = true; $payment_method = $_SESSION['payment_method'] = 'quotation'; $order_id = wpshop_checkout::process_checkout($payment_method, $order_id, get_current_user_id(), $_SESSION['billing_address'], $_SESSION['shipping_address']); $response = get_permalink(wpshop_tools::get_page_id($checkout_page_id)) . (!empty($permalink_option) ? '?' : '&') . 'order_step=6'; } elseif (!empty($_SESSION) && !empty($_SESSION['cart']) && isset($_SESSION['cart']['order_amount_to_pay_now']) && number_format($_SESSION['cart']['order_amount_to_pay_now'], 2, '.', '') == '0.00') { $status = true; $payment_method = $_SESSION['payment_method'] = 'free'; $order_id = wpshop_checkout::process_checkout($payment_method, $order_id, get_current_user_id(), $_SESSION['billing_address'], $_SESSION['shipping_address']); $permalink_option = get_option('permalink_structure'); $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')); $url = get_permalink($checkout_page_id) . (!empty($permalink_option) ? '?' : '&') . 'order_step=6'; // wpshop_tools::wpshop_safe_redirect( $url ); $response = $url; } else { $status = true; $response = get_permalink(wpshop_tools::get_page_id($checkout_page_id)) . (!empty($permalink_option) ? '?' : '&') . 'order_step=5'; } } else { $status = true; $response = get_permalink($checkout_page_id) . (!empty($permalink_option) ? '?' : '&') . 'order_step=4'; } } //Stock checking verification $this->checking_stock(); echo json_encode(array('status' => $status, 'response' => $response)); die; }
?> </div> <input type="hidden" id="wps_pos_selected_customer" value="<?php echo $customer_id; ?> " /> </div> <div class="customer_address wps-boxed"> <span class="wps-h4"><?php _e('Billing address', 'wpshop'); ?> </span> <?php $billing_option = get_option('wpshop_billing_address'); $addresses_customer = wps_address::get_addresses_list_no_hidden_attributes($customer_id); if (!empty($addresses_customer[$billing_option['choice']])) { $billing = reset($addresses_customer[$billing_option['choice']]); //echo '<strong>' . $billing['address_title']['value'] . '</strong>' . '' . '<br>'; echo @(__(wpshop_attributes::get_attribute_type_select_option_info($billing['civility']['value'], 'label', 'custom')) . ' <strong>' . $billing['address_first_name']['value'] . ' ' . $billing['address_last_name']['value'] . '</strong><br>'); echo @($billing['address']['value'] . '<br>'); echo @($billing['city']['value'] . ' ' . $billing['postcode']['value'] . ' ' . $billing['country']['value']) . '<br>'; } ?> </div> <div class="order_historic wps-boxed"> <a href="#" class="toggle-historic dashicons dashicons-arrow-down alignright"></a> <span class="wps-h4"><?php _e('Historic', 'wpshop'); ?>
&width=740&height=690" title="<?php _e('Edit this address', 'wpshop'); ?> " class="wps-address-edit-address thickbox" id="wps-address-edit-address-<?php echo $address_id; ?> "><i class="wps-icon-pencil"></i></a> <a href="" title="<?php _e('Delete this address', 'wpshop'); ?> " class="wps-address-delete-address" id="wps-address-delete-address-<?php echo $address_id; ?> -<?php echo $address_type_id; ?> "><i class="wps-icon-trash"></i></a> </span> <?php //endif; ?> </li> <li class="wps_address_li_content"> <?php echo wps_address::display_an_address($address, $address_id); ?> </li> <?php $i++; } }
/** * AJAX - Refresh customer informations */ function wps_order_refresh_customer_informations() { $status = false; $account = $addresses = ''; $customer_id = !empty($_POST['customer_id']) ? intval($_POST['customer_id']) : null; $order_id = !empty($_POST['order_id']) ? intval($_POST['order_id']) : null; if (!empty($customer_id)) { $order_metadata = get_post_meta($order_id, '_order_postmeta', true); if (!empty($order_metadata)) { $order_metadata['customer_id'] = $customer_id; update_post_meta($order_id, '_order_postmeta', $order_metadata); } // Selected customer informations $wps_account = new wps_account_ctr(); $account = $wps_account->display_account_informations($customer_id); $wps_address = new wps_address(); $addresses = $wps_address->display_addresses_interface($customer_id, true, $order_id); $status = true; } echo json_encode(array('status' => $status, 'account' => $account, 'addresses' => $addresses)); wp_die(); }
function ajax_wpshop_create_new_customer() { $result = ''; if ($_POST['attribute'][$_REQUEST['billing_address']]['varchar']['address_user_email'] != null) { /** Crerate the new customer user account */ $username = $_REQUEST['attribute'][$_REQUEST['billing_address']]['varchar']['address_user_email']; $password = wp_generate_password($length = 12, $include_standard_special_chars = false); $email = $_REQUEST['attribute'][$_REQUEST['billing_address']]['varchar']['address_user_email']; if (!empty($username) && !username_exists($username) && !empty($email) && !email_exists($email)) { $user_id = wp_create_user($username, $password, $email); $_REQUEST['user']['customer_id'] = $user_id; /** Save addresses */ $billing_set_infos = get_option('wpshop_billing_address'); $shipping_set_infos = get_option('wpshop_shipping_address_choice'); /** If it's same addresses for Shipping and Billing */ if (isset($_REQUEST['shiptobilling']) && $_REQUEST['shiptobilling'] == "on") { wpshop_account::same_billing_and_shipping_address($_REQUEST['billing_address'], $_REQUEST['shipping_address']); } if (!empty($_POST['billing_address'])) { wps_address::save_address_infos($_REQUEST['billing_address']); } if (!empty($_POST['shipping_address'])) { wps_address::save_address_infos($_REQUEST['shipping_address']); } $result = json_encode(array(true, __('Customer created', 'wpshop'), $user_id)); } else { $result = json_encode(array(false, __('A customer account is already created with this email address', 'wpshop'))); } } else { $result = json_encode(array(false, __('An email address is required', 'wpshop'))); } echo $result; die; }
/** * AJAX - Function for save address */ function wps_save_address() { global $wpshop; $status = false; $result = $address_type = $same_address_type = ''; foreach ($_POST['attribute'] as $id_group => $attribute_group) { $address_type = $id_group; $group = wps_address::get_addresss_form_fields_by_type($id_group); foreach ($group as $attribute_sets) { foreach ($attribute_sets as $attribute_set_field) { $validate = $wpshop->validateForm($attribute_set_field['content'], $_POST['attribute'][$id_group], 'address_edition'); } if ($validate) { $shipping_save = self::save_address_infos($id_group); // echo '<pre>'; print_r($_POST); echo '</pre>'; if (!empty($_POST['wps-shipping-to-billing'])) { $_POST['wps-shipping-to-billing-id'] = $shipping_save['current_id']; $billing_option = get_option('wpshop_billing_address'); $shipping_option = get_option('wpshop_shipping_address_choice'); self::shipping_to_billing($shipping_option['choice'], $billing_option['choice']); self::save_address_infos($billing_option['choice']); $same_address_type = $billing_option['choice']; } $status = true; } else { if (!empty($wpshop->errors)) { $result = '<div class="wps-alert wps-alert-error">' . __('Some errors have been detected', 'wpshop') . ' : <ul>'; foreach ($wpshop->errors as $error) { $result .= '<li>' . $error . '</li>'; } $result .= '</div>'; } } } } echo json_encode(array($status, $result, $address_type, $same_address_type)); die; }
/** * META-BOX CONTENT - Display Customer's addresses in customer back-office interface */ function wps_customer_addresses_list() { global $post; $output = ''; $wps_addresses = new wps_address(); $output = $wps_addresses->display_addresses_interface($post->post_author); echo $output; }
<?php $box_content = wps_address::display_address_interface_content($address_type_id, $address_title, '', $type, $customer_id, true, $order_id); ?> <div> <div class="<?php echo $extra_class; ?> wps-boxed"> <span class="wps-h3"><?php echo $address_title; ?> <a id="wps-add-an-address-<?php echo $address_type_id; ?> " class="add-new-h2 alignright thickbox" href="<?php echo admin_url('admin-ajax.php'); ?> ?action=wps_order_load_address_edit_form&address_type=<?php echo $address_type_id; ?> &customer_id=<?php echo $customer_id; ?> &width=740&height=690"><i class="wps-icon-plus"></i><?php printf(__('Create a %s', 'wpshop'), strtolower($address_title)); ?> </a> </span> <div style="clear : both;">
/** * AJAX - Création d'un nouveau client / Create a new customer */ function create_customer() { global $wpdb; $response = array('status' => false, 'output' => __('An error occured while saving customer', 'wpshop'), 'customer_id' => -1); /** Check if a attribute set id have been sended in order to check if therer are some check to do on sended input */ $customer_attributes = wpshop_attributes_set::getAttributeSetDetails($_POST['wps-customer-account-set-id'], "'valid'"); /** Read sended values for checking */ $email_founded = false; $email_field = $last_name_field = $first_name_field = ''; if (!empty($_POST)) { foreach ($_POST['attribute'] as $attribute_type => $attributes) { foreach ($attributes as $attribute_code => $attribute_value) { $query = $wpdb->prepare("SELECT frontend_verification FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s", $attribute_code); $current_attribute = $wpdb->get_var($query); if ('email' == $current_attribute) { $email_founded = true; $email_field = $attribute_code; $email_field_type = $attribute_type; } else { if (strpos($attribute_code, 'last_name')) { $last_name_field = $attribute_code; $last_name_field_type = $attribute_type; } else { if (strpos($attribute_code, 'first_name')) { $first_name_field = $attribute_code; $first_name_field_type = $attribute_type; } } } } } } /** Define customer email field value */ $customer_email = $_POST['attribute'][$email_field_type][$email_field]; $customer_last_name = !empty($_POST) && !empty($_POST['attribute']) && !empty($_POST['attribute'][$last_name_field_type]) && !empty($_POST['attribute'][$last_name_field_type][$last_name_field]) ? $_POST['attribute'][$last_name_field_type][$last_name_field] : ''; $customer_first_name = !empty($_POST) && !empty($_POST['attribute']) && !empty($_POST['attribute'][$first_name_field_type]) && !empty($_POST['attribute'][$first_name_field_type][$first_name_field]) ? $_POST['attribute'][$first_name_field_type][$first_name_field] : ''; if ($email_founded && is_email($customer_email)) { /** Check if current e-mail address does not already exists */ $user_id = username_exists($customer_email); if (empty($user_id)) { /** Create the user with a random password */ $random_password = wp_generate_password(12, false); $user_id = wp_create_user($customer_email, $random_password, $customer_email); if (!is_wp_error($user_id)) { update_user_meta($user_id, 'last_name', $customer_last_name); update_user_meta($user_id, 'first_name', $customer_first_name); /** Build a response for customer first letter - Specific action (POS) */ if (!empty($customer_last_name)) { $field_for_letter = $customer_last_name; } elseif (!empty($customer_first_name)) { $field_for_letter = $customer_first_name; } else { $field_for_letter = $customer_email; } $response['letter'] = substr($field_for_letter, 0, 1); /** Build response */ $response['status'] = true; $response['output'] = __('Customer created succesfully', 'wpshop'); /** Create customer address from sended data **/ $_REQUEST['user']['customer_id'] = $user_id; $attribute_to_save = $_POST['attribute']; unset($_POST['attribute']); $_POST['attribute'][$_POST['wps-customer-account-set-id']] = $attribute_to_save; wps_address::save_address_infos($_POST['wps-customer-account-set-id']); } } else { $response['output'] = __('An account is already created with this e-mail address', 'wpshop'); } $response['customer_id'] = $user_id; } else { $response['output'] = __('An email address is required', 'wpshop'); } wp_die(json_encode($response)); }
/** * AJAX - Choose customer to create order */ function wps_order_choose_customer() { $status = false; $billing_data = $shipping_data = ''; $customer_id = !empty($_POST['customer_id']) ? intval($_POST['customer_id']) : null; if (!empty($customer_id)) { $wps_address = new wps_address(); $billing_option = get_option('wpshop_billing_address'); $shipping_option = get_option('wpshop_shipping_address_choice'); $billing_option = $billing_option['choice']; $customer_addresses_list = wps_address::get_addresses_list($customer_id); $status = true; $billing_data = '<div class="wps-alert-info">' . sprintf(__('No Billing address created, <a href="%s" title="' . __('Create a new billing address', 'wpshop') . '" class="thickbox">create one</a>', 'wpshop'), admin_url('admin-ajax.php') . '?action=wps-add-an-address-in-admin&address_type=' . $billing_option . '&customer_id=' . $customer_id . '&height=600') . '</div>'; if (!empty($shipping_option) && !empty($shipping_option['activate'])) { $shipping_option = $shipping_option['choice']; $shipping_data = '<div class="wps-alert-info">' . sprintf(__('No shipping address created, <a href="%s" title="' . __('Create a new shipping address', 'wpshop') . '" class="thickbox">create one</a>', 'wpshop'), admin_url('admin-ajax.php') . '?action=wps-add-an-address-in-admin&address_type=' . $shipping_option . '&customer_id=' . $customer_id . '&height=600') . '</div>'; } if (!empty($customer_addresses_list)) { foreach ($customer_addresses_list as $address_type => $customer_addresses) { if ($billing_option == $address_type) { $billing_data = $wps_address->display_address_in_administration($customer_addresses, $address_type); } else { $shipping_data = $wps_address->display_address_in_administration($customer_addresses, $address_type); } } } } echo json_encode(array('status' => $status, 'billing_data' => $billing_data, 'shipping_data' => $shipping_data)); wp_die(); }
/** * Save informations for current entity */ public static function save_entities_custom_informations($post) { global $wpdb; global $wpshop_account; $post_id = !empty($_REQUEST['post_ID']) ? intval(wpshop_tools::varSanitizer($_REQUEST['post_ID'])) : null; if (!empty($post_id) && empty($_POST['edit_other_thing']) || !empty($_REQUEST['post_ID']) && !(bool) $_POST['edit_other_thing'] && get_post_type($_REQUEST['post_ID']) != WPSHOP_NEWTYPE_IDENTIFIER_ORDER) { $current_post_type = get_post_type($post_id); /* Vérification de l'existence de l'envoi de l'identifiant du set d'attribut */ if (!empty($_REQUEST[$current_post_type . '_attribute_set_id'])) { $attribute_set_id = intval(wpshop_tools::varSanitizer($_REQUEST[$current_post_type . '_attribute_set_id'])); $attribet_set_infos = wpshop_attributes_set::getElement($attribute_set_id, "'valid'", 'id'); if ($attribet_set_infos->entity == $_REQUEST['post_type']) { /* Enregistrement de l'identifiant du set d'attribut associé à l'entité */ update_post_meta($post_id, sprintf(WPSHOP_ATTRIBUTE_SET_ID_META_KEY, $current_post_type), $attribute_set_id); /* Enregistrement de tous les attributs */ if (!empty($_REQUEST[$current_post_type . '_attribute'])) { /* Traduction des virgule en point pour la base de donnees */ if (!empty($_REQUEST[$current_post_type . '_attribute']['decimal'])) { foreach ($_REQUEST[$current_post_type . '_attribute']['decimal'] as $attributeName => $attributeValue) { if (!is_array($attributeValue)) { $_REQUEST[$current_post_type . '_attribute']['decimal'][$attributeName] = str_replace(',', '.', $_REQUEST[$current_post_type . '_attribute']['decimal'][$attributeName]); } } } /* Enregistrement des valeurs des différents attributs */ wpshop_attributes::saveAttributeForEntity($_REQUEST[$current_post_type . '_attribute'], wpshop_entities::get_entity_identifier_from_code($current_post_type), $post_id, WPSHOP_CURRENT_LOCALE); /* Enregistrement des valeurs des attributs dans les metas de l'entité => Permet de profiter de la recherche native de wordpress */ $productMetaDatas = array(); foreach ($_REQUEST[$current_post_type . '_attribute'] as $attributeType => $attributeValues) { foreach ($attributeValues as $attributeCode => $attributeValue) { $productMetaDatas[$attributeCode] = $attributeValue; } } update_post_meta($_REQUEST['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas); } } } if (!empty($_REQUEST['attribute'])) { $current_id = array(); foreach ($_REQUEST['attribute'] as $key => $values) { $ad_id = ''; $addresses_id = get_post_meta($_REQUEST['post_ID'], '_wpshop_attached_address', true); if (!empty($addresses_id)) { foreach ($addresses_id as $address_id) { $address_type = get_post_meta($address_id, '_wpshop_address_attribute_set_id', true); if ($address_type == $key) { $ad_id = $address_id; } } } $_REQUEST['item_id'] = $ad_id; $result = wps_address::save_address_infos($key); $current_id[] = $result['current_id']; } update_post_meta($_REQUEST['post_ID'], '_wpshop_attached_address', $current_id); } else { $current_id = array(); if (!empty($_REQUEST['address_type'])) { foreach ($_REQUEST['address_type'] as $key => $value) { $current_id[] = $value; } } update_post_meta($_REQUEST['post_ID'], '_wpshop_entity_attached_address', $current_id); } } /** Save price infos **/ if (!empty($_REQUEST) && !empty($_REQUEST['post_ID']) && !empty($_REQUEST['post_type']) && $_REQUEST['post_type'] == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) { } flush_rewrite_rules(); }
/** * Display the differents forms fields * @param string $type : Type of address * @param string $first : Customer first address ? * @param string $referer : Referer website page * @param string $admin : Display this form in admin panel */ function display_form_fields($type, $id = '', $first = '', $referer = '', $special_values = array(), $options = array(), $display_for_admin = array(), $other_customer = '') { global $wpshop, $wpshop_form, $wpdb; $choosen_address = get_option('wpshop_billing_address'); $shipping_address = get_option('wpshop_shipping_address_choice'); $output_form_fields = $form_model = ''; $user_id = !empty($other_customer) ? $other_customer : get_current_user_id(); if (empty($type)) { $type = $choosen_address['choice']; } $result = wps_address::get_addresss_form_fields_by_type($type, $id); /** Check if it's shipping or billing **/ if ($type == $choosen_address['choice']) { $form_model = !empty($choosen_address['display_model']) ? $choosen_address['display_model'] : null; } elseif ($type == $shipping_address['choice']) { $form_model = !empty($shipping_address['display_model']) ? $shipping_address['display_model'] : null; } $form = $result[$type]; // Take the post id to make the link with the post meta of address $values = array(); // take the address informations $current_item_edited = !empty($id) ? (int) wpshop_tools::varSanitizer($id) : null; foreach ($form as $group_id => $group_fields) { if (empty($options) || !empty($options) && $options['title']) { $output_form_fields .= '<h2>' . __($group_fields['name'], 'wpshop') . '</h2>'; } $end_line_indicator = 0; $fields_limit_per_line = -1; foreach ($group_fields['content'] as $key => $field) { $attribute_def = wpshop_attributes::getElement($field['name'], $element_status = "'valid'", $field_to_search = 'code'); /** Grid opening **/ if (!empty($form_model) && !empty($form_model[$group_id]) && in_array('wps-attribute-end-line-' . $end_line_indicator, $form_model[$group_id]) && $fields_limit_per_line == -1) { $current_key = array_search('wps-attribute-end-line-' . $end_line_indicator, $form_model[$group_id]); $current_attribute_key = array_search('attribute_' . $attribute_def->id, $form_model[$group_id]); if ($current_attribute_key > $current_key) { /** Define limit **/ if (in_array('wps-attribute-end-line-' . ($end_line_indicator + 1), $form_model[$group_id])) { $next_key = array_search('wps-attribute-end-line-' . ($end_line_indicator + 1), $form_model[$group_id]); $fields_limit_per_line = $next_key - $current_key - 1; $fields_limit_per_line = $fields_limit_per_line > 6 ? 6 : $fields_limit_per_line; } else { $current_key = array_search('wps-attribute-end-line-' . $end_line_indicator, $form_model[$group_id]); $end_tab = count($form_model[$group_id]) - 1; $fields_limit_per_line = $end_tab - $current_key - 1; $fields_limit_per_line = $fields_limit_per_line > 6 ? 6 : $fields_limit_per_line; } if (!empty($fields_limit_per_line) && $fields_limit_per_line != -1) { if ($fields_limit_per_line == 1) { $output_form_fields .= '<div class="wps-row">'; } else { $output_form_fields .= '<div class="wps-row wps-gridwrapper' . $fields_limit_per_line . '-padded">'; } } } } if (empty($options['field_to_hide']) || !is_array($options['field_to_hide']) || !in_array($key, $options['field_to_hide'])) { $attributeInputDomain = 'attribute[' . $type . '][' . $field['data_type'] . ']'; // Test if there is POST var or if user have already fill his address infos and fill the fields with these infos if (!empty($_POST)) { $referer = !empty($_POST['referer']) ? $_POST['referer'] : ''; if (!empty($form['id']) && !empty($field['name']) && isset($_POST[$form['id'] . "_" . $field['name']])) { $value = $_POST[$form['id'] . "_" . $field['name']]; } } // Fill Automaticly some fields when it's an address creation switch ($field['name']) { case 'address_title': if (empty($field['value'])) { /** Count Billing and shipping address **/ $billing_address_count = $shipping_address_count = 1; if (get_current_user_id() != 0) { $addresses = get_posts(array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, 'post_parent' => get_current_user_id(), 'post_status' => 'draft')); if (!empty($addresses)) { foreach ($addresses as $address) { $address_type = get_post_meta($address->ID, '_wpshop_address_attribute_set_id', true); if (!empty($address_type)) { if (!empty($shipping_address_choice['choice']) && $address_type == $shipping_address_choice['choice']) { $shipping_address_count++; } else { $billing_address_count++; } } } } } $field['value'] = $type == $choosen_address['choice'] ? __('Billing address', 'wpshop') . ($billing_address_count > 1 ? ' ' . $billing_address_count : '') : __('Shipping address', 'wpshop') . ($shipping_address_count > 1 ? ' ' . $shipping_address_count : ''); } break; case 'address_last_name': if (empty($field['value'])) { $usermeta_last_name = get_user_meta($user_id, 'last_name', true); $field['value'] = !empty($usermeta_last_name) ? $usermeta_last_name : ''; } break; case 'address_first_name': if (empty($field['value'])) { $usermeta_first_name = get_user_meta($user_id, 'first_name', true); $field['value'] = !empty($usermeta_first_name) ? $usermeta_first_name : ''; } break; case 'address_user_email': if (empty($field['value'])) { $user_infos = get_userdata($user_id); $field['value'] = !empty($user_infos) && !empty($user_infos->user_email) ? $user_infos->user_email : ''; } break; default: $field['value'] = !empty($field['value']) ? $field['value'] : ''; break; } /** Fill fields if $_POST exist **/ if (!empty($_POST['attribute'][$type][$field['data_type']][$field['name']])) { $field['value'] = $_POST['attribute'][$type][$field['data_type']][$field['name']]; } if ($field['name'] == 'address_title' && !empty($first) && $type == __('Billing address', 'wpshop')) { $value = __('Billing address', 'wpshop'); } elseif ($field['name'] == 'address_title' && !empty($first) && $type == __('Shipping address', 'wpshop')) { $value = __('Shipping address', 'wpshop'); } if (!empty($special_values[$field['name']])) { $field['value'] = $special_values[$field['name']]; } $template = 'wpshop_account_form_input'; if ($field['type'] == 'hidden') { $template = 'wpshop_account_form_hidden_input'; } if ($field['frontend_verification'] == 'country') { $field['type'] = 'select'; /** display a country list **/ $countries_list = unserialize(WPSHOP_COUNTRY_LIST); $possible_values = array_merge(array('' => __('Choose a country')), $countries_list); $limit_countries_list = get_option('wpshop_limit_country_list'); $default_country_choice = get_option('wpshop_country_default_choice'); if (!empty($limit_countries_list)) { $possible_values = array(); if (count($limit_countries_list) > 1) { $possible_values[''] = __('Choose a country'); } foreach ($limit_countries_list as $country_code) { if (!empty($countries_list) && !empty($countries_list[$country_code])) { $possible_values[$country_code] = $countries_list[$country_code]; } } } $field['value'] = !empty($default_country_choice) && array_key_exists($default_country_choice, $possible_values) ? $default_country_choice : ''; $field['possible_value'] = $possible_values; $field['valueToPut'] = 'index'; } $element_simple_class = str_replace('"', '', str_replace('class="', '', str_replace('wpshop_input_datetime', '', $field['option']))); $input_tpl_component = array(); //$input_tpl_component['CUSTOMER_FORM_INPUT_MAIN_CONTAINER_CLASS'] = ' wsphop_customer_account_form_container wsphop_customer_account_form_container_' . $field['name'] . $element_simple_class; $input_tpl_component['CUSTOMER_FORM_INPUT_LABEL'] = $field['type'] != 'hidden' ? stripslashes(__($field['label'], 'wpshop')) . ($field['required'] == 'yes' ? ' <em>*</em>' : '') : ''; $input_tpl_component['CUSTOMER_FORM_INPUT_LABEL_OPTIONS'] = ' for="' . $field['id'] . '"'; $input_tpl_component['CUSTOMER_FORM_INPUT_FIELD'] = wpshop_form::check_input_type($field, $attributeInputDomain); //$output_form_fields .= wpshop_display::display_template_element($template, $input_tpl_component); $output_form_fields .= wpshop_display::display_template_element('wps_address_field', $input_tpl_component, array(), 'wpshop'); unset($input_tpl_component); if ($field['_need_verification'] == 'yes') { $field['name'] = $field['name'] . '2'; $field['id'] = $field['id'] . '2'; $element_simple_class = str_replace('"', '', str_replace('class="', '', str_replace('wpshop_input_datetime', '', $field['option']))); $input_tpl_component = array(); $input_tpl_component['CUSTOMER_FORM_INPUT_LABEL'] = __($field['label'], 'wpshop') . ($field['required'] == 'yes' && !is_admin() || $field['name'] == 'address_user_email' && is_admin() ? ' <span class="required">*</span>' : ''); $input_tpl_component['CUSTOMER_FORM_INPUT_LABEL_OPTIONS'] = ' for="' . $field['id'] . '"'; $input_tpl_component['CUSTOMER_FORM_INPUT_MAIN_CONTAINER_CLASS'] = ' wsphop_customer_account_form_container wsphop_customer_account_form_container_' . $field['name'] . $element_simple_class; $input_tpl_component['CUSTOMER_FORM_INPUT_LABEL'] = sprintf(__('Confirm %s', 'wpshop'), strtolower(__($field['label'], 'wpshop'))) . ($field['required'] == 'yes' && !is_admin() ? ' <span class="required">*</span>' : ''); $input_tpl_component['CUSTOMER_FORM_INPUT_FIELD'] = wpshop_form::check_input_type($field, $attributeInputDomain) . $field['options']; //$output_form_fields .= wpshop_display::display_template_element($template, $input_tpl_component); $output_form_fields .= wpshop_display::display_template_element('wps_address_field', $input_tpl_component, array(), 'wpshop'); unset($input_tpl_component); } } /** Grid closing **/ if ($fields_limit_per_line != -1 && !empty($fields_limit_per_line)) { $fields_limit_per_line--; if ($fields_limit_per_line == 0) { $output_form_fields .= '</div>'; $fields_limit_per_line = -1; $end_line_indicator++; } } } } if ($type == $choosen_address['choice']) { $output_form_fields .= '<input type="hidden" name="billing_address" value="' . $choosen_address['choice'] . '" />'; } $shipping_address_options = get_option('wpshop_shipping_address_choice'); if ($type == $shipping_address_options['choice']) { $output_form_fields .= '<input type="hidden" name="shipping_address" value="' . $shipping_address_options['choice'] . '" />'; } $output_form_fields .= '<input type="hidden" name="edit_other_thing" value="' . false . '" /><input type="hidden" name="referer" value="' . $referer . '" /> <input type="hidden" name="type_of_form" value="' . $type . '" /><input type="hidden" name="attribute[' . $type . '][item_id]" value="' . $current_item_edited . '" />'; $output_form_fields .= $user_id != get_current_user_id() ? '<input type="hidden" name="user[customer_id]" value="' . $user_id . '" />' : ''; if (empty($first)) { $output_form_fields = wpshop_display::display_template_element('wpshop_customer_addresses_form', array('CUSTOMER_ADDRESSES_FORM_CONTENT' => $output_form_fields, 'CUSTOMER_ADDRESSES_FORM_BUTTONS' => '')); } return $output_form_fields; }
/** * ACCOUNT - Save account informations */ function wps_save_account_informations() { global $wpdb; global $wpshop; $status = false; $response = ''; $exclude_user_meta = array('user_email', 'user_pass'); $wps_entities = new wpshop_entities(); $element_id = $wps_entities->get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); $user_id = get_current_user_id(); if (!empty($element_id) && !empty($user_id)) { $query = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $user_id); $cid = $wpdb->get_var($query); $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $element_id); $attribute_set_id = $wpdb->get_var($query); if (!empty($attribute_set_id)) { $group = wps_address::get_addresss_form_fields_by_type($attribute_set_id); foreach ($group as $attribute_sets) { foreach ($attribute_sets as $attribute_set_field) { $validate = $wpshop->validateForm($attribute_set_field['content'], $_POST['attribute']); if (empty($wpshop->errors)) { $user_name = !empty($_POST['attribute']['varchar']['user_login']) ? $_POST['attribute']['varchar']['user_login'] : $_POST['attribute']['varchar']['user_email']; $user_pass = !empty($_POST['attribute']['varchar']['user_pass']) ? $_POST['attribute']['varchar']['user_pass'] : ''; $wpshop_attributes = new wpshop_attributes(); foreach ($attribute_set_field['content'] as $attribute) { $attribute_def = wpshop_attributes::getElement($attribute['name'], "'valid'", 'code'); if (!in_array($attribute['name'], $exclude_user_meta)) { update_user_meta($user_id, $attribute['name'], wpshop_tools::varSanitizer($_POST['attribute'][$attribute['data_type']][$attribute['name']])); } else { wp_update_user(array('ID' => $user_id, $attribute['name'] => wpshop_tools::varSanitizer($_POST['attribute'][$attribute['data_type']][$attribute['name']]))); } //Save data in attribute tables, ckeck first if exist to know if Insert or Update $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($attribute['data_type']) . ' WHERE entity_type_id = %d AND entity_id = %d AND attribute_id = %d', $element_id, $cid, $attribute_def->id); $checking_attribute_exist = $wpdb->get_results($query); if (!empty($checking_attribute_exist)) { $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($attribute['data_type']), array('value' => wpshop_tools::varSanitizer($_POST['attribute'][$attribute['data_type']][$attribute['name']])), array('entity_type_id' => $element_id, 'entity_id' => $cid, 'attribute_id' => $attribute_def->id)); } else { $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($attribute['data_type']), array('entity_type_id' => $element_id, 'attribute_id' => $attribute_def->id, 'entity_id' => $cid, 'user_id' => $user_id, 'creation_date_value' => current_time('mysql', 0), 'language' => 'fr_FR', 'value' => wpshop_tools::varSanitizer($_POST['attribute'][$attribute['data_type']][$attribute['name']]))); } } /** Update newsletter user preferences **/ $newsletter_preferences = array(); if (!empty($_POST['newsletters_site'])) { $newsletter_preferences['newsletters_site'] = 1; } if (!empty($_POST['newsletters_site_partners'])) { $newsletter_preferences['newsletters_site_partners'] = 1; } update_user_meta($user_id, 'user_preferences', $newsletter_preferences); $status = true; } else { $response = '<div class="wps-alert-error">' . __('Some errors have been detected', 'wpshop') . ' : <ul>'; foreach ($wpshop->errors as $error) { $response .= '<li>' . $error . '</li>'; } $response .= '</div>'; } } } } } echo json_encode(array('status' => $status, 'response' => $response)); wp_die(); }