From a53b53ebe49e236af678030d9eecaaab0bc7dbdd Mon Sep 17 00:00:00 2001 From: Tom Ransom Date: Thu, 21 Mar 2013 15:30:33 -0700 Subject: [PATCH 1/6] Buy Now button with Variations wp-e-commerce.js when updating on change in selected variance, update the corresponding Buy Now button display.functions.php - include a hidden field in the Buy Now form to pass the variation value(s) to the Add_to_cart --- wpsc-core/js/wp-e-commerce.js | 6 +++++- wpsc-includes/display.functions.php | 30 +++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/wpsc-core/js/wp-e-commerce.js b/wpsc-core/js/wp-e-commerce.js index 14e0207c58..93db8d47c1 100755 --- a/wpsc-core/js/wp-e-commerce.js +++ b/wpsc-core/js/wp-e-commerce.js @@ -280,6 +280,7 @@ jQuery(document).ready(function ($) { // update the price when the variations are altered. jQuery(".wpsc_select_variation").live('change', function() { jQuery('option[value="0"]', this).attr('disabled', 'disabled'); + self = this; var parent_form = jQuery(this).closest("form.product_form"); if ( parent_form.length == 0 ) return; @@ -292,7 +293,7 @@ jQuery(document).ready(function ($) { donation_price = jQuery('input#donation_price_' + prod_id), old_price = jQuery('#old_product_price_' + prod_id), save = jQuery('#yousave_' + prod_id), - buynow = jQuery('#BB_BuyButtonForm' + prod_id); + buynow = jQuery('#buy-now-product_' + prod_id); if ( response.variation_found ) { if ( response.stock_available ) { stock_display.removeClass('out_of_stock').addClass('in_stock'); @@ -320,6 +321,9 @@ jQuery(document).ready(function ($) { } } donation_price.val(response.numeric_price); + + buynow.find('input[name="'+$(self).prop('name')+'"]').val($(self).val()); + buynow.find('input.wpsc-buy-now-button').prop('disabled', false); } }, 'json'); }); diff --git a/wpsc-includes/display.functions.php b/wpsc-includes/display.functions.php index e432096a15..b75b1f6fce 100755 --- a/wpsc-includes/display.functions.php +++ b/wpsc-includes/display.functions.php @@ -35,15 +35,33 @@ function wpsc_buy_now_button( $product_id, $replaced_shortcode = false ) { $handling = $shipping; } + $disabled = ''; + if( $has_variants = wpsc_product_has_variations($product_id) ) + $disabled = ' disabled="disabled" '; + $src = _x( 'https://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif', 'PayPal Buy Now Button', 'wpsc' ); $src = apply_filters( 'wpsc_buy_now_button_src', $src ); $classes = "wpsc-buy-now-form wpsc-buy-now-form-{$product_id}"; - $button_html = ''; + $button_html = sprintf('', + $disabled, + esc_attr( $product_id ), + esc_url( $src ), + esc_attr( 'PayPal - The safer, easier way to pay online', 'wpsc' ) + ); $button_html = apply_filters( 'wpsc_buy_now_button_html', $button_html, $product_id ); - ?> -
+?> + +', wpsc_vargrp_id(), wpsc_vargrp_form_id()); + endwhile; + endif; /* END wpsc_product_has_variations */ +?>
@@ -70,20 +88,20 @@ function wpsc_also_bought( $product_id ) { if ( get_option( 'wpsc_also_bought' ) == 0 ) { return ''; } - + // To be made customiseable in a future release $also_bought_limit = 3; $element_widths = 96; $image_display_height = 96; $image_display_width = 96; - + // Filter will be used by a plugin to provide 'Also Bought' functionality when this is deprecated from core. // Filter is currently private and should not be used by plugin/theme devs as it may only be temporary. $output = apply_filters( '_wpsc_also_bought', '', $product_id ); if ( ! empty( $output ) ) { return $output; } - + // If above filter returns output then the following is ignore and can be deprecated in future. $also_bought = $wpdb->get_results( $wpdb->prepare( "SELECT `" . $wpdb->posts . "`.* FROM `" . WPSC_TABLE_ALSO_BOUGHT . "`, `" . $wpdb->posts . "` WHERE `selected_product`= %d AND `" . WPSC_TABLE_ALSO_BOUGHT . "`.`associated_product` = `" . $wpdb->posts . "`.`id` AND `" . $wpdb->posts . "`.`post_status` IN('publish','protected') ORDER BY `" . WPSC_TABLE_ALSO_BOUGHT . "`.`quantity` DESC LIMIT $also_bought_limit", $product_id ), ARRAY_A ); if ( is_array( $also_bought ) && count( $also_bought ) > 0 ) { From 1b2ec5560d3985e0bf18d0612c887b3e451b9901 Mon Sep 17 00:00:00 2001 From: Tom Ransom Date: Thu, 21 Mar 2013 21:35:16 -0700 Subject: [PATCH 2/6] Escape the things We need to escape the "disabled" attribute. And apparently the Paypal string has never used the right i18n function --- wpsc-includes/display.functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wpsc-includes/display.functions.php b/wpsc-includes/display.functions.php index b75b1f6fce..7e536dee59 100755 --- a/wpsc-includes/display.functions.php +++ b/wpsc-includes/display.functions.php @@ -43,10 +43,10 @@ function wpsc_buy_now_button( $product_id, $replaced_shortcode = false ) { $src = apply_filters( 'wpsc_buy_now_button_src', $src ); $classes = "wpsc-buy-now-form wpsc-buy-now-form-{$product_id}"; $button_html = sprintf('', - $disabled, + esc_attr( $disabled ), esc_attr( $product_id ), esc_url( $src ), - esc_attr( 'PayPal - The safer, easier way to pay online', 'wpsc' ) + esc_attr__( 'PayPal - The safer, easier way to pay online', 'wpsc' ) ); $button_html = apply_filters( 'wpsc_buy_now_button_html', $button_html, $product_id ); ?> From eebb4116bf9b15255ffd15c6e5c2511f04ea7618 Mon Sep 17 00:00:00 2001 From: Tom Ransom Date: Thu, 21 Mar 2013 22:17:13 -0700 Subject: [PATCH 3/6] Use Disabled function, clean up code Cleaner code --- wpsc-includes/display.functions.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/wpsc-includes/display.functions.php b/wpsc-includes/display.functions.php index 7e536dee59..31188906f8 100755 --- a/wpsc-includes/display.functions.php +++ b/wpsc-includes/display.functions.php @@ -35,15 +35,11 @@ function wpsc_buy_now_button( $product_id, $replaced_shortcode = false ) { $handling = $shipping; } - $disabled = ''; - if( $has_variants = wpsc_product_has_variations($product_id) ) - $disabled = ' disabled="disabled" '; - $src = _x( 'https://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif', 'PayPal Buy Now Button', 'wpsc' ); $src = apply_filters( 'wpsc_buy_now_button_src', $src ); $classes = "wpsc-buy-now-form wpsc-buy-now-form-{$product_id}"; $button_html = sprintf('', - esc_attr( $disabled ), + disabled(wpsc_product_has_variations($product_id), true, false), esc_attr( $product_id ), esc_url( $src ), esc_attr__( 'PayPal - The safer, easier way to pay online', 'wpsc' ) @@ -54,7 +50,7 @@ function wpsc_buy_now_button( $product_id, $replaced_shortcode = false ) { Date: Fri, 22 Mar 2013 08:08:35 -0700 Subject: [PATCH 4/6] Change $ to jQuery for consistency Since all other jQuery selectors using the jQuery (rather than $ shortcut), the two references to self have modified --- wpsc-core/js/wp-e-commerce.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpsc-core/js/wp-e-commerce.js b/wpsc-core/js/wp-e-commerce.js index 93db8d47c1..449d592ad8 100755 --- a/wpsc-core/js/wp-e-commerce.js +++ b/wpsc-core/js/wp-e-commerce.js @@ -322,7 +322,7 @@ jQuery(document).ready(function ($) { } donation_price.val(response.numeric_price); - buynow.find('input[name="'+$(self).prop('name')+'"]').val($(self).val()); + buynow.find('input[name="'+jQuery(self).prop('name')+'"]').val(jQuery(self).val()); buynow.find('input.wpsc-buy-now-button').prop('disabled', false); } }, 'json'); From 61c0b2fd9f51f7939db04988110917497f42a7c1 Mon Sep 17 00:00:00 2001 From: Tom Ransom Date: Fri, 22 Mar 2013 16:34:29 -0700 Subject: [PATCH 5/6] Reduce the calls to wpsc_product_has_variations minor whitespace corrections --- wpsc-includes/display.functions.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/wpsc-includes/display.functions.php b/wpsc-includes/display.functions.php index 31188906f8..b7d68d4939 100755 --- a/wpsc-includes/display.functions.php +++ b/wpsc-includes/display.functions.php @@ -35,11 +35,12 @@ function wpsc_buy_now_button( $product_id, $replaced_shortcode = false ) { $handling = $shipping; } + $has_variants = wpsc_product_has_variations($product_id); $src = _x( 'https://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif', 'PayPal Buy Now Button', 'wpsc' ); $src = apply_filters( 'wpsc_buy_now_button_src', $src ); $classes = "wpsc-buy-now-form wpsc-buy-now-form-{$product_id}"; $button_html = sprintf('', - disabled(wpsc_product_has_variations($product_id), true, false), + disabled( $has_variants, true, false ), esc_attr( $product_id ), esc_url( $src ), esc_attr__( 'PayPal - The safer, easier way to pay online', 'wpsc' ) @@ -50,7 +51,7 @@ function wpsc_buy_now_button( $product_id, $replaced_shortcode = false ) { Date: Fri, 22 Mar 2013 16:47:46 -0700 Subject: [PATCH 6/6] Include disabled() in the input string directly rather than via sprintf --- wpsc-includes/display.functions.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/wpsc-includes/display.functions.php b/wpsc-includes/display.functions.php index b7d68d4939..b62a144337 100755 --- a/wpsc-includes/display.functions.php +++ b/wpsc-includes/display.functions.php @@ -39,8 +39,7 @@ function wpsc_buy_now_button( $product_id, $replaced_shortcode = false ) { $src = _x( 'https://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif', 'PayPal Buy Now Button', 'wpsc' ); $src = apply_filters( 'wpsc_buy_now_button_src', $src ); $classes = "wpsc-buy-now-form wpsc-buy-now-form-{$product_id}"; - $button_html = sprintf('', - disabled( $has_variants, true, false ), + $button_html = sprintf('', esc_attr( $product_id ), esc_url( $src ), esc_attr__( 'PayPal - The safer, easier way to pay online', 'wpsc' )