co-cart / co-cart

🛒 CoCart makes it easy to decouple your WooCommerce store via a customizable REST API that takes the pain out of developing – allowing you to build fast and flexible headless stores.

Home Page:https://cocartapi.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[3.1 rc 4]: Add to Cart response crash

DarkChris86 opened this issue · comments

Describe the bug

Add to cart url response showing a site crash

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. Add product to cart by {{COCART_API_URL}}/cart/add-item?id=<product_id>
  2. Response will be a site crash, but added succesfully to the cart

Expected/actual behaviour

Add product to the cart without site crash response

Errors

[21-Sep-2021 15:47:38 UTC] PHP Fatal error: Uncaught Error: Non-static method CoCart_Cart_Cache::set_cached_item() cannot be called statically in /wp-content/plugins/cart-rest-api-for-woocommerce/includes/api/class-cocart-cart-controller.php:1545
Stack trace:
#0 /wp-content/plugins/cart-rest-api-for-woocommerce/includes/api/class-cocart-add-item-controller.php(148): CoCart_Cart_V2_Controller->cache_cart_item(Array)
#1 /wp-includes/rest-api/class-wp-rest-server.php(1140): CoCart_Add_Item_v2_Controller->add_to_cart(Object(WP_REST_Request))
#2 /wp-includes/rest-api/class-wp-rest-server.php(987): WP_REST_Server->respond_to_request(Object(WP_REST_Request), '/cocart/v2/cart...', Array, NULL)
#3 /wp-includes/rest-api/class-wp-rest-server.php(414): WP_REST_Server->dispatch(Object(WP_REST_Request))
#4 /wp-includes/rest-api.php(370): WP_REST_Server->serve_request('/cocart/v2/cart...')
#5 /wp-includes/class-wp-hook.php(303): rest_api_loaded(Object(WP))
#6 /wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters(NULL, Array)
#7 /wp-includes/plugin.php(518): WP_Hook->do_action(Array)
#8 /wp-includes/class-wp.php(388): do_action_ref_array('parse_request', Array)
#9 /wp-includes/class-wp.php(750): WP->parse_request('')
#10 /wp-includes/functions.php(1291): WP->main('')
#11 /wp-blog-header.php(16): wp()
#12 /index.php(17): require('/home/clients/8...')
#13 {main}
thrown in /wp-content/plugins/cart-rest-api-for-woocommerce/includes/api/class-cocart-cart-controller.php on line 1545

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>

@DarkChris86 Can you test the PHP 8 branch to see if this error has now disappeared?

@seb86 I can confirm the Add to Cart function related error disappeared.

I got the following Warnings in PHP 8
[24-Sep-2021 06:25:50 UTC] cocart_get_cart is deprecated since version 3.0.0 with no alternative available. [24-Sep-2021 06:25:50 UTC] PHP Warning: Undefined variable $item_key in /wp-content/plugins/co-cart-master/includes/api/class-cocart-cart-controller.php on line 957

@DarkChris86 Updated PHP8 branch.

@seb86 Still got these + checked v3.0.12 and there also ( PHP 8 )

[24-Sep-2021 16:44:55 UTC] cocart_get_cart is deprecated since version 3.0.0 with no alternative available. [24-Sep-2021 16:44:55 UTC] PHP Warning: Undefined variable $item_key in /wp-content/plugins/cart-rest-api-for-woocommerce/includes/api/class-cocart-cart-controller.php on line 915

That last error does not make sense. This is line 915 for that file.

@DarkChris86 This error log is fine. It is only shown if you have debug mode enabled.

"cocart_get_cart is deprecated since version 3.0.0"

As for the undefined $item_key it should be fixed now.