Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Hotfix for Buy Now functionality #396

Closed
wants to merge 2 commits into from

2 participants

@1bigidea

There are two errors related to wrapping conditions with DOING_AJAX that 1) cause a fatal error (since no value is returned if we aren't DOING_AJAX) and 2) wpsc_empty_cart shouldn't die if we aren't DOING_AJAX

1bigidea added some commits
@1bigidea 1bigidea Operand error on line 112 of wpsc-includes/ajax-functions.php when us…
…ing Buy Now

_wpsc_ajax_get_cart returns NULL when called via BUY NOW (since this is
NOT an ajax call)
43c5357
@1bigidea 1bigidea empty_cart function should only die for AJAX functions
Wrap json return in DOING_AJAX
6f8f19d
@JustinSainton JustinSainton commented on the diff
wpsc-includes/ajax.functions.php
@@ -136,8 +136,10 @@ function wpsc_empty_cart() {
global $wpsc_cart;
$wpsc_cart->empty_cart( false );
- $output = _wpsc_ajax_get_cart( false );
- die( json_encode( $output ) );
+ if( defined('DOING_AJAX') && DOING_AJAX ){
+ $output = _wpsc_ajax_get_cart( false );
+ die( json_encode( $output ) );
+ }
@JustinSainton Owner

This was resolved in 8087d74

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@1bigidea

I was testing my Buy Now with Variations pull against the master I pulled earlier today. It wasn't working so I dug in to figure out why. Appears we were working parallel. I am closing this as a dupe.

@1bigidea 1bigidea closed this
@JustinSainton

Not entirely duplicate, actually - as the commit I referred to did not place the $return array outside of the AJAX condition.

@JustinSainton JustinSainton reopened this
@1bigidea

We have to return an empty array. Otherwise it returns a NULL which then causes a fatal.

@JustinSainton

Right, I'm agreeing with you :)

@JustinSainton

This bit committed and fixed in 47178bd. Still have some work to do elsewhere (See #395) Thanks Tom!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 6, 2013
  1. @1bigidea

    Operand error on line 112 of wpsc-includes/ajax-functions.php when us…

    1bigidea authored
    …ing Buy Now
    
    _wpsc_ajax_get_cart returns NULL when called via BUY NOW (since this is
    NOT an ajax call)
  2. @1bigidea

    empty_cart function should only die for AJAX functions

    1bigidea authored
    Wrap json return in DOING_AJAX
This page is out of date. Refresh to see the latest.
View
20 wpsc-includes/ajax.functions.php
@@ -136,8 +136,10 @@ function wpsc_empty_cart() {
global $wpsc_cart;
$wpsc_cart->empty_cart( false );
- $output = _wpsc_ajax_get_cart( false );
- die( json_encode( $output ) );
+ if( defined('DOING_AJAX') && DOING_AJAX ){
+ $output = _wpsc_ajax_get_cart( false );
+ die( json_encode( $output ) );
+ }
@JustinSainton Owner

This was resolved in 8087d74

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
}
add_action( 'wp_ajax_empty_cart' , 'wpsc_empty_cart' );
@@ -221,9 +223,10 @@ function wpsc_update_item_quantity() {
* @return mixed Returns an array of output data, alternatively
*/
function _wpsc_ajax_get_cart( $die = true, $cart_messages = array() ) {
- if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
- $return = array();
+ $return = array();
+
+ if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
ob_start();
include_once( wpsc_get_template_file_path( 'wpsc-cart_widget.php' ) );
@@ -258,11 +261,12 @@ function _wpsc_ajax_get_cart( $die = true, $cart_messages = array() ) {
$return['action_output'] = $action_output;
}
- if ( $die )
- die( $output . $action_output );
- else
- return $return;
}
+
+ if ( $die )
+ die( $output . $action_output );
+ else
+ return $return;
}
// execute on POST and GET
View
2  wpsc-merchants/paypal-standard.merchant.php
@@ -865,7 +865,7 @@ function form_paypal_multiple() {
}
function _wpsc_buy_now_callback() {
- global $wpsc_cart, $user_ID;
+ global $wpsc_cart, $user_ID, $paypal_url;
$paypal_url = get_option( 'paypal_multiple_url' );
$_POST['custom_gateway'] = 'wpsc_merchant_paypal_standard';
Something went wrong with that request. Please try again.