function wp_eStore_handle_save_cart_action($action) { //TODO - do an IP addresss check and potentially limit request based on that if needed. eStore_payment_debug('Processing save cart action...', true); if (!isset($_SESSION['eStore_cart']) || empty($_SESSION['eStore_cart'])) { eStore_payment_debug('Error! Shopping cart is empty... nothing to save!', false); echo json_encode(array('reply_action' => $action, 'status' => 'error', 'details' => ESTORE_CART_EMPTY)); exit; } $eStore_cart = wp_eStore_load_eStore_cart_class(); wp_eStore_write_debug_array($eStore_cart, true); $cart_id = $eStore_cart->GetCartId(); eStore_payment_debug('Saving cart to the database... Cart ID: ' . $cart_id, true); wp_eStore_save_cart_details_to_db($eStore_cart); eStore_payment_debug('Cart saved successfully!', true); echo json_encode(array('reply_action' => $action, 'status' => 'success', 'ID' => $cart_id)); exit; }
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; }