woocommerce / woocommerce-blocks

(Deprecated) This plugin has been merged into woocommerce/woocommerce
https://wordpress.org/plugins/woo-gutenberg-products-block/
GNU General Public License v3.0
407 stars 219 forks source link

Use of REST API cart endpoint provokes a fatal error #2924

Closed markhowellsmead closed 4 years ago

markhowellsmead commented 4 years ago

Please provide us with the information requested in this bug report. Without these details, we won't be able to fully evaluate this issue. Bug reports lacking detail, or for any other reason than to report a bug, may be closed without action.

Prerequisites (mark completed items with an [x]):

Describe the bug example.org/wp-json/wc/store/cart/items always fails with HTTP 500 and the following entry in the fatal errors log:

CRITICAL Uncaught Error: Call to a member function get_cart() on null in [[WEBROOT]]/wp-content/plugins/woocommerce/packages/woocommerce-blocks/src/StoreApi/Utilities/CartController.php:410

Expected behavior The error should not occur.

Actual behavior The error noted above occurs.

Steps to reproduce the bug (We need to be able to reproduce the bug in order to fix it.) Steps to reproduce the bug:

  1. Go to the URL indicated.
  2. See error

Isolating the problem (mark completed items with an [x]):

WordPress Environment

``` ` ### WordPress Environment ### WordPress address (URL): https://PRIVATE/ Site address (URL): https://PRIVATE/ WC Version: 4.3.1 REST API Version: ✔ 1.0.10 WC Blocks Version: ✔ 2.7.2 Action Scheduler Version: ✔ 3.1.6 WC Admin Version: ✔ 1.3.1 Log Directory Writable: ✔ WP Version: 5.4.2 WP Multisite: ✔ WP Memory Limit: 256 MB WP Debug Mode: ✔ WP Cron: – Language: de_CH External object cache: – ### Server Environment ### Server Info: Apache/2.4.10 (Debian) PHP Version: 7.3.2 PHP Post Max Size: 1'000 MB PHP Time Limit: 900 PHP Max Input Vars: 3000 cURL Version: 7.38.0 OpenSSL/1.0.1t SUHOSIN Installed: – MySQL Version: 5.6.34 Max Upload Size: 10 MB Default Timezone is UTC: ✔ fsockopen/cURL: ✔ SoapClient: ✔ DOMDocument: ✔ GZip: ✔ Multibyte String: ✔ Remote Post: ✔ Remote Get: ✔ ### Database ### WC Database Version: 4.3.1 WC Database Prefix: wp_3_ Datenbank-Gesamtgrösse: 34.93MB Datenbank-Datengrösse: 23.34MB Datenbank-Indexgrösse: 11.59MB wp_3_woocommerce_sessions: Daten: 10.52MB + Index: 0.14MB + Engine InnoDB wp_3_woocommerce_api_keys: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_woocommerce_attribute_taxonomies: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB wp_3_woocommerce_downloadable_product_permissions: Daten: 0.02MB + Index: 0.06MB + Engine InnoDB wp_3_woocommerce_order_items: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB wp_3_woocommerce_order_itemmeta: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_woocommerce_tax_rates: Daten: 0.02MB + Index: 0.06MB + Engine InnoDB wp_3_woocommerce_tax_rate_locations: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_woocommerce_shipping_zones: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB wp_3_woocommerce_shipping_zone_locations: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_woocommerce_shipping_zone_methods: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB wp_3_woocommerce_payment_tokens: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB wp_3_woocommerce_payment_tokenmeta: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_woocommerce_log: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB wp_3_actionscheduler_actions: Daten: 0.02MB + Index: 0.11MB + Engine InnoDB wp_3_actionscheduler_claims: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB wp_3_actionscheduler_groups: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB wp_3_actionscheduler_logs: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_aws_cache: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB wp_3_aws_index: Daten: 1.52MB + Index: 0.56MB + Engine InnoDB wp_3_commentmeta: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_comments: Daten: 0.02MB + Index: 0.09MB + Engine InnoDB wp_3_links: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB wp_3_matomo_access: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB wp_3_matomo_archive_blob_2020_01: Daten: 0.11MB + Index: 0.05MB + Engine InnoDB wp_3_matomo_archive_blob_2020_06: Daten: 0.30MB + Index: 0.11MB + Engine InnoDB wp_3_matomo_archive_numeric_2008_12: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_matomo_archive_numeric_2009_01: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_matomo_archive_numeric_2010_01: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_matomo_archive_numeric_2011_01: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_matomo_archive_numeric_2012_01: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_matomo_archive_numeric_2013_01: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_matomo_archive_numeric_2014_01: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_matomo_archive_numeric_2015_01: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_matomo_archive_numeric_2016_01: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_matomo_archive_numeric_2017_01: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_matomo_archive_numeric_2018_01: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_matomo_archive_numeric_2019_01: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_matomo_archive_numeric_2019_09: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_matomo_archive_numeric_2019_10: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_matomo_archive_numeric_2019_11: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_matomo_archive_numeric_2019_12: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_matomo_archive_numeric_2020_01: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_matomo_archive_numeric_2020_02: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_matomo_archive_numeric_2020_03: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_matomo_archive_numeric_2020_04: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_matomo_archive_numeric_2020_05: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_matomo_archive_numeric_2020_06: Daten: 0.08MB + Index: 0.16MB + Engine InnoDB wp_3_matomo_brute_force_log: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB wp_3_matomo_goal: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB wp_3_matomo_locks: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB wp_3_matomo_logger_message: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB wp_3_matomo_log_action: Daten: 0.06MB + Index: 0.02MB + Engine InnoDB wp_3_matomo_log_conversion: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_matomo_log_conversion_item: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB wp_3_matomo_log_link_visit_action: Daten: 0.19MB + Index: 0.13MB + Engine InnoDB wp_3_matomo_log_profiling: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB wp_3_matomo_log_visit: Daten: 0.14MB + Index: 0.05MB + Engine InnoDB wp_3_matomo_option: Daten: 0.19MB + Index: 0.02MB + Engine InnoDB wp_3_matomo_plugin_setting: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB wp_3_matomo_privacy_logdata_anonymizations: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB wp_3_matomo_report: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB wp_3_matomo_report_subscriptions: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB wp_3_matomo_segment: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB wp_3_matomo_sequence: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB wp_3_matomo_session: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB wp_3_matomo_site: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB wp_3_matomo_site_setting: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB wp_3_matomo_site_url: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB wp_3_matomo_tracking_failure: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB wp_3_matomo_twofactor_recovery_code: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB wp_3_matomo_user: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB wp_3_matomo_user_dashboard: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB wp_3_matomo_user_language: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB wp_3_options: Daten: 0.39MB + Index: 0.06MB + Engine InnoDB wp_3_postmeta: Daten: 1.52MB + Index: 0.55MB + Engine InnoDB wp_3_posts: Daten: 1.52MB + Index: 0.13MB + Engine InnoDB wp_3_redirection_404: Daten: 0.02MB + Index: 0.06MB + Engine InnoDB wp_3_redirection_groups: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_redirection_items: Daten: 0.02MB + Index: 0.09MB + Engine InnoDB wp_3_redirection_logs: Daten: 0.02MB + Index: 0.08MB + Engine InnoDB wp_3_relevanssi: Daten: 3.52MB + Index: 6.05MB + Engine InnoDB wp_3_relevanssi_log: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB wp_3_relevanssi_stopwords: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB wp_3_statistics_exclusions: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_statistics_historical: Daten: 0.02MB + Index: 0.05MB + Engine InnoDB wp_3_statistics_pages: Daten: 0.13MB + Index: 0.42MB + Engine InnoDB wp_3_statistics_search: Daten: 0.02MB + Index: 0.05MB + Engine InnoDB wp_3_statistics_useronline: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB wp_3_statistics_visit: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB wp_3_statistics_visitor: Daten: 0.09MB + Index: 0.13MB + Engine InnoDB wp_3_termmeta: Daten: 0.05MB + Index: 0.03MB + Engine InnoDB wp_3_terms: Daten: 0.05MB + Index: 0.03MB + Engine InnoDB wp_3_term_relationships: Daten: 0.06MB + Index: 0.05MB + Engine InnoDB wp_3_term_taxonomy: Daten: 0.05MB + Index: 0.03MB + Engine InnoDB wp_3_wacv_abandoned_cart_record: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB wp_3_wacv_cart_log: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB wp_3_wacv_email_history: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB wp_3_wacv_guest_info_record: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB wp_3_wc_admin_notes: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB wp_3_wc_admin_note_actions: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB wp_3_wc_category_lookup: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB wp_3_wc_customer_lookup: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_wc_download_log: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_wc_order_coupon_lookup: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_wc_order_product_lookup: Daten: 0.02MB + Index: 0.06MB + Engine InnoDB wp_3_wc_order_stats: Daten: 0.02MB + Index: 0.05MB + Engine InnoDB wp_3_wc_order_tax_lookup: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_wc_product_meta_lookup: Daten: 0.06MB + Index: 0.09MB + Engine InnoDB wp_3_wc_reserved_stock: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB wp_3_wc_tax_rate_classes: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB wp_3_wc_webhooks: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB wp_3_wpmailsmtp_emails_log: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_wpmailsmtp_tasks_meta: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB wp_3_yoast_indexable: Daten: 0.33MB + Index: 0.09MB + Engine InnoDB wp_3_yoast_indexable_hierarchy: Daten: 0.02MB + Index: 0.05MB + Engine InnoDB wp_3_yoast_migrations: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB wp_3_yoast_primary_term: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_3_yoast_seo_links: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB wp_3_yoast_seo_meta: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB wp_blogmeta: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_blogs: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB wp_registration_log: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB wp_signups: Daten: 0.02MB + Index: 0.06MB + Engine InnoDB wp_site: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB wp_sitemeta: Daten: 0.16MB + Index: 0.03MB + Engine InnoDB wp_usermeta: Daten: 0.20MB + Index: 0.09MB + Engine InnoDB wp_users: Daten: 0.02MB + Index: 0.05MB + Engine InnoDB ### Post Type Counts ### acf-field: 69 acf-field-group: 23 attachment: 171 block_area: 1 customize_changeset: 22 nav_menu_item: 9 page: 12 post: 4 product: 204 revision: 96 shop_order: 4 wacv_email_template: 3 wp_block: 1 ### Security ### Secure connection (HTTPS): ✔ Hide errors from visitors: ❌Fehlermeldungen sollten Besuchern nicht angezeigt werden. ### Active Plugins (16) ### WooCommerce: von Automattic – 4.3.1 Advanced Custom Fields PRO: von Elliot Condon – 5.8.12 Block Areas: von The WP Rig Contributors – 0.2.0 Reading Time WP: von Jason Yingling – 2.0.9 Members: von MemberPress – 3.0.10 Preferred Languages: von Pascal Birchler – 1.6.0 Regenerate Thumbnails: von Alex Mills (Viper007Bond) – 3.1.3 Redirection: von John Godley – 4.8 Email Templates: von Damian Logghe – 1.3.1.2 Enable Media Replace: von ShortPixel – 3.4.1 WP Mail SMTP Pro: von WPForms – 2.2.1 Safe SVG: von Daryll Doyle – 1.9.9 Matomo Analytics - Ethische Statistiken. Eindrucksvolle Einblicke.: von Matomo – 1.2.0 – Die installierte Version wurde nicht mit der aktiven WooCommerce-Version 4.3.1 getestet WP Statistics: von VeronaLabs – 12.6.13 User Switching: von John Blackbourn und Mitwirkende – 1.5.5 Yoast SEO: von Team Yoast – 14.6.1 ### Inactive Plugins (3) ### iThemes Security Pro: von iThemes – 6.6.0 Relevanssi: von Mikko Saari – 4.7.2.1 WooCommerce Services: von Automattic – 1.23.2 – Die installierte Version wurde nicht mit der aktiven WooCommerce-Version 4.3.1 getestet ### Must Use Plugins (1) ### Local by Flywheel Relative URL (for Live Links): von Flywheel – 1.1 ### 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) 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-Basis: woocommerce/woocommerce#20 - /produkte/ Warenkorb: woocommerce/woocommerce#21 - /warenkorb/ Kasse: woocommerce/woocommerce#22 - /kasse/ Mein Konto: woocommerce/woocommerce#23 - /mein-konto/ Allgemeine Geschäftsbedingungen: woocommerce/woocommerce#660 - /agb/ ### Theme ### Name: PRIVATE Version: 1.16.7 Author URL: https://PRIVATE Child Theme: ❌ – Wenn Sie WooCommerce mit einem Theme das Sie nicht selbst entwickelt haben an eigene Bedürfnisse anpassen dann empfehlen wir die Verwendung eines Child-Themes. Siehe Wie Sie ein Child-Theme erstellen (engl.) WooCommerce Support: ✔ ### Templates ### Overrides: PRIVATE/archive-product.php ### Action Scheduler ### Abgeschlossen: 4 Oldest: 2020-07-08 16:21:51 +0200 Newest: 2020-07-27 09:41:43 +0200 ` ```
nerrad commented 4 years ago

I can reproduce, while we definitely have to handle the fatal condition, the route is designed to only work when there is a cart in session. So the first problem here is that there likely isn't a cart in session available when accessing the endpoint.