co-cart / co-cart

🛒 CoCart is a free REST API designed to decouple your slow WooCommerce storefront and convert it blazing-fast, build in any web framework, and save you countless hours.

Home Page:https://cocartapi.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[3.1 rc 4]: Cart does not clear due to session not closing before returning cart results

DarkChris86 opened this issue · comments

Describe the bug

Cart clear url doesn't clear the cart at the backend.

Prerequisites

  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • The issue still exists against the latest master branch of CoCart on GitHub (this is not the same version as on WordPress.org!)
  • I have attempted to find the simplest possible steps to reproduce the issue.
  • I have included a failing test as a pull request (Optional)
  • I have installed the requirements to run this plugin.

Steps to reproduce the issue

  1. {{COCART_API_URL}}/cart/clear?keep_removed_items=false
  2. Check your Cart
  3. Still not empty

Expected/actual behaviour

Clear the cart at the backend

Screenshots

image

Isolating the problem

  • This bug happens with only WooCommerce and CoCart plugin are active.
  • This bug happens with a default WordPress theme active.
  • This bug happens with the WordPress theme Storefront active.
  • This bug happens with the latest release of WooCommerce active.
  • This bug happens only when I authenticate as a customer.
  • This bug happens only when I authenticate as administrator.
  • I can reproduce this bug consistently using the steps above.

WordPress Environment

``` ` ### WordPress Environment ###

WordPress address (URL): https://bbdiam.com
Site address (URL): https://bbdiam.com
WC Version: 5.6.0
REST API Version: ✔ 5.6.0
WC Blocks Version: ✔ 5.5.1
Action Scheduler Version: ✔ 3.2.1
WC Admin Version: ✔ 2.5.1
Log Directory Writable: ✔
WP Version: 5.8.1
WP Multisite: –
WP Memory Limit: 640 MB
WP Debug Mode: ✔
WP Cron: ✔
Language: en_US
External object cache: –

Server Environment

Server Info: Apache
PHP Version: 8.0.9
PHP Post Max Size: 300 MB
PHP Time Limit: 60
PHP Max Input Vars: 10000
cURL Version: 7.52.1
OpenSSL/1.0.2l

SUHOSIN Installed: –
MySQL Version: 5.7.32-log
Max Upload Size: 300 MB
Default Timezone is UTC: ✔
fsockopen/cURL: ✔
SoapClient: ✔
DOMDocument: ✔
GZip: ✔
Multibyte String: ✔
Remote Post: ✔
Remote Get: ✔

Database

WC Database Version: 5.6.0
WC Database Prefix: wp_687357_
Total Database Size: 5.31MB
Database Data Size: 3.52MB
Database Index Size: 1.79MB
wp_687357_woocommerce_sessions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_687357_woocommerce_api_keys: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_687357_woocommerce_attribute_taxonomies: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_687357_woocommerce_downloadable_product_permissions: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
wp_687357_woocommerce_order_items: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_687357_woocommerce_order_itemmeta: Data: 0.05MB + Index: 0.03MB + Engine InnoDB
wp_687357_woocommerce_tax_rates: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
wp_687357_woocommerce_tax_rate_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_687357_woocommerce_shipping_zones: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_687357_woocommerce_shipping_zone_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_687357_woocommerce_shipping_zone_methods: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_687357_woocommerce_payment_tokens: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_687357_woocommerce_payment_tokenmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_687357_woocommerce_log: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_687357_actionscheduler_actions: Data: 0.06MB + Index: 0.13MB + Engine InnoDB
wp_687357_actionscheduler_claims: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_687357_actionscheduler_groups: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_687357_actionscheduler_logs: Data: 0.06MB + Index: 0.03MB + Engine InnoDB
wp_687357_cocart_carts: Data: 0.05MB + Index: 0.02MB + Engine InnoDB
wp_687357_commentmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_687357_comments: Data: 0.05MB + Index: 0.09MB + Engine InnoDB
wp_687357_diamond_subscriptions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_687357_duplicator_pro_entities: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_687357_duplicator_pro_packages: Data: 0.05MB + Index: 0.02MB + Engine InnoDB
wp_687357_links: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_687357_options: Data: 2.08MB + Index: 0.20MB + Engine InnoDB
wp_687357_postmeta: Data: 0.22MB + Index: 0.17MB + Engine InnoDB
wp_687357_posts: Data: 0.06MB + Index: 0.06MB + Engine InnoDB
wp_687357_termmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_687357_terms: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_687357_term_relationships: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_687357_term_taxonomy: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_687357_usermeta: Data: 0.05MB + Index: 0.03MB + Engine InnoDB
wp_687357_users: Data: 0.02MB + Index: 0.05MB + Engine InnoDB
wp_687357_wcpdf_invoice_number: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_687357_wc_admin_notes: Data: 0.05MB + Index: 0.00MB + Engine InnoDB
wp_687357_wc_admin_note_actions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_687357_wc_category_lookup: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_687357_wc_customer_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_687357_wc_download_log: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_687357_wc_order_coupon_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_687357_wc_order_product_lookup: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
wp_687357_wc_order_stats: Data: 0.02MB + Index: 0.05MB + Engine InnoDB
wp_687357_wc_order_tax_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_687357_wc_product_meta_lookup: Data: 0.02MB + Index: 0.09MB + Engine InnoDB
wp_687357_wc_reserved_stock: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_687357_wc_tax_rate_classes: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_687357_wc_webhooks: Data: 0.02MB + Index: 0.02MB + Engine InnoDB

Post Type Counts

acf-field: 5
acf-field-group: 2
attachment: 5
customize_changeset: 1
nav_menu_item: 5
page: 8
post: 3
product: 3
revision: 7
shop_order: 28
shop_subscription: 5

Security

Secure connection (HTTPS): ✔
Hide errors from visitors: ✔

Active Plugins (16)

Advanced Custom Fields PRO: by Delicious Brains – 5.10.2
REST API Password Reset with Code: by Be Devious Web Development – 0.0.13
CoCart Lite: by Sébastien Dumont – 3.0.12
CoCart - Carts in Session: by Sébastien Dumont – 1.0.0-alpha.5
CoCart CORS: by Sébastien Dumont – 1.0.0
CoCart - Cart Enhanced: by Sébastien Dumont – 3.0.4
CoCart Pro: by Sébastien Dumont – 1.0.0-rc.5
CoCart - Products: by Sébastien Dumont – 1.0.0-beta.12
Duplicator Pro: by Snap Creek – 4.0.4.1
Rename wp-login.php: by Ella van Durpe – 2.6.0
REST API Toolbox: by Pete Nelson – 1.4.3
Shipping Method Description for WooCommerce: by Thomas Charbit – 1.0.0
WooCommerce Stripe Gateway: by WooCommerce – 5.5.0
WooCommerce PDF Invoices & Packing Slips: by Ewout Fernhout – 2.9.3
WooCommerce Subscriptions: by WooCommerce – 3.1.4
WooCommerce: by Automattic – 5.6.0

Inactive Plugins (0)

Settings

API Enabled: –
Force SSL: –
Currency: CHF (CHF)
Currency Position: left_space
Thousand Separator: '
Decimal Separator: .
Number of Decimals: 2
Taxonomies: Product Types: external (external)
grouped (grouped)
simple (simple)
subscription (subscription)
variable (variable)
variable subscription (variable-subscription)

Taxonomies: Product Visibility: exclude-from-catalog (exclude-from-catalog)
exclude-from-search (exclude-from-search)
featured (featured)
outofstock (outofstock)
rated-1 (rated-1)
rated-2 (rated-2)
rated-3 (rated-3)
rated-4 (rated-4)
rated-5 (rated-5)

Connected to WooCommerce.com: ✔

WC Pages

Shop base: #5 - /
Cart: #6 - /cart/
Checkout: #7 - /checkout/
My account: #8 - /my-account/
Terms and conditions: #3 - /privacy-policy/

Theme

Name: Twenty Twenty-One Child
Version: 1.0.0
Author URL: https://webmernok.hu/
Child Theme: ✔
Parent Theme Name: Twenty Twenty-One
Parent Theme Version: 1.4
Parent Theme Author URL: https://wordpress.org/
WooCommerce Support: ✔

Templates

Overrides: twenty-twenty-one-child/woocommerce/cart/cart.php
twenty-twenty-one-child/woocommerce/checkout/form-checkout.php
twenty-twenty-one-child/woocommerce/checkout/review-order.php
twenty-twenty-one-child/woocommerce/checkout/thankyou.php

Subscriptions

WCS_DEBUG: ✔ No
Subscriptions Mode: ✔ Live
Subscriptions Live URL: https://bbdiam.com
Subscriptions Template Theme Overrides: twenty-twenty-one-child/woocommerce/myaccount/my-subscriptions.php
twenty-twenty-one-child/woocommerce/myaccount/related-orders.php
twenty-twenty-one-child/woocommerce/myaccount/related-subscriptions.php
twenty-twenty-one-child/woocommerce/myaccount/subscription-details.php
twenty-twenty-one-child/woocommerce/myaccount/subscription-totals-table.php
twenty-twenty-one-child/woocommerce/myaccount/subscription-totals.php
twenty-twenty-one-child/woocommerce/myaccount/subscriptions.php
twenty-twenty-one-child/woocommerce/myaccount/view-subscription.php

Subscription Statuses: wc-active: 5
WooCommerce Account Connected: ✔ Yes
Active Product Key: ✔ Yes
Report Cache Enabled: ✔ Yes
Cache Update Failures: ✔ 0 failure

Store Setup

Country / State: Switzerland — Geneva

Subscriptions by Payment Gateway

Stripe: wc-active: 5

Payment Gateway Support

Stripe: products
refunds
tokenization
add_payment_method
subscriptions
subscription_cancellation
subscription_suspension
subscription_reactivation
subscription_amount_changes
subscription_date_changes
subscription_payment_method_change
subscription_payment_method_change_customer
subscription_payment_method_change_admin
multiple_subscriptions
pre-orders

Action Scheduler

Complete: 124
Oldest: 2021-08-26 10:36:14 +0200
Newest: 2021-09-21 18:19:42 +0200

Pending: 5
Oldest: 2021-09-23 20:09:13 +0200
Newest: 2021-10-09 13:51:26 +0200

CoCart

Version: 3.0.12
Database Version: 3.1.0-rc.4
Install Date: July 8
2021

Carts in Session: 10
Carts Active: 10 out of 10 in session.
Carts Expiring Soon: 0 out of 10 in session.
Carts Expired: 0 out of 10 in session.
Carts Source (by CoCart): 0
Carts Source (by Web): 7
Carts Source (by Other): 3

Status report information

Generated at: 2021-09-21 18:33:22 +02:00
`

</details>

My bad. This bug was caused by supporting a new feature. I have now asked the cart cache to clear when requested to clear the cart.

@seb86 I tested with the latest master branch, but still the cart not empty after clear cart request, but maybe it is on your progress list yet.

@DarkChris86 Your kidding me. It worked fine again for me once I added the hook. I will check again.

So even though the clear cart route has it's response changed from just a message response to returning the cart object, the session was not closing at all times. Also the cart class was not wiping even though the session was.

We attempted to clear the session instead because an internal function within the cart class for the fees was set as private and calling WC->cart->empty_cart() was not working via the REST API which is why I thought clearing the session was enough. Turns out it is not.

As a work around we forked the function, kept the cart fees to be cleared by session as it uses it's own API system rather than be part of the cart object like everything else and force a session save before the cart object response is returned.

This way should the session not save after updating the cart later, it's still correct when fetching the cart.

It has been a problem since the start of CoCart so I'm pleased to see more stable results.

Still more tests to be done but I think this one may be the winning ticket.

Closing as there has been no further reports.