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

CRITICAL Uncaught Error: Call to a member function get_type() on bool #336

Closed
6 of 13 tasks
jnz31 opened this issue May 5, 2022 · 3 comments
Closed
6 of 13 tasks
Labels
focus: products API This issue/PR is related to the products API. PHP: 8.0 Issues related to PHP 8.0 only. priority: low The issue/PR is low priority—not many people are affected or there’s a workaround, etc. status:changelog added Mark all PRs that have their changelog entries added to CHANGELOG.md status: in progress This is being worked on.

Comments

@jnz31
Copy link

jnz31 commented May 5, 2022

Describe the bug

i got this fatal 500:

CRITICAL Uncaught Error: Call to a member function get_type() on bool in /plugins/cart-rest-api-for-woocommerce/includes/api/cocart/v2/products/class-cocart-products-controller.php:684

from loading a bunch of products e.g. /wp-json/cocart/v2/products/?per_page=20&page=2

The issue is as follows:

The function get_connected_products() receives some product ids, guess for related / cross sells etc.. products. in line 683 you call for $_product = wc_get_product( $id ); but in my case it returns false. not really sure, why that is. i checked one product that was causing this issue, but it had no related/cross sells set, means these get set by wc. but since wc_get_product() only returns bool false, following line $_product->get_type() crashes, resulting in fatal error 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 trunk branch of CoCart on GitHub.
  • The issue still exists against the latest dev 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

i have no clue, why this is happening. maybe it is caused by some external products? these do exist in the mentioned shop but are excluded from the default shop overview. they have their own section in the shop.

Expected/actual behavior

When I follow those steps, I see...

I was expecting to see...

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

WordPress Environment

wp and plugins are all latest. php 8.0.16

Additional context

i got rid of the error, by wrapping the following lines into if statement:

if ($_product) {
    $type = $_product->get_type();

    $connected_products[] = array(
        'id' => $id,
        'name' => $_product->get_name('view'),
        'permalink' => $_product->get_permalink(),
        'price' => cocart_prepare_money_response($_product->get_price('view'), wc_get_price_decimals()),
        'add_to_cart' => array(
            'text' => $_product->add_to_cart_text(),
            'description' => $_product->add_to_cart_description(),
            'rest_url' => $this->add_to_cart_rest_url($_product, $type),
        ),
        'rest_url' => $this->product_rest_url($id),
    );
}

but i am not sure, why wc_get_product() returns false in the first place..

@jnz31 jnz31 added the priority: low The issue/PR is low priority—not many people are affected or there’s a workaround, etc. label May 5, 2022
@seb86 seb86 added the focus: products API This issue/PR is related to the products API. label May 5, 2022
@seb86
Copy link
Member

seb86 commented May 5, 2022

Even if the product is external the product data should still return like any other.

Go to "WooCommerce > System Status. There will be a button to press to copy the system status report. Just paste it here please. Thanks.

@seb86 seb86 added status: in progress This is being worked on. PHP: 8.0 Issues related to PHP 8.0 only. labels May 5, 2022
@seb86
Copy link
Member

seb86 commented May 5, 2022

It could also be an issue with WC it's self in supporting PHP 8. Your method to wrap in an if condition should be fine. Will push a patch asap.

@seb86 seb86 added the status:changelog added Mark all PRs that have their changelog entries added to CHANGELOG.md label May 5, 2022
@seb86 seb86 closed this as completed May 5, 2022
@jnz31
Copy link
Author

jnz31 commented May 6, 2022

Even if the product is external the product data should still return like any other.

Go to "WooCommerce > System Status. There will be a button to press to copy the system status report. Just paste it here please. Thanks.

sorry for not being more specific on this one. i run a filter on cocart_prepare_objects_query to exclude external products. maybe that is interfering with the results in the related products. when i wrapped the function i saw some products with only 3 related products, while i am requesting 4. but whatever, i am more than happy i got rid of the error 500, in exchange for eventually less related products..

system report:
`

WordPress Environment

WC Version: 6.4.1
REST API Version: ✔ 6.4.1
WC Blocks Version: ✔ 7.2.2
Action Scheduler Version: ✔ 3.4.0
WC Admin Version: ✔ 3.3.2
Log Directory Writable: ✔
WP Version: 5.9.3
WP Multisite: –
WP Memory Limit: 512 MB
WP Debug Mode: –
WP Cron: –
Language: en_US
External object cache: –

Server Environment

Server Info: Apache
PHP Version: 8.0.16
PHP Post Max Size: 16 MB
PHP Time Limit: 30
PHP Max Input Vars: 1000
cURL Version: 7.74.0
OpenSSL/1.1.1k

SUHOSIN Installed: –
MySQL Version: 10.5.15-MariaDB-0+deb11u1
Max Upload Size: 16 MB
Default Timezone is UTC: ✔
fsockopen/cURL: ✔
SoapClient: ✔
DOMDocument: ✔
GZip: ✔
Multibyte String: ✔
Remote Post: ✔
Remote Get: ✔

Database

WC Database Version: 6.4.1
WC Database Prefix: wppp16_
Total Database Size: 265.53MB
Database Data Size: 174.64MB
Database Index Size: 90.89MB
wppp16_woocommerce_sessions: Data: 0.08MB + Index: 0.03MB + Engine InnoDB
wppp16_woocommerce_api_keys: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
wppp16_woocommerce_attribute_taxonomies: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wppp16_woocommerce_downloadable_product_permissions: Data: 0.02MB + Index: 0.11MB + Engine InnoDB
wppp16_woocommerce_order_items: Data: 1.52MB + Index: 0.39MB + Engine InnoDB
wppp16_woocommerce_order_itemmeta: Data: 7.52MB + Index: 13.55MB + Engine InnoDB
wppp16_woocommerce_tax_rates: Data: 0.02MB + Index: 0.11MB + Engine InnoDB
wppp16_woocommerce_tax_rate_locations: Data: 0.08MB + Index: 0.25MB + Engine InnoDB
wppp16_woocommerce_shipping_zones: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wppp16_woocommerce_shipping_zone_locations: Data: 0.02MB + Index: 0.08MB + Engine InnoDB
wppp16_woocommerce_shipping_zone_methods: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wppp16_woocommerce_payment_tokens: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wppp16_woocommerce_payment_tokenmeta: Data: 0.02MB + Index: 0.05MB + Engine InnoDB
wppp16_woocommerce_log: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wppp16_actionscheduler_actions: Data: 0.38MB + Index: 0.50MB + Engine InnoDB
wppp16_actionscheduler_claims: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wppp16_actionscheduler_groups: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wppp16_actionscheduler_logs: Data: 0.23MB + Index: 0.20MB + Engine InnoDB
wppp16_cocart_carts: Data: 0.93MB + Index: 0.02MB + Engine MyISAM
wppp16_commentmeta: Data: 0.09MB + Index: 0.11MB + Engine InnoDB
wppp16_comments: Data: 5.52MB + Index: 7.02MB + Engine InnoDB
wppp16_links: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wppp16_newsletter: Data: 2.52MB + Index: 0.47MB + Engine InnoDB
wppp16_newsletter_emails: Data: 0.27MB + Index: 0.00MB + Engine InnoDB
wppp16_newsletter_sent: Data: 1.52MB + Index: 0.81MB + Engine InnoDB
wppp16_newsletter_stats: Data: 1.52MB + Index: 0.64MB + Engine InnoDB
wppp16_newsletter_user_logs: Data: 0.45MB + Index: 0.00MB + Engine InnoDB
wppp16_options: Data: 43.14MB + Index: 1.19MB + Engine InnoDB
wppp16_postmeta: Data: 41.56MB + Index: 31.13MB + Engine InnoDB
wppp16_posts: Data: 12.45MB + Index: 3.52MB + Engine InnoDB
wppp16_termmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wppp16_terms: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wppp16_term_relationships: Data: 0.08MB + Index: 0.06MB + Engine InnoDB
wppp16_term_taxonomy: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wppp16_usermeta: Data: 2.52MB + Index: 4.03MB + Engine InnoDB
wppp16_users: Data: 0.14MB + Index: 0.14MB + Engine InnoDB
wppp16_wc_admin_notes: Data: 0.06MB + Index: 0.00MB + Engine InnoDB
wppp16_wc_admin_note_actions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wppp16_wc_category_lookup: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wppp16_wc_customer_lookup: Data: 0.23MB + Index: 0.20MB + Engine InnoDB
wppp16_wc_download_log: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wppp16_wc_order_coupon_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wppp16_wc_order_product_lookup: Data: 0.47MB + Index: 0.48MB + Engine InnoDB
wppp16_wc_order_stats: Data: 0.27MB + Index: 0.38MB + Engine InnoDB
wppp16_wc_order_tax_lookup: Data: 0.14MB + Index: 0.16MB + Engine InnoDB
wppp16_wc_pos_grid_tiles: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wppp16_wc_product_attributes_lookup: Data: 0.01MB + Index: 0.01MB + Engine MyISAM
wppp16_wc_product_meta_lookup: Data: 0.25MB + Index: 0.47MB + Engine InnoDB
wppp16_wc_rate_limits: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wppp16_wc_reserved_stock: Data: 0.08MB + Index: 0.00MB + Engine MyISAM
wppp16_wc_tax_rate_classes: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wppp16_wc_webhooks: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wppp16_woocommerce_shipping_table_rates: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wppp16_woocommerce_termmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wppp16_woo_sales_country_region: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wppp16_wpmm_subscribers: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wppp16_wrc_caches: Data: 34.95MB + Index: 10.64MB + Engine MyISAM
wppp16_wrc_relations: Data: 9.83MB + Index: 12.11MB + Engine MyISAM
wppp16_yoast_indexable: Data: 3.50MB + Index: 1.23MB + Engine InnoDB
wppp16_yoast_indexable_hierarchy: Data: 0.20MB + Index: 0.28MB + Engine InnoDB
wppp16_yoast_migrations: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wppp16_yoast_primary_term: Data: 0.05MB + Index: 0.03MB + Engine InnoDB
wppp16_yoast_seo_links: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wppp16_yoast_seo_meta: Data: 1.52MB + Index: 0.00MB + Engine InnoDB

Post Type Counts

acf-field: 39
acf-field-group: 9
attachment: 2439
booking: 6
nav_menu_item: 19
oembed_cache: 99
page: 14
pos_outlet: 1
pos_receipt: 1
pos_register: 1
pos_session: 5
pos_temp_order: 1
post: 23
postman_sent_mail: 250
product: 280
product_variation: 265
revision: 1298
shop_coupon: 178
shop_order: 6533
shop_order_refund: 216
wp_global_styles: 1
wpcf7_contact_form: 2

Security

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

Active Plugins (23)

Advanced Custom Fields PRO: by Delicious Brains – 5.12.2
AfterShip Tracking - All-In-One WooCommerce Order Tracking (Free plan available): by AfterShip – 1.14.7
CoCart Lite: by Sébastien Dumont – 3.6.0
CoCart - Cart Enhanced: by Sébastien Dumont – 3.2.0
CoCart Pro: by Sébastien Dumont – 1.0.0-rc.5
CoCart - Products: by Sébastien Dumont – 1.0.0-beta.12
DHL for WooCommerce: by DHL – 2.8.13
Disable Emojis (GDPR friendly): by Ryan Hellyer – 1.7.4
Post SMTP: by Post SMTP – 2.0.26
PP Blocks: by Jens Buss – 1.0.0
PP: by Jens Buss – 1.0.0
Regenerate Thumbnails: by Alex Mills (Viper007Bond) – 3.1.5
REST API Data Localizer: by Brandon Shiluk – 1.0.0
Simple Custom Post Order: by Colorlib – 2.5.6
UpdraftPlus - Backup/Restore: by UpdraftPlus.Com
DavidAnderson – 1.22.12

Invoices for WooCommerce: by Bas Elbers – 3.1.9
Point of Sale for WooCommerce: by Actuality Extensions – 5.5.4
WooCommerce Table Rate Shipping: by WooCommerce – 3.0.38
WooCommerce: by Automattic – 6.4.1
Yoast SEO: by Team Yoast – 18.7
WP Crontrol: by John Blackbourn & crontributors – 1.12.1
WP REST Cache: by Acato – 2021.4.1
Perfect Images (Retina, Thumbnails, Replace): by Jordy Meow – 6.2.4

Inactive Plugins (4)

Maintenance: by WebFactory Ltd – 4.05
Newsletter: by Stefano Lissa & The Newsletter Team – 7.4.2
Password Protected: by Ben Huson – 2.5
PP Coupons: by Jens Buss – 1.0.0

Must Use Plugins (4)

Bedrock Autoloader: by Roots – 1.0.3
Disallow Indexing: by Roots – 1.0.0
Register Theme Directory: by Roots – 1.0.0
WP REST Cache - Must-Use Plugin: by Richard Korthuis - Acato – 2018.2.1

Settings

API Enabled: ✔
Force SSL: –
Currency: EUR (€)
Currency Position: right
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: #11 - /shop/
Cart: #70 - /cart/
Checkout: #71 - /checkout/
My account: #72 - /my-account/
Terms and conditions: #196 - /terms-conditions/

Theme

Name: Vue.wordpress
Version: 1.0.0
Author URL: https://github.com/bucky355
Child Theme: ❌ – If you are modifying WooCommerce on a parent theme that you did not build personally we recommend using a child theme. See: How to create a child theme
WooCommerce Support: ❌ Not declared

Templates

Overrides: –

Action Scheduler

Complete: 1,266
Oldest: 2022-04-07 12:32:11 +0200
Newest: 2022-05-06 07:22:34 +0200

CoCart

Version: 3.6.0
Database Version: 3.6.0
Install Date: March 25
2021

Carts in Session: 165
Carts Active: 164 out of 165 in session.
Carts Expiring Soon: 2 out of 165 in session.
Carts Expired: 1 out of 165 in session.
Carts Source (by CoCart): 153
Carts Source (by Web): 1
Carts Source (by Other): 11

Status report information

Generated at: 2022-05-06 09:24:07 +02:00
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
focus: products API This issue/PR is related to the products API. PHP: 8.0 Issues related to PHP 8.0 only. priority: low The issue/PR is low priority—not many people are affected or there’s a workaround, etc. status:changelog added Mark all PRs that have their changelog entries added to CHANGELOG.md status: in progress This is being worked on.
Projects
None yet
Development

No branches or pull requests

2 participants