jamesgol / woocommerce-cart-stock-reducer

Allow WooCommerce inventory stock to be reduced when adding items to cart
GNU General Public License v2.0
58 stars 19 forks source link

Error when I try to buy all remaining products (with Paypal Express) #93

Closed marcelbusch closed 2 years ago

marcelbusch commented 2 years ago

Hey, I'm using your plugin to reduce some items in an onlineshop I'm setting up at the moment. Now I'm facing a problem when checking out via Paypal (I'm using WebToffees Paypal Express Plugin): when I put all available items of one product in my cart, I get an error during checkout, this doesn't happen when I want to buy all but one items of the product. I was able to trace the problem down to the ReserveStock.php which lies in plugins/woocommerce/src/Checkout/Helpers/. On line 86 it asks if $product->is_in_stock() which resolves to false, which should return true during checkout, shouldn't it? I set up bank transfer as an alternative payment and here the error doesn't happen. Any advise?

Error trace (reduced): ` 2021-12-02T18:40:33+00:00 DEBUG <------------------- WebToffee PayPal Express Payment ( catch Exception on Express Start/Credit Start ) -------------------> stdClass Object ( [0] => Exception Object ( [message:protected] => „Googly Eye“ is sold out and can't be purchased. [string:Exception:private] => [code:protected] => 0 [file:protected] => /var/www/virtual/fummel/html/wp-content/plugins/express-checkout-paypal-payment-gateway-for-woocommerce/includes/class-paypal-express-api.php [line:protected] => 510 [trace:Exception:private] => Array ( [0] => Array ( [file] => /var/www/virtual/fummel/html/wp-includes/class-wp-hook.php [line] => 303 [function] => perform_api_request_paypal [class] => Eh_PayPal_Express_Payment [type] => -> [args] => Array ( [0] => )

                     )

                [1] => Array
                    (
                        [file] => /var/www/virtual/fummel/html/wp-includes/class-wp-hook.php
                        [line] => 327
                        [function] => apply_filters
                        [class] => WP_Hook
                        [type] => ->
                        [args] => Array
                            (
                                [0] => 
                                [1] => Array
                                    (
                                        [0] => 
                                    )

                            )

                    )

                [2] => Array
                    (
                        [file] => /var/www/virtual/fummel/html/wp-includes/plugin.php
                        [line] => 470
                        [function] => do_action
                        [class] => WP_Hook
                        [type] => ->
                        [args] => Array
                            (
                                [0] => Array
                                    (
                                        [0] => 
                                    )

                            )

                    )

                [3] => Array
                    (
                        [file] => /var/www/virtual/fummel/html/wp-content/plugins/woocommerce/includes/class-wc-api.php
                        [line] => 161
                        [function] => do_action
                        [args] => Array
                            (
                                [0] => woocommerce_api_eh_paypal_express_payment
                            )

                    )

                [4] => Array
                    (
                        [file] => /var/www/virtual/fummel/html/wp-includes/class-wp-hook.php
                        [line] => 303
                        [function] => handle_api_requests
                        [class] => WC_API
                        [type] => ->
                        [args] => Array
                            (
                                [0] => WP Object
                                    (
                                        [public_query_vars] => Array
                                            (
                                                //removed
                                            )

                                        [private_query_vars] => Array
                                            (
                                                //removed
                                            )

                                        [extra_query_vars] => Array
                                            (
                                            )

                                        [query_vars] => Array
                                            (
                                                [p] => https://fummelei.com/kasse/
                                                [wc-api] => Eh_PayPal_Express_Payment
                                            )

                                        [query_string] => 
                                        [request] => wc-api/Eh_PayPal_Express_Payment
                                        [matched_rule] => wc-api(/(.*))?/?$
                                        [matched_query] => &wc-api=Eh_PayPal_Express_Payment
                                        [did_permalink] => 1
                                    )

                            )

                    )

                [5] => Array
                    (
                        [file] => /var/www/virtual/fummel/html/wp-includes/class-wp-hook.php
                        [line] => 327
                        [function] => apply_filters
                        [class] => WP_Hook
                        [type] => ->
                        [args] => Array
                            (
                                [0] => 
                                [1] => Array
                                    (
                                        [0] => WP Object
                                            (
                                                [public_query_vars] => Array
                                                    (
                                                        //removed
                                                    )

                                                [private_query_vars] => Array
                                                    (
                                                        //removed
                                                    )

                                                [extra_query_vars] => Array
                                                    (
                                                    )

                                                [query_vars] => Array
                                                    (
                                                        [p] => https://fummelei.com/kasse/
                                                        [wc-api] => Eh_PayPal_Express_Payment
                                                    )

                                                [query_string] => 
                                                [request] => wc-api/Eh_PayPal_Express_Payment
                                                [matched_rule] => wc-api(/(.*))?/?$
                                                [matched_query] => &wc-api=Eh_PayPal_Express_Payment
                                                [did_permalink] => 1
                                            )

                                    )

                            )

                    )

                [6] => Array
                    (
                        [file] => /var/www/virtual/fummel/html/wp-includes/plugin.php
                        [line] => 518
                        [function] => do_action
                        [class] => WP_Hook
                        [type] => ->
                        [args] => Array
                            (
                                [0] => Array
                                    (
                                        [0] => WP Object
                                            (
                                                [public_query_vars] => Array
                                                    (
                                                        //removed
                                                    )

                                                [private_query_vars] => Array
                                                    (
                                                        //removed
                                                    )

                                                [extra_query_vars] => Array
                                                    (
                                                    )

                                                [query_vars] => Array
                                                    (
                                                        [p] => https://fummelei.com/kasse/
                                                        [wc-api] => Eh_PayPal_Express_Payment
                                                    )

                                                [query_string] => 
                                                [request] => wc-api/Eh_PayPal_Express_Payment
                                                [matched_rule] => wc-api(/(.*))?/?$
                                                [matched_query] => &wc-api=Eh_PayPal_Express_Payment
                                                [did_permalink] => 1
                                            )

                                    )

                            )

                    )

                [7] => Array
                    (
                        [file] => /var/www/virtual/fummel/html/wp-includes/class-wp.php
                        [line] => 388
                        [function] => do_action_ref_array
                        [args] => Array
                            (
                                [0] => parse_request
                                [1] => Array
                                    (
                                        [0] => WP Object
                                            (
                                                [public_query_vars] => Array
                                                    (
                                                        //removed
                                                    )

                                                [private_query_vars] => Array
                                                    (
                                                        //removed
                                                    )

                                                [extra_query_vars] => Array
                                                    (
                                                    )

                                                [query_vars] => Array
                                                    (
                                                        [p] => https://fummelei.com/kasse/
                                                        [wc-api] => Eh_PayPal_Express_Payment
                                                    )

                                                [query_string] => 
                                                [request] => wc-api/Eh_PayPal_Express_Payment
                                                [matched_rule] => wc-api(/(.*))?/?$
                                                [matched_query] => &wc-api=Eh_PayPal_Express_Payment
                                                [did_permalink] => 1
                                            )

                                    )

                            )

                    )

                [8] => Array
                    (
                        [file] => /var/www/virtual/fummel/html/wp-includes/class-wp.php
                        [line] => 750
                        [function] => parse_request
                        [class] => WP
                        [type] => ->
                        [args] => Array
                            (
                                [0] => 
                            )

                    )

                [9] => Array
                    (
                        [file] => /var/www/virtual/fummel/html/wp-includes/functions.php
                        [line] => 1291
                        [function] => main
                        [class] => WP
                        [type] => ->
                        [args] => Array
                            (
                                [0] => 
                            )

                    )

                [10] => Array
                    (
                        [file] => /var/www/virtual/fummel/html/wp-blog-header.php
                        [line] => 16
                        [function] => wp
                        [args] => Array
                            (
                            )

                    )

                [11] => Array
                    (
                        [file] => /var/www/virtual/fummel/html/index.php
                        [line] => 30
                        [args] => Array
                            (
                                [0] => /var/www/virtual/fummel/html/wp-blog-header.php
                            )

                        [function] => require
                    )

            )

        [previous:Exception:private] => 
    )

) `

jamesgol commented 2 years ago

Can you send me a copy of that other plugin? I'm sure there's a function that needs to be whitelisted to get the actual stock instead of virtual

Is this happen when processing the IPN or on the checkout page?

marcelbusch commented 2 years ago

It's this one https://de.wordpress.org/plugins/express-checkout-paypal-payment-gateway-for-woocommerce/

I'm not sure if either, you can click on the paypal express button on whatever page you're on, then it builds a request and redirects to paypal, it happens during the building of the request (/express-checkout-paypal-payment-gateway-for-woocommerce/includes/class-paypal-express-api.php:509).

jamesgol commented 2 years ago

Are you using 'Express checkout' or 'Smart Button' payment button? Any other settings unique to that payment plugin that you have so I can try to duplicate the issue?

Edit: The exception text thrown doesn't seem to match with anything in WooCommerce, do you have another plugin (or a custom translation) that is throwing an exception with the text "is sold out and can't be purchased." The exception thrown in ReserveStock.php has text " is out of stock and cannot be purchased."

I have the plugin installed and setup enough for some testing though I haven't been able to reproduce the error yet. I'll keep trying but if you can share some more details about your setup it would help keep me from trying a lot of random stuff. What type of products are they?

marcelbusch commented 2 years ago

I'm using the Express checkout button, anything else I could image that might be relevant is just that the button is on the cart page (with no possibility to go to the checkout page). Oh, my store runs in german and I translated it when I posted the log here and apparently didn't get the wording right, sorry for the confusion. I'm sure that the exception is really coming from the ReserveStock.php. I don't really have any other woocommerce-related plugins installed, just a stock manager, but even when it's deactivated the problem persists. There's nothing special to the products, they're simple products, don't have any variations, stock managing is activated and they have a low single digit stock amount and don't allow backorders. I attached the settings I'm using for your plugin. I use an ajax-cart, but the error also occurs when I try to check out from the normal, non-ajax cart-page or from the checkout-page, so I don't think it has anything to do with that. Anything else that might be useful for you?

grafik grafik
jamesgol commented 2 years ago

Thanks for the info. Just wanted to make sure I wasn't chasing down a red herring. It looks like my test didn't trigger it because I don't have the 'woocommerce_hold_stock_minutes' option enabled. I'll do some more testing, but I suspect that function will need to be whitelisted to return actual stock.

jamesgol commented 2 years ago

I just pushed out version 3.85 to the WordPress repository. This should fix your issue.

I have not done much testing with the WooCommerce reserve stock feature, I've never seen a benefit to using that as well as this plugin at the same time. Please do further testing to see if you need it and it helps in any way.

marcelbusch commented 2 years ago

Honestly I wasn't aware I had that option turned enabled, but your update works:) thanks a lot!