Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed AddToCart duplication when other plugins clone cart #2631

Merged
merged 2 commits into from
Oct 4, 2023

Conversation

StyleT
Copy link
Contributor

@StyleT StyleT commented Sep 16, 2023

Changes proposed in this Pull Request:

Other plugins often clone Woocommerce cart to do various "on the fly" calculations and now this causes duplication of the AddToCart server events.

This fixes it once and forever ;)

fixes #2544

Screenshots:

How it looks before fix:
Screenshot 2023-09-16 at 2 19 38 PM

Detailed test instructions:

How to reproduce in tests

$cart = clone WC()->cart;
$cart->add_to_cart( $product_id, $qty, $variation_id, $variation )

Real-life test

Install this plugin and woo-stripe-payment as an example. Observe the following stack traces:

2023-09-16T17:51:06+00:00 DEBUG AddToCart: #0 /wp-includes/class-wp-hook.php(312): WC_Facebookcommerce_EventsTracker->inject_add_to_cart_event()
#1 /wp-includes/class-wp-hook.php(334): WP_Hook->apply_filters()
#2 /wp-includes/plugin.php(517): WP_Hook->do_action()
#3 /wp-content/plugins/woocommerce/includes/class-wc-cart.php(1279): do_action()
#4 /wp-content/plugins/woo-stripe-payment/includes/controllers/class-wc-stripe-controller-cart.php(275): WC_Cart->add_to_cart()
#5 /wp-includes/rest-api/class-wp-rest-server.php(1188): WC_Stripe_Controller_Cart->cart_calculation()
#6 /wp-includes/rest-api/class-wp-rest-server.php(1035): WP_REST_Server->respond_to_request()
#7 /wp-includes/rest-api/class-wp-rest-server.php(447): WP_REST_Server->dispatch()
#8 /wp-includes/rest-api.php(418): WP_REST_Server->serve_request()
#9 /wp-content/plugins/woo-stripe-payment/includes/class-wc-stripe-rest-api.php(159): rest_api_loaded()
#10 /wp-includes/class-wp-hook.php(310): WC_Stripe_Rest_API->process_frontend_request()
#11 /wp-includes/class-wp-hook.php(334): WP_Hook->apply_filters()
#12 /wp-includes/plugin.php(517): WP_Hook->do_action()
#13 /wp-content/plugins/woocommerce/includes/class-wc-ajax.php(96): do_action()
#14 /wp-includes/class-wp-hook.php(310): WC_AJAX::do_wc_ajax()
#15 /wp-includes/class-wp-hook.php(334): WP_Hook->apply_filters()
#16 /wp-includes/plugin.php(517): WP_Hook->do_action()
#17 /wp-includes/template-loader.php(13): do_action()
#18 /wp-blog-header.php(19): require_once('/var/www/html/u...')
#19 /index.php(17): require('/var/www/html/u...')
#20 {main}

Changelog entry

Fix - AddToCart duplication when other plugins clone cart

Other plugins often clone Woocommerce cart to do various "on the fly" calculations and now this causes duplication of the AddToCart server events.

This fixes it once and forever ;)
@ibndawood
Copy link
Contributor

Thank you, @StyleT, for your contribution. We'll have this PR reviewed by our team as soon as possible.

Copy link
Contributor

@rawdreeg rawdreeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code is good, and thanks for your contribution. Just a coding style related issue to be fixed before we can merge this.

@rawdreeg
Copy link
Contributor

rawdreeg commented Oct 2, 2023

Hi @StyleT,

I have dropped a few review comments. Let us know if you have any questions.

Update: I committed then suggestion, I will proceed with merging this.

Thanks.
R

@rawdreeg rawdreeg merged commit a96533d into facebook:develop Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Meta Add To Cart Reporting Issue
3 participants