woocommerce / woocommerce-square

Square POS and Payments Integration
https://woo.com/products/square
Other
11 stars 7 forks source link

Fatal error/warning Unsupported operand types: int * string in Digital_Wallet.php:462 #187

Closed helgatheviking closed 4 months ago

helgatheviking commented 4 months ago

Describe the bug

2024-07-25T01:04:53+00:00 Critical Uncaught TypeError: Unsupported operand types: int * string in /public_html/wp-content/plugins/woocommerce-square/includes/Gateway/Digital_Wallet.php:462  
Additional context
{
    "error": {
        "type": 1,
        "file": "/public_html/wp-content/plugins/woocommerce-square/includes/Gateway/Digital_Wallet.php",
        "line": 462
    },
    "backtrace": [
        "",
        "#0 /public_html/wp-content/plugins/woocommerce-square/includes/Gateway/Digital_Wallet.php(383): WooCommerce\Square\Gateway\Digital_Wallet->get_product_payment_request(11846)",
        "#1 /public_html/wp-content/plugins/woocommerce-square/includes/Gateway/Digital_Wallet.php(132): WooCommerce\Square\Gateway\Digital_Wallet->get_payment_request_for_context('product')",
        "#2 /public_html/wp-includes/class-wp-hook.php(324): WooCommerce\Square\Gateway\Digital_Wallet->init(Object(WP))",
        "#3 /public_html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array)",
        "#4 /public_html/wp-includes/plugin.php(565): WP_Hook->do_action(Array)",
        "#5 /public_html/wp-includes/class-wp.php(830): do_action_ref_array('wp', Array)",
        "#6 /public_html/wp-includes/functions.php(1336): WP->main('')",
        "#7 /public_html/wp-blog-header.php(16): wp()",
        "#8 /public_html/index.php(17): require('/home/dynamicwe...')",
        "#9 {main}",
        "thrown"
    ]
}

To reproduce

  1. Create a simple product
  2. enable NYP for that product
  3. do not add any prices or minimum prices
  4. save product and visit on front end

I'm not seeing this fatal error any longer (or am not sure how to reproduce, just relaying it from the customer's log). I do however, still see a warning pointing to the same line

Warning: A non-numeric value encountered in /public_html/wp-content/plugins/woocommerce-square/includes/Gateway/Digital_Wallet.php on line 462

The line in question

$amount         = number_format( $quantity * $product->get_price(), 2, '.', '' );

If I had to guess, $product->get_price() can be a null string if there's no minimum price set. (I'll have to go double check as I thought that I was setting the price to 0, both for sorting AND for math purposes like this). I don't really know what this code is responsible for, but as a name your price product, it technically doesn't have a price until the customer enters one.

Screenshots image

Environment (please complete the following information):

### WordPress Environment ###

WC Version: 9.1.2
Legacy REST API Package Version: ✔ 1.0.4
Action Scheduler Version: ✔ 3.7.4
Log Directory Writable: ✔
WP Version: 6.6.1
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: 7.4.33
PHP Post Max Size: 128 MB
PHP Time Limit: 300
PHP Max Input Vars: 1000
cURL Version: 7.61.1
OpenSSL/1.1.1k

Square 4.7.1

helgatheviking commented 4 months ago

Following up to add that I do set a product's price to be 0 when the minimum is a null string. So if I toggle NYP off and then back on again at their site, my save routine kicks in and 0 is saved as the regular price as intended. This resolves the warning (and I presume the fatal error as well).