function eStore_gateway_specific_buy_now_submit_listener() { if (isset($_REQUEST['eStore_gs_buy_now_submit'])) { $wp_eStore_config = WP_eStore_Config::getInstance(); $cookie_domain = eStore_get_top_level_domain(); setcookie("cart_in_use", "true", time() + 21600, "/", $cookie_domain); if (function_exists('wp_cache_serve_cache_file')) { //WP Super cache workaround setcookie("comment_author_", "eStore", time() + 21600, "/", $cookie_domain); } unset($_SESSION['eStore_last_action_msg']); unset($_SESSION['eStore_last_action_msg_2']); unset($_SESSION['eStore_last_action_msg_3']); unset($_SESSION['eStore_gs_bn_co_error_msg']); if (isset($_SESSION['eStore_cart'])) { unset($_SESSION['eStore_cart']); } //sanitize data $_REQUEST['product'] = strip_tags($_REQUEST['product']); //for PHP5.2 use filter_var($_REQUEST['product'], FILTER_SANITIZE_STRING); $_REQUEST['add_qty'] = strip_tags($_REQUEST['add_qty']); $_REQUEST['item_number'] = strip_tags($_REQUEST['item_number']); if (isset($_REQUEST['custom_price'])) { $_REQUEST['custom_price'] = strip_tags($_REQUEST['custom_price']); } if (isset($_REQUEST['price'])) { $_REQUEST['price'] = strip_tags($_REQUEST['price']); } isset($_REQUEST['shipping']) ? $_REQUEST['shipping'] = strip_tags($_REQUEST['shipping']) : ($_REQUEST['shipping'] = ''); isset($_REQUEST['cartLink']) ? $_REQUEST['cartLink'] = strip_tags($_REQUEST['cartLink']) : ($_REQUEST['cartLink'] = ''); isset($_REQUEST['thumbnail_url']) ? $_REQUEST['thumbnail_url'] = strip_tags($_REQUEST['thumbnail_url']) : ($_REQUEST['thumbnail_url'] = ''); isset($_REQUEST['tax']) ? $_REQUEST['tax'] = strip_tags($_REQUEST['tax']) : ($_REQUEST['tax'] = ''); if (isset($_REQUEST['digital_flag'])) { $_REQUEST['digital_flag'] = strip_tags($_REQUEST['digital_flag']); } else { $_REQUEST['digital_flag'] = ''; } $gateway = strip_tags($_REQUEST['eStore_gsbn_gateway']); $products = array(); $eStore_gs_buy_now_checkout_error = false; $count = 1; if ($count == 1) { $item_addittion_permitted = true; $quantity_available = is_quantity_availabe($_REQUEST['item_number'], $_REQUEST['add_qty']); if (!$quantity_available) { //Requested qty not available $_REQUEST['add_qty'] = 1; //Add one by default $eStore_gs_buy_now_checkout_error = true; } if (isset($_SESSION['eStore_last_action_msg'])) { $_SESSION['eStore_gs_bn_co_error_msg'] = $_SESSION['eStore_last_action_msg']; } if ($item_addittion_permitted) { if (!empty($_REQUEST[$_REQUEST['product']])) { $price = $_REQUEST[$_REQUEST['product']]; } else { if (isset($_REQUEST['custom_price'])) { global $wpdb; $products_table_name = WP_ESTORE_PRODUCTS_TABLE_NAME; $id = $_REQUEST['item_number']; $retrieved_product = $wpdb->get_row("SELECT * FROM {$products_table_name} WHERE id = '{$id}'", OBJECT); if ($_REQUEST['custom_price'] < $retrieved_product->price) { $price = $retrieved_product->price; $currSymbol = get_option('cart_currency_symbol'); $eStore_gs_buy_now_checkout_error = true; $_SESSION['eStore_gs_bn_co_error_msg'] = '<p style="color: red;">' . WP_ESTORE_MINIMUM_PRICE_YOU_CAN_ENTER . $currSymbol . $retrieved_product->price . '</p>'; } else { $price = $_REQUEST['custom_price']; } } else { $price = $_REQUEST['price']; } } $product = array('name' => stripslashes($_REQUEST['product']), 'price' => $price, 'quantity' => $_REQUEST['add_qty'], 'shipping' => $_REQUEST['shipping'], 'item_number' => $_REQUEST['item_number'], 'cartLink' => $_REQUEST['cartLink'], 'thumbnail_url' => $_REQUEST['thumbnail_url'], 'tax' => $_REQUEST['tax'], 'digital_flag' => $_REQUEST['digital_flag']); array_push($products, $product); } } if (!$eStore_gs_buy_now_checkout_error) { $_SESSION['eStore_cart'] = $products; $_SESSION['eStore_url'] = WP_ESTORE_URL; $_SESSION['eStore_cart_sub_total'] = eStore_get_cart_total(); $_SESSION['eStore_cart_postage_cost'] = eStore_get_cart_shipping(); $_SESSION['eStore_cart_total_tax'] = eStore_calculate_total_cart_tax(); wp_eStore_check_cookie_flag_and_store_values(); if (WP_ESTORE_ENABLE_NEW_CHECKOUT_REDIRECTION === '1') { $redirect_page = WP_ESTORE_WP_SITE_URL . '/?eStore_checkout=process&eStore_gateway=' . $gateway; } else { $redirect_page = WP_ESTORE_URL . '/eStore_payment_submission.php?eStore_gateway=' . $gateway; } eStore_redirect_to_url($redirect_page); } } }
function eStore_handle_item_addition_to_cart($prod_data_array) { $output = ""; $wp_eStore_config = WP_eStore_Config::getInstance(); //Need to drop cookie? unset($_SESSION['eStore_last_action_msg']); unset($_SESSION['eStore_last_action_msg_2']); unset($_SESSION['eStore_last_action_msg_3']); if (isset($_SESSION['eStore_cart'])) { //Load data from standard cart items $estore_cart = wp_eStore_load_eStore_cart_class(); } else { isset($_SESSION['eStore_cart_class']) ? $estore_cart = unserialize($_SESSION['eStore_cart_class']) : ($estore_cart = new WP_eStore_Cart()); } $product_id = $prod_data_array['item_number']; $add_qty = $prod_data_array['add_qty']; if ($add_qty < 1) { $add_qty = 1; $prod_data_array['add_qty'] = 1; } eStore_general_debug("Checking if item already exists in cart", true); $existing_item = $estore_cart->GetItemIfInCart($prod_data_array); if ($existing_item !== "-1") { //Found an item eStore_general_debug("This item already exists in the cart. Updating item ...", true); if ($wp_eStore_config->getValue('eStore_do_not_show_qty_in_cart')) { $output = '<p class="eStore_error_message">' . ESTORE_ITEM_ALREADY_EXISTS . '</p>'; eStore_ajax_send_error_response($output); } $new_qty = $existing_item->quantity + $add_qty; if (!is_quantity_availabe($product_id, $new_qty)) { //Check if the requested qty is available eStore_general_debug("Requested quantity is not available! Product ID: " . $product_id . " Requested qty: " . $new_qty, false); if (isset($_SESSION['eStore_last_action_msg'])) { $output = $_SESSION['eStore_last_action_msg']; } if (isset($_SESSION['eStore_last_action_msg_2'])) { $output = $_SESSION['eStore_last_action_msg_2']; } eStore_ajax_send_error_response($output); } //Update the quantity of this item $estore_cart->UpdateItemQty($existing_item, $prod_data_array['add_qty']); } else { //New item eStore_general_debug("Adding a brand new item to the cart", true); if (!is_quantity_availabe($product_id, $add_qty)) { //Check if the requested qty is available eStore_general_debug("Requested quantity is not available! Product ID: " . $product_id . " Requested qty: " . $add_qty, false); if (isset($_SESSION['eStore_last_action_msg'])) { $output = $_SESSION['eStore_last_action_msg']; } if (isset($_SESSION['eStore_last_action_msg_2'])) { $output = $_SESSION['eStore_last_action_msg_2']; } eStore_ajax_send_error_response($output); } if (isset($prod_data_array['custom_price'])) { //Check if it is a custom price amount if ($prod_data_array['custom_price'] < $prod_data_array['price']) { eStore_general_debug("Custom price value is less than the minimum amount!", false); $output = '<p class="eStore_error_message">' . WP_ESTORE_MINIMUM_PRICE_YOU_CAN_ENTER . WP_ESTORE_CURRENCY_SYMBOL . $prod_data_array['price'] . '</p>'; eStore_ajax_send_error_response($output); } $prod_data_array['price'] = $prod_data_array['custom_price']; } //Add the item $estore_cart->AddNewItemFromDataArray($prod_data_array); } $_SESSION['eStore_cart_class'] = serialize($estore_cart); //$db_data_cart = $estore_cart->print_eStore_cart_details(); //eStore_general_debug("Cart details: ".$db_data_cart,true); //Load to the legacy cart session wp_eStore_load_cart_class_to_session($estore_cart); $output = eStore_shopping_cart_multiple_gateway(); return $output; }
function eStore_cart_actions_handlers() { if (isset($_POST['addcart_eStore'])) { $wp_eStore_config = WP_eStore_Config::getInstance(); //$cookie_domain = eStore_get_top_level_domain(); setcookie("cart_in_use", "true", time() + 21600, "/", COOKIE_DOMAIN); if (function_exists('wp_cache_serve_cache_file')) { //WP Super cache workaround setcookie("comment_author_", "eStore", time() + 21600, "/", COOKIE_DOMAIN); } unset($_SESSION['eStore_last_action_msg']); unset($_SESSION['eStore_last_action_msg_2']); unset($_SESSION['eStore_last_action_msg_3']); if (isset($_SESSION['discount_applied_once']) && $_SESSION['discount_applied_once'] == 1) { //Coupon was already applied eStore_load_price_from_backed_up_cart(); } $count = 1; isset($_SESSION['eStore_cart']) ? $products = $_SESSION['eStore_cart'] : ($products = ''); //$products = $_SESSION['eStore_cart']; //sanitize data $_POST['product'] = strip_tags($_POST['product']); //for PHP5.2 use filter_var($_POST['product'], FILTER_SANITIZE_STRING); $_POST['add_qty'] = strip_tags($_POST['add_qty']); $_POST['item_number'] = strip_tags($_POST['item_number']); if (isset($_POST['custom_price'])) { $_POST['custom_price'] = strip_tags($_POST['custom_price']); } if (isset($_POST['price'])) { $_POST['price'] = strip_tags($_POST['price']); } isset($_POST['shipping']) ? $_POST['shipping'] = strip_tags($_POST['shipping']) : ($_POST['shipping'] = ''); isset($_POST['cartLink']) ? $_POST['cartLink'] = strip_tags($_POST['cartLink']) : ($_POST['cartLink'] = ''); isset($_POST['thumbnail_url']) ? $_POST['thumbnail_url'] = strip_tags($_POST['thumbnail_url']) : ($_POST['thumbnail_url'] = ''); isset($_POST['tax']) ? $_POST['tax'] = strip_tags($_POST['tax']) : ($_POST['tax'] = ''); if (isset($_POST['digital_flag'])) { $_POST['digital_flag'] = strip_tags($_POST['digital_flag']); } else { $_POST['digital_flag'] = ''; } if ($_POST['add_qty'] < 1) { $_POST['add_qty'] = 1; } if (is_array($products)) { foreach ($products as $key => $item) { if ($item['name'] == stripslashes($_POST['product'])) { if ($wp_eStore_config->getValue('eStore_do_not_show_qty_in_cart')) { $_SESSION['eStore_last_action_msg'] = '<p class="eStore_error_message">' . ESTORE_ITEM_ALREADY_EXISTS . '</p>'; $_SESSION['action_msg_set_time'] = time(); $count = 2; continue; } $req_qty = $item['quantity'] + $_POST['add_qty']; $update_quantity = is_quantity_availabe($item['item_number'], $req_qty, $item['name']); $count += $item['quantity']; if ($update_quantity) { $item['quantity'] = $item['quantity'] + $_POST['add_qty']; unset($products[$key]); array_push($products, $item); } } } } else { $products = array(); } if ($count == 1) { $item_addittion_permitted = true; $prod_name = stripslashes($_POST['product']); $quantity_available = is_quantity_availabe($_POST['item_number'], $_POST['add_qty'], $prod_name); if (!$quantity_available) { //Requested qty not available if (is_numeric(WP_ESTORE_CART_CHECKOUT_ITEM_LIMIT) && WP_ESTORE_CART_CHECKOUT_ITEM_LIMIT > 0) { //cart checkout limit apply so cannot add this item $item_addittion_permitted = false; } $_POST['add_qty'] = 1; //Add one by default } if ($item_addittion_permitted) { if (!empty($_POST[$_POST['product']])) { $price = $_POST[$_POST['product']]; } else { if (isset($_POST['custom_price'])) { global $wpdb; $products_table_name = WP_ESTORE_PRODUCTS_TABLE_NAME; $id = $_POST['item_number']; $retrieved_product = $wpdb->get_row("SELECT * FROM {$products_table_name} WHERE id = '{$id}'", OBJECT); if ($_POST['custom_price'] < $retrieved_product->price) { $price = $retrieved_product->price; $currSymbol = get_option('cart_currency_symbol'); $_SESSION['eStore_last_action_msg'] = '<p style="color: red;">' . WP_ESTORE_MINIMUM_PRICE_YOU_CAN_ENTER . $currSymbol . $retrieved_product->price . '</p>'; } else { $price = $_POST['custom_price']; } } else { $price = $_POST['price']; } } $product = array('name' => stripslashes($_POST['product']), 'price' => $price, 'quantity' => $_POST['add_qty'], 'shipping' => $_POST['shipping'], 'item_number' => $_POST['item_number'], 'cartLink' => $_POST['cartLink'], 'thumbnail_url' => $_POST['thumbnail_url'], 'tax' => $_POST['tax'], 'digital_flag' => $_POST['digital_flag']); array_push($products, $product); $_SESSION['eStore_last_item_add_url'] = $_POST['cartLink']; //$_SESSION['eStore_last_action_msg'] = '<p style="color: green;">'.ESTORE_ITEM_ADDED.'</p>'; } } sort($products); $_SESSION['eStore_cart'] = $products; $_SESSION['eStore_url'] = WP_ESTORE_URL; $last_added_item_id = $_POST['item_number']; if (isset($_SESSION['discount_applied_once']) && $_SESSION['discount_applied_once'] == 1) { //Handle discount if already applied to the cart if (isset($_SESSION['auto_discount_applied_once']) && $_SESSION['auto_discount_applied_once'] == 1) { //The auto discount will be taken care of later when the cart loads (it will recalculate) } else { unset($_SESSION['discount_applied_once']); eStore_apply_discount($_SESSION['eStore_coupon_code']); } } do_action('eStore_action_item_added_to_cart', $last_added_item_id); do_action('eStore_action_cart_data_updated'); wp_eStore_check_cookie_flag_and_store_values(); if (get_option('eStore_auto_checkout_redirection')) { $checkout_page_settings_value = get_option('eStore_checkout_page_url'); if (empty($checkout_page_settings_value)) { echo '<div class="eStore_error_message">Error in your eStore configuration! You must specify a value in the "Checkout Page" field in the settings menu if you want to use the "Automatic redirection to checkout page" option.</div>'; exit; } $checkout_url = eStore_get_checkout_url(); $redirection_parameter = 'Location: ' . $checkout_url; header($redirection_parameter); exit; } eStore_redirect_if_using_anchor(); } else { if (isset($_POST['eStore_cquantity'])) { unset($_SESSION['eStore_last_action_msg']); unset($_SESSION['eStore_last_action_msg_2']); unset($_SESSION['eStore_last_action_msg_3']); if (isset($_SESSION['discount_applied_once']) && $_SESSION['discount_applied_once'] == 1) { //reset_eStore_cart(); eStore_load_price_from_backed_up_cart(); } $products = $_SESSION['eStore_cart']; //sanitize data $_POST['product'] = strip_tags($_POST['product']); $_POST['quantity'] = strip_tags($_POST['quantity']); foreach ($products as $key => $item) { if ($item['name'] == stripslashes($_POST['product']) && $_POST['quantity']) { $update_quantity = is_quantity_availabe($item['item_number'], $_POST['quantity'], $item['name']); if ($update_quantity) { $item['quantity'] = $_POST['quantity']; unset($products[$key]); array_push($products, $item); } } else { if ($item['name'] == stripslashes($_POST['product']) && !$_POST['quantity']) { unset($products[$key]); } } } sort($products); $_SESSION['eStore_cart'] = $products; if (isset($_SESSION['discount_applied_once']) && $_SESSION['discount_applied_once'] == 1) { if (isset($_SESSION['auto_discount_applied_once']) && $_SESSION['auto_discount_applied_once'] == 1) { //The auto discount will be taken care of later when the cart loads (it will recalculate) } else { unset($_SESSION['discount_applied_once']); eStore_apply_discount($_SESSION['eStore_coupon_code']); } } do_action('eStore_action_item_qty_changed_in_cart'); do_action('eStore_action_cart_data_updated'); wp_eStore_check_cookie_flag_and_store_values(); eStore_redirect_if_using_anchor(); } else { if (isset($_POST['eStore_delcart'])) { unset($_SESSION['eStore_last_action_msg']); unset($_SESSION['eStore_last_action_msg_2']); unset($_SESSION['eStore_last_action_msg_3']); if (isset($_SESSION['discount_applied_once']) && $_SESSION['discount_applied_once'] == 1) { //reset_eStore_cart(); eStore_load_price_from_backed_up_cart(); } $products = $_SESSION['eStore_cart']; //sanitize data $_POST['product'] = strip_tags($_POST['product']); foreach ($products as $key => $item) { if ($item['name'] == stripslashes($_POST['product'])) { unset($products[$key]); } } $_SESSION['eStore_cart'] = $products; if (isset($_SESSION['discount_applied_once']) && $_SESSION['discount_applied_once'] == 1) { if (isset($_SESSION['auto_discount_applied_once']) && $_SESSION['auto_discount_applied_once'] == 1) { //The auto discount will be taken care of later when the cart loads } else { unset($_SESSION['discount_applied_once']); eStore_apply_discount($_SESSION['eStore_coupon_code']); } } do_action('eStore_action_item_removed_from_cart'); do_action('eStore_action_cart_data_updated'); wp_eStore_check_cookie_flag_and_store_values(); eStore_redirect_if_using_anchor(); } } } }