function eStore_cart_display_items_part($currency_symbol, $decimal, $fancy = '') { $wp_eStore_config = WP_eStore_Config::getInstance(); if (get_option('eStore_use_auto_discount')) { $total = eStore_get_cart_total(); $total_items = eStore_get_total_cart_item_qty(); // Auto discount for normal purchase $amt_threshold = get_option('eStore_amount_threshold_auto_coupon'); if (!empty($amt_threshold) && $total > $amt_threshold) { if (isset($_SESSION['discount_applied_once']) && $_SESSION['discount_applied_once'] == 1) { eStore_load_price_from_backed_up_cart(); unset($_SESSION['discount_applied_once']); } $coupon = get_option('eStore_amount_threshold_auto_coupon_code'); eStore_apply_discount($coupon); $_SESSION['auto_discount_applied_once'] = 1; } $qty_threshold = get_option('eStore_qty_threshold_auto_coupon'); if (!empty($qty_threshold) && $total_items > $qty_threshold) { if (isset($_SESSION['discount_applied_once']) && $_SESSION['discount_applied_once'] == 1) { eStore_load_price_from_backed_up_cart(); unset($_SESSION['discount_applied_once']); } $coupon = get_option('eStore_qty_threshold_auto_coupon_code'); eStore_apply_discount($coupon); $_SESSION['auto_discount_applied_once'] = 1; } } $output = ""; $total_items = 0; $total = 0; $item_total_shipping = 0; if ($_SESSION['eStore_cart'] && is_array($_SESSION['eStore_cart'])) { $output .= '<tr> <th class="eStore_cart_item_name">' . ESTORE_ITEM_NAME . '</th>'; if ($wp_eStore_config->getValue('eStore_do_not_show_qty_in_cart')) { $output .= '<th></th>'; } else { $output .= '<th class="eStore_cart_item_qty">' . ESTORE_QUANTITY . '</th>'; } $output .= '<th class="eStore_cart_item_price">' . ESTORE_PRICE . '</th><th></th> </tr>'; foreach ($_SESSION['eStore_cart'] as $item) { //Draw the line item if (!empty($fancy)) { if ($fancy == "2") { $output .= eStore_cart_display_line_item_fancy2($item, $currency_symbol, $decimal); } } else { $output .= eStore_cart_display_line_item($item, $currency_symbol, $decimal); } //End drawing line item $total += $item['price'] * $item['quantity']; $item_total_shipping += $item['shipping'] * $item['quantity']; $total_items += $item['quantity']; } $_SESSION['eStore_cart_sub_total'] = $total; //Check the shipping variation price if (!isset($_SESSION['eStore_selected_shipping_option_cost'])) { $_SESSION['eStore_selected_shipping_option_cost'] = 0; } if (isset($_POST['eStore_shipping_variation'])) { $_POST['eStore_shipping_variation'] = strip_tags($_POST['eStore_shipping_variation']); $pieces = explode('|', $_POST['eStore_shipping_variation']); $_SESSION['eStore_selected_shipping_option'] = $pieces[0]; if (!empty($pieces[1])) { $_SESSION['eStore_selected_shipping_option_cost'] = $pieces[1]; } else { $_SESSION['eStore_selected_shipping_option_cost'] = 0; } } // Base shipping can only be used in conjunction with individual item shipping if ($item_total_shipping != 0) { $baseShipping = get_option('eStore_base_shipping'); $postage_cost = $item_total_shipping + $baseShipping; $_SESSION['eStore_cart_postage_cost'] = $postage_cost + $_SESSION['eStore_selected_shipping_option_cost']; } else { $postage_cost = 0; $_SESSION['eStore_cart_postage_cost'] = $postage_cost + $_SESSION['eStore_selected_shipping_option_cost']; } if (get_option('eStore_use_auto_discount')) { // Auto shipping discount $amt_threshold_free_shipping = get_option('eStore_amount_free_shipping_threshold'); if (!empty($amt_threshold_free_shipping) && $total > $amt_threshold_free_shipping) { $postage_cost = 0; $_SESSION['eStore_cart_postage_cost'] = $postage_cost; $_SESSION['eStore_last_action_msg_3'] = '<p style="color: green;">' . ESTORE_TOTAL_DISCOUNT . ESTORE_DISCOUNT_FREE_SHIPPING; } $qty_threshold_free_shipping = get_option('eStore_qty_free_shipping_threshold'); if (!empty($qty_threshold_free_shipping) && $total_items > $qty_threshold_free_shipping) { $postage_cost = 0; $_SESSION['eStore_cart_postage_cost'] = $postage_cost; $_SESSION['eStore_last_action_msg_3'] = '<p style="color: green;">' . ESTORE_TOTAL_DISCOUNT . ESTORE_DISCOUNT_FREE_SHIPPING; } } } $below_item_details_section = ""; $below_item_details_section = apply_filters('eStore_below_item_details_filter', $below_item_details_section); if (!empty($below_item_details_section)) { $output .= '<div class="eStore_below_item_details">' . $below_item_details_section . '</div>'; } do_action('eStore_action_after_cart_items_details'); 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(); } } } }