wp-e-commerce / WP-e-Commerce

WP eCommerce - The most popular independent eCommerce platform for WordPress
https://wpecommerce.org
GNU General Public License v2.0
215 stars 217 forks source link

Activating WPEC via WP CLI error - Call to undefined function wpsc_get_current_customer_id #2302

Open ablears opened 7 years ago

ablears commented 7 years ago

I see the following when I activate WPEC 3.12.0 via WP CLI:

wp plugin activate wp-e-commerce --url=https://mysite.com
Plugin 'wp-e-commerce' activated.
Success: Activated 1 of 1 plugins.
PHP Fatal error:  Uncaught Error: Call to undefined function wpsc_get_current_customer_id() in /var/www/mu/mysite/wp-content/plugins/wp-e-commerce/wpsc-core/wpsc-functions.php:649
Stack trace:
#0 /var/www/mu/mysite/wp-includes/class-wp-hook.php(298): wpsc_serialize_shopping_cart('')
#1 /var/www/mu/mysite/wp-includes/class-wp-hook.php(323): WP_Hook->apply_filters(NULL, Array)
#2 /var/www/mu/mysite/wp-includes/plugin.php(453): WP_Hook->do_action(Array)
#3 /var/www/mu/mysite/wp-includes/load.php(677): do_action('shutdown')
#4 [internal function]: shutdown_action_hook()
#5 {main}
  thrown in /var/www/mu/mysite/wp-content/plugins/wp-e-commerce/wpsc-core/wpsc-functions.php on line 649
Fatal error: Uncaught Error: Call to undefined function wpsc_get_current_customer_id() in /var/www/mu/mysite/wp-content/plugins/wp-e-commerce/wpsc-core/wpsc-functions.php:649
Stack trace:
#0 /var/www/mu/mysite/wp-includes/class-wp-hook.php(298): wpsc_serialize_shopping_cart('')
#1 /var/www/mu/mysite/wp-includes/class-wp-hook.php(323): WP_Hook->apply_filters(NULL, Array)
#2 /var/www/mu/mysite/wp-includes/plugin.php(453): WP_Hook->do_action(Array)
#3 /var/www/mu/mysite/wp-includes/load.php(677): do_action('shutdown')
#4 [internal function]: shutdown_action_hook()
#5 {main}
  thrown in /var/www/mu/mysite/wp-content/plugins/wp-e-commerce/wpsc-core/wpsc-functions.php on line 649
DrewAPicture commented 7 years ago

Just hit this too. Probably could get away with keeping it by just wrapping it in a function_exists() call:

function wpsc_serialize_shopping_cart() {
    global $wpsc_cart;

    if ( is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) )
        return;

    if ( is_object( $wpsc_cart ) ) {
        $wpsc_cart->errors = array();
    }

    if ( function_exists( 'wpsc_get_current_customer_id' ) ) {
        // need to prevent set_cookie from being called at this stage in case the user just logged out
        // because by now, some output must have been printed out
        $customer_id = wpsc_get_current_customer_id();

        if ( $customer_id ) {
            wpsc_update_customer_cart( $wpsc_cart, $customer_id );
        }
    }

    return true;
}
JustinSainton commented 7 years ago

@DrewAPicture Would happily accept that PR 👍

DrewAPicture commented 7 years ago

PR: #2316