function wp_eStore_handle_retrieve_cart_action($action)
{
    eStore_payment_debug('Processing retrieve cart action...', true);
    $cart_id = strip_tags($_REQUEST['cart_id']);
    if (empty($cart_id)) {
        eStore_payment_debug('Error! Cart ID is empty! Cannot process this request', false);
        echo json_encode(array('reply_action' => $action, 'status' => 'error', 'code' => 'ESTORE_AJAX_01', 'details' => 'Cart ID is empty!'));
        exit;
    }
    eStore_payment_debug('Retrieving previously saved cart... Cart ID: ' . $cart_id, true);
    $eStore_cart = wp_eStore_get_cart_details_from_db($cart_id);
    if ($eStore_cart === "-1") {
        eStore_payment_debug('Error! Failed to retrieve cart for the given cart ID!', false);
        echo json_encode(array('reply_action' => $action, 'status' => 'error', 'code' => 'ESTORE_AJAX_02', 'details' => 'Failed to retrieve cart for the given cart ID!'));
        exit;
    }
    eStore_payment_debug('Loading cart into session...', true);
    wp_eStore_load_cart_class_to_session($eStore_cart);
    wp_eStore_write_debug_array($_SESSION['eStore_cart'], true);
    echo json_encode(array('reply_action' => $action, 'status' => 'success', 'ID' => $cart_id));
    exit;
}
Example #2
0
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;
}