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

Cannot add items into cart [3.1 RC4]

vertisan opened this issue Β· comments

Describe the bug

On the latest RC release (3.1 RC4) on PHP 8, we cannot any items into the cart due to an error with code 500.

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. Install the CoCart 3.1 RC4.
  2. Enable the plugin.
  3. Try to add any item into the cart, i.e.
curl --request POST 'https://shop.com/wp-json/cocart/v2/cart/add-item?cart_key=custom_key' --header 'Content-Type: application/json' --data-raw '{"id": "24","quantity": "1"}'

Expected/actual behavior

When I follow those steps, I see the 500 error with the following reason:

PHP Fatal error:  Uncaught TypeError: array_merge(): Argument #1 must be of type array, null given in /var/www/html/wp-content/plugins/cart-rest-api-for-woocommerce/includes/class-cocart-woocommerce.php:147\nStack trace:\n#0 /var/www/html/wp-content/plugins/cart-rest-api-for-woocommerce/includes/class-cocart-woocommerce.php(147): array_merge(NULL, NULL)\n#1 /var/www/html/wp-includes/class-wp-hook.php(303): CoCart_WooCommerce::load_cart_from_session('')\n#2 /var/www/html/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters('', Array)\n#3 /var/www/html/wp-includes/plugin.php(470): WP_Hook->do_action(Array)\n#4 /var/www/html/wp-content/plugins/woocommerce/includes/class-wc-cart-session.php(72): do_action('woocommerce_loa...')\n#5 /var/www/html/wp-includes/class-wp-hook.php(303): WC_Cart_Session->get_cart_from_session('')\n#6 /var/www/html/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters(NULL, Array)\n#7 /var/www/html/wp-includes/plugin.php(470): WP_Hook->do_action(Array)\n#8 /var/www/html/wp-settings.php(600): do_action('wp_loaded')\n#9 /var/www/html/wp-config.php(133): require_once('/var/www/html/w...')\n#10 /var/www/html/wp-load.php(50): require_once('/var/www/html/w...')\n#11 /var/www/html/wp-blog-header.php(13): require_once('/var/www/html/w...')\n#12 /var/www/html/index.php(17): require('/var/www/html/w...')\n#13 {main}\n  thrown in /var/www/html/wp-content/plugins/cart-rest-api-for-woocommerce/includes/class-cocart-woocommerce.php on line 147

I was expecting to get a correct cart with the added items.

Screenshots

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 an administrator.
  • I can reproduce this bug consistently using the steps above.

WordPress Environment

```

WordPress Environment

WordPress address (URL): xxx
Site address (URL): xxx
WC Version: 5.7.1
REST API Version: βœ” 5.7.1
WC Blocks Version: βœ” 5.7.2
Action Scheduler Version: βœ” 3.2.1
WC Admin Version: βœ” 2.6.5
Log Directory Writable: βœ”
WP Version: 5.8.1
WP Multisite: –
WP Memory Limit: 256 MB
WP Debug Mode: –
WP Cron: βœ”
Language: en_US
External object cache: –

Server Environment

Server Info: Apache/2.4.48 (Debian)
PHP Version: 8.0.11
PHP Post Max Size: 8 MB
PHP Time Limit: 30
PHP Max Input Vars: 1000
cURL Version: 7.74.0
OpenSSL/1.1.1k

SUHOSIN Installed: –
MySQL Version: 5.7.35
Max Upload Size: 2 MB
Default Timezone is UTC: βœ”
fsockopen/cURL: βœ”
SoapClient: βœ”
DOMDocument: βœ”
GZip: βœ”
Multibyte String: βœ”
Remote Post: βœ”
Remote Get: βœ”

Database

WC Database Version: 5.7.1
WC Database Prefix: swp_
Total Database Size: 5.12MB
Database Data Size: 3.43MB
Database Index Size: 1.69MB
swp_woocommerce_sessions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
swp_woocommerce_api_keys: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
swp_woocommerce_attribute_taxonomies: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
swp_woocommerce_downloadable_product_permissions: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
swp_woocommerce_order_items: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
swp_woocommerce_order_itemmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
swp_woocommerce_tax_rates: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
swp_woocommerce_tax_rate_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
swp_woocommerce_shipping_zones: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
swp_woocommerce_shipping_zone_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
swp_woocommerce_shipping_zone_methods: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
swp_woocommerce_payment_tokens: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
swp_woocommerce_payment_tokenmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
swp_woocommerce_log: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
swp_actionscheduler_actions: Data: 0.02MB + Index: 0.13MB + Engine InnoDB
swp_actionscheduler_claims: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
swp_actionscheduler_groups: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
swp_actionscheduler_logs: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
swp_cocart_carts: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
swp_commentmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
swp_comments: Data: 0.02MB + Index: 0.09MB + Engine InnoDB
swp_gla_budget_recommendations: Data: 0.22MB + Index: 0.14MB + Engine InnoDB
swp_gla_merchant_issues: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
swp_gla_shipping_rates: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
swp_gla_shipping_times: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
swp_links: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
swp_options: Data: 2.11MB + Index: 0.08MB + Engine InnoDB
swp_postmeta: Data: 0.13MB + Index: 0.06MB + Engine InnoDB
swp_posts: Data: 0.06MB + Index: 0.06MB + Engine InnoDB
swp_termmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
swp_terms: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
swp_term_relationships: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
swp_term_taxonomy: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
swp_usermeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
swp_users: Data: 0.02MB + Index: 0.05MB + Engine InnoDB
swp_wc_admin_notes: Data: 0.05MB + Index: 0.00MB + Engine InnoDB
swp_wc_admin_note_actions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
swp_wc_category_lookup: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
swp_wc_customer_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
swp_wc_download_log: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
swp_wc_order_coupon_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
swp_wc_order_product_lookup: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
swp_wc_order_stats: Data: 0.02MB + Index: 0.05MB + Engine InnoDB
swp_wc_order_tax_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
swp_wc_product_meta_lookup: Data: 0.02MB + Index: 0.09MB + Engine InnoDB
swp_wc_reserved_stock: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
swp_wc_tax_rate_classes: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
swp_wc_webhooks: Data: 0.02MB + Index: 0.02MB + Engine InnoDB

Post Type Counts

attachment: 23
page: 7
post: 2
product: 18
product_variation: 7
shop_order: 1

Security

Secure connection (HTTPS): βœ”
Hide errors from visitors: βœ”

Active Plugins (2)

CoCart Lite: by SΓ©bastien Dumont – 3.1.0-rc.4
WooCommerce: by Automattic – 5.7.1

Inactive Plugins (0)

Settings

API Enabled: –
Force SSL: –
Currency: PLN (zΕ‚)
Currency Position: right_space
Thousand Separator:
Decimal Separator: ,
Number of Decimals: 2
Taxonomies: Product Types: external (external)
grouped (grouped)
simple (simple)
variable (variable)

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: #6 - /shop/
Cart: #7 - /cart/
Checkout: #8 - /checkout/
My account: #9 - /my-account/
Terms and conditions: ❌ Page not set

Theme

Name: Storefront child
Version: (update to version 0 is available)
Author URL:
Child Theme: βœ”
Parent Theme Name: Storefront
Parent Theme Version: 3.9.1
Parent Theme Author URL: https://woocommerce.com/
WooCommerce Support: βœ”

Templates

Overrides: –

Action Scheduler

Complete: 31
Oldest: 2021-10-09 14:38:19 +0000
Newest: 2021-10-11 14:23:58 +0000

CoCart

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

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

Status report information

Generated at: 2021-10-11 14:26:11 +00:00

</details>

## Additional context

<!--Any additional context or details you think might be helpful.-->

Thank you for the report. Bug should be solved now which is currently on the master branch.