function ajax_wpshop_restart_the_order() { global $wpshop_cart, $wpdb; $status = $add_to_cart_checking = $manage_stock_checking_bool = false; $add_to_cart_checking_message = ''; $result = __('Error, you cannot restart this order', 'wpshop'); $order_id = !empty($_POST['order_id']) ? wpshop_tools::varSanitizer($_POST['order_id']) : null; $is_make_order_again = !empty($_POST['make_order_again']) ? wpshop_tools::varSanitizer($_POST['make_order_again']) : null; if (!empty($order_id)) { $order_meta = get_post_meta($order_id, '_order_postmeta', true); $_SESSION['cart'] = array(); $_SESSION['cart']['order_items'] = array(); $wpshop_cart_type = $order_meta['cart_type']; if (!empty($order_meta) && !empty($order_meta['order_items'])) { $wpshop_cart_type = $order_meta['cart_type']; foreach ($order_meta['order_items'] as $item_key => $item) { $item_meta = get_post_meta($item['item_id'], '_wpshop_product_metadata', true); $stock = $item_meta['product_stock']; $qty = $item['item_qty']; $item_option = get_post_meta($item['item_id'], '_wpshop_product_options', true); if (!empty($item_meta['manage_stock'])) { $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $item_meta['manage_stock']); $manage_stock_checking = $wpdb->get_var($query); if (!empty($manage_stock_checking) && strtolower(__($manage_stock_checking, 'wpshop')) == strtolower(__('Yes', 'wpshop'))) { $manage_stock_checking_bool = true; } } else { if (get_post_type($item['item_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { $parent_product = wpshop_products::get_parent_variation($item['item_id']); if (!empty($parent_product) && !empty($parent_product['parent_post_meta'])) { $parent_metadata = $parent_product['parent_post_meta']; if (!empty($parent_product['parent_post_meta']['manage_stock'])) { $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $parent_product['parent_post_meta']['manage_stock']); $manage_stock_checking = $wpdb->get_var($query); if (!empty($manage_stock_checking) && strtolower(__($manage_stock_checking, 'wpshop')) == strtolower(__('Yes', 'wpshop'))) { $manage_stock_checking_bool = true; $stock = $parent_product['parent_post_meta']['product_stock']; } } } } } /** Checking stock **/ if (empty($item_meta['manage_stock']) || !empty($item_meta['manage_stock']) && !$manage_stock_checking_bool || !empty($item_meta['manage_stock']) && $manage_stock_checking_bool && $stock >= $qty) { $_SESSION['cart']['order_items'][$item_key] = $item; } else { $add_to_cart_checking = true; $add_to_cart_checking_message = __('Some products cannot be added to cart because they are out of stock', 'wpshop'); } } $wps_cart_ctr = new wps_cart(); $order = $wps_cart_ctr->calcul_cart_information(array()); $order['cart_type'] = $wpshop_cart_type; $wps_cart_ctr->store_cart_in_session($order); } if (empty($is_make_order_again)) { $_SESSION['order_id'] = $order_id; } $status = true; $result = get_permalink(get_option('wpshop_cart_page_id')); } $response = array('status' => $status, 'response' => $result, 'add_to_cart_checking' => $add_to_cart_checking, 'add_to_cart_checking_message' => $add_to_cart_checking_message); echo json_encode($response); die; }
public static function direct_payment_link($token, $order_id, $login) { global $wpdb; if (!empty($token) && !empty($order_id) && !empty($login)) { /** Verify informations **/ $query = $wpdb->prepare('SELECT * FROM ' . $wpdb->users . ' WHERE user_login = %s AND user_activation_key = %s', $login, $token); $user_infos = $wpdb->get_row($query); if (!empty($user_infos)) { /** Connect the user **/ $secure_cookie = is_ssl() ? true : false; wp_set_auth_cookie($user_infos->ID, true, $secure_cookie); /** Add order to SESSION **/ $order_meta = get_post_meta($order_id, '_order_postmeta', true); $_SESSION['cart'] = array(); $_SESSION['cart']['order_items'] = array(); if (!empty($order_meta) && !empty($order_meta['order_items'])) { $wpshop_cart_type = 'cart'; foreach ($order_meta['order_items'] as $item) { $_SESSION['cart']['order_items'][$item['item_id']] = $item; } $wps_cart_ctr = new wps_cart(); $order = $wps_cart_ctr->calcul_cart_information(array()); $wps_cart_ctr->store_cart_in_session($order); } $_SESSION['order_id'] = $order_id; $wpdb->update($wpdb->users, array('user_activation_key' => ''), array('user_login' => $login)); wpshop_tools::wpshop_safe_redirect(get_permalink(wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')))); } else { wpshop_tools::wpshop_safe_redirect(get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id')))); } } }
/** * AJAX - Update cart informations */ function wps_orders_update_cart_informations() { $status = false; $order_id = !empty($_POST['order_id']) ? intval($_POST['order_id']) : ''; $shipping_cost = !empty($_POST['shipping_cost']) ? wpshop_tools::varSanitizer($_POST['shipping_cost']) : ''; $discount_value = !empty($_POST['discount_amount']) ? wpshop_tools::varSanitizer($_POST['discount_amount']) : ''; $discount_type = !empty($_POST['discount_type']) ? wpshop_tools::varSanitizer($_POST['discount_type']) : ''; if (!empty($order_id)) { $order_meta = get_post_meta($order_id, '_order_postmeta', true); $order_meta['order_shipping_cost'] = $shipping_cost; //Add discounts if exists if (!empty($discount_value) && !empty($discount_type)) { $order_meta['order_discount_type'] = $discount_type; $order_meta['order_discount_value'] = $discount_value; } $wps_cart = new wps_cart(); $order_meta = $wps_cart->calcul_cart_information(array(), '', $order_meta, true); update_post_meta($order_id, '_order_postmeta', $order_meta); $status = true; } echo json_encode(array('status' => $status)); wp_die(); }
/** Ajax action to reload summary cart */ public static function wps_reload_summary_cart() { $wps_cart = new wps_cart(); $result = $wps_cart->resume_cart_content(); echo json_encode(array('response' => $result)); die; }
/** * Checking stock in differents checkout steps */ function checking_stock() { if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) { foreach ($_SESSION['cart']['order_items'] as $item_id => $item) { $wps_product = new wps_product_ctr(); $checking = $wps_product->check_stock($item['item_id'], $item['item_qty'], $item_id); if ($checking !== true) { unset($_SESSION['cart']['order_items'][$item_id]); $wps_cart_ctr = new wps_cart(); $order = $wps_cart_ctr->calcul_cart_information(array()); $wps_cart_ctr->store_cart_in_session($order); } } } }
/** * AJAX - Calculate Shipping cost */ function wps_calculate_shipping_cost() { $status = false; $result = ''; $chosen_method = !empty($_POST['chosen_method']) ? wpshop_tools::varSanitizer($_POST['chosen_method']) : null; if (!empty($chosen_method)) { $_SESSION['shipping_method'] = $chosen_method; $wps_cart = new wps_cart(); $order = $wps_cart->calcul_cart_information(array()); $wps_cart->store_cart_in_session($order); $status = true; } $response = array('status' => $status); echo json_encode($response); die; }
} else { $array = array('result' => false, 'message' => __('An error occured', 'wpshop')); } echo json_encode($array); break; case 'related_products': $data = wpshop_products::product_list(false, $_REQUEST['search']); $array = array(); foreach ($data as $d) { $array[] = array('id' => $d->ID, 'name' => $d->post_title); } echo json_encode($array); break; case 'ajax_cartAction': global $wpshop_cart; switch ($_REQUEST['action']) { case 'applyCoupon': $wps_coupon_ctr = new wps_coupon_ctr(); $result = $wps_coupon_ctr->applyCoupon($_REQUEST['coupon_code']); if ($result['status'] === true) { $wps_cart_ctr = new wps_cart(); $order = $wps_cart_ctr->calcul_cart_information(array()); $wps_cart_ctr->store_cart_in_session($order); echo json_encode(array(true, '')); } else { echo json_encode(array(false, $result['message'])); } break; } break; }
/** * AJAX - Traite la commande / Process checkout */ function wps_pos_process_checkout() { $status = false; $output = $message = ''; $order_id = !empty($_POST['order_id']) ? wpshop_tools::varSanitizer($_POST['order_id']) : null; $payment_method = !empty($_POST['wpspos-payment-method']) ? wpshop_tools::varSanitizer($_POST['wpspos-payment-method']) : null; $customer_id = !empty($_SESSION['cart']['customer_id']) ? wpshop_tools::varSanitizer($_SESSION['cart']['customer_id']) : null; $payment_amount = !empty($_POST['wps-pos-total-order-amount']) ? wpshop_tools::varSanitizer($_POST['wps-pos-total-order-amount']) : null; $received_payment_amount = !empty($_POST['wpspos-order-received-amount']) ? wpshop_tools::varSanitizer($_POST['wpspos-order-received-amount']) : $payment_amount; if (!empty($customer_id)) { //if ( !empty( $payment_method ) ) { //$_SESSION['shipping_method'] = __('Point of sale method', 'wpshop'); $_SESSION['shipping_method'] = 'default_shipping_mode_for_pos'; if (empty($order_id) && !empty($payment_method)) { $order_id = wpshop_checkout::process_checkout($payment_method, '', $customer_id, $_SESSION['billing_address'], $_SESSION['shipping_address']); wp_update_post(array('ID' => $order_id, 'post_parent' => get_current_user_id())); } if (!empty($order_id)) { $status = true; if (!empty($received_payment_amount) && empty($_SESSION['wpspos_is_quotation']) && empty($_SESSION['wpspos_is_receipt'])) { $params_array = array('method' => $payment_method, 'waited_amount' => $payment_amount, 'status' => 'payment_received', 'author' => $customer_id, 'payment_reference' => '', 'date' => current_time('mysql', 0), 'received_amount' => 'money' == $payment_method && number_format((double) $received_payment_amount, 2, '.', '') > number_format((double) $payment_amount, 2, '.', '') ? $payment_amount : $received_payment_amount); wpshop_payment::check_order_payment_total_amount($order_id, $params_array, 'completed'); } /** Get order content */ $order_postmeta = get_post_meta($order_id, '_order_postmeta', true); ob_start(); require_once wpshop_tools::get_template_part(WPSPOS_DIR, WPSPOS_TEMPLATES_MAIN_DIR, 'backend/order', 'order', 'complete'); $output = ob_get_contents(); ob_end_clean(); /** Empty the cart */ if (!empty($order_postmeta) && !empty($order_postmeta['order_status']) && 'completed' == $order_postmeta['order_status']) { $wps_cart = new wps_cart(); $wps_cart->empty_cart(); } $message = __('Order have been saved', 'wps-pos-i18n'); } else { $message = __('No order have been found', 'wps-pos-i18n'); } /*} else { $message = __( 'Please choose a payment method for order', 'wps-pos-i18n' ); }*/ } else { $message = __('No customer has been selected for current order', 'wps-pos-i18n'); } wp_die(json_encode(array('status' => $status, 'output' => $output, 'message' => $message))); }