function eStore_show_compact_cart() { if ($_SESSION['eStore_cart'] && is_array($_SESSION['eStore_cart'])) { //$num_items = count($_SESSION['eStore_cart']);//to unique item count $num_items = eStore_get_total_cart_item_qty(); // to show the total quantity count } if ($num_items > 0) { if ($num_items == 1) { $output .= $num_items . ESTORE_ITEM_IN_THE_CART; } else { $output .= $num_items . ESTORE_ITEMS_IN_THE_CART; } $output .= "<br /><a href=" . eStore_get_checkout_url() . ">" . ESTORE_VIEW_CART . "</a><br />"; } else { $output = eStore_empty_cart_display(); } 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(); } } } }