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; }
/** * 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(); }
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')))); } } }
/** * 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; }