/** * update quantity function, used through ajax and in normal page loading. * No parameters, returns nothing */ function wpsc_update_item_quantity() { global $wpdb, $wpsc_cart, $wpsc_theme_path; if (is_numeric($_POST['key'])) { $key = (int) $_POST['key']; if ($_POST['quantity'] > 0) { // if the quantity is greater than 0, update the item; $parameters['quantity'] = (int) $_POST['quantity']; $wpsc_cart->edit_item($key, $parameters); } else { // if the quantity is 0, remove the item. $wpsc_cart->remove_item($key); } wpsc_coupon_price($_SESSION['coupon_numbers']); } if ($_REQUEST['ajax'] == 'true') { ob_start(); $cur_wpsc_theme_folder = apply_filters('wpsc_theme_folder', $wpsc_theme_path . WPSC_THEME_DIR); include_once $cur_wpsc_theme_folder . "/cart_widget.php"; $output = ob_get_contents(); ob_end_clean(); $output = str_replace(array("\n", "\r"), array("\\n", "\\r"), addslashes($output)); echo "jQuery('div.shopping-cart-wrapper').html('{$output}');\n"; do_action('wpsc_alternate_cart_html'); exit; } }
/** * update quantity function, used through ajax and in normal page loading. * No parameters, returns nothing */ function wpsc_update_item_quantity() { global $wpsc_cart; if (is_numeric($_POST['key'])) { $key = (int) $_POST['key']; if ($_POST['quantity'] > 0) { // if the quantity is greater than 0, update the item; $parameters['quantity'] = (int) $_POST['quantity']; $wpsc_cart->edit_item($key, $parameters); } else { // if the quantity is 0, remove the item. $wpsc_cart->remove_item($key); } $coupon = wpsc_get_customer_meta('coupon'); if ($coupon) { wpsc_coupon_price($coupon); } } if (isset($_REQUEST['ajax']) && $_REQUEST['ajax'] == 'true') { ob_start(); include_once wpsc_get_template_file_path('wpsc-cart_widget.php'); $output = ob_get_contents(); ob_end_clean(); $output = str_replace(array("\n", "\r"), array("\\n", "\\r"), addslashes($output)); echo "jQuery('div.shopping-cart-wrapper').html('{$output}');\n"; do_action('wpsc_alternate_cart_html'); exit; } }
/** * update quantity function, used through ajax and in normal page loading. * No parameters, returns nothing */ function wpsc_update_item_quantity() { global $wpsc_cart; if (is_numeric($_POST['key'])) { $key = (int) $_POST['key']; $quantity = isset($_POST['wpsc_quantity_update']) ? $_POST['wpsc_quantity_update'] : ''; if (isset($_POST['quantity'])) { $quantity = $_POST['quantity']; } if ($quantity > 0) { // if the quantity is greater than 0, update the item; $parameters['quantity'] = (int) $quantity; $wpsc_cart->edit_item($key, $parameters); } else { // if the quantity is 0, remove the item. $wpsc_cart->remove_item($key); } $coupon = wpsc_get_customer_meta('coupon'); if ($coupon) { wpsc_coupon_price($coupon); } } $die = !(isset($_REQUEST['wpsc_ajax_action']) && 'true' == $_REQUEST['wpsc_ajax_action'] || (!defined('DOING_AJAX') || !DOING_AJAX)); _wpsc_ajax_get_cart($die); }
/** * Refreshes discount for coupons when a new product is added to the cart. * * This is a fairly generally expected workflow, though there are some instances wherein * one might prefer to force the customer to "Update". In those instances, this can be unhooked. * * @since 3.8.14 * @return void */ function wpsc_cart_item_refresh_coupon() { $coupon = wpsc_get_customer_meta('coupon'); if (!empty($coupon)) { wpsc_coupon_price($coupon); } }
public function _callback_apply_coupon() { global $wpsc_coupons; wpsc_coupon_price($_POST['coupon_code']); $coupon = wpsc_get_customer_meta('coupon'); if (!empty($coupon)) { $wpsc_coupons = new wpsc_coupons($coupon); } if ($wpsc_coupons->errormsg || empty($_POST['coupon_code'])) { $this->message_collection->add(__('Coupon not applied.', 'wpsc'), 'error', 'main', 'flash'); } else { $this->message_collection->add(__('Coupon applied.', 'wpsc'), 'success', 'main', 'flash'); } wp_safe_redirect(wp_get_referer()); die; }