bobbingwide / vgc

VGC - Garden Vista Group theme
GNU General Public License v2.0
0 stars 0 forks source link

Fatal error: Uncaught TypeError: number_format() #32

Open bobbingwide opened 2 years ago

bobbingwide commented 2 years ago

Found accidentally when visiting https://gvg.co.uk/store/swallow-robin-5-x-4-ft-greenhouse/#options_area Fatal error: Uncaught TypeError: number_format(): Argument #1 ($num) must be of type float, string given in C:\apache\htdocs\wordpress\wp-content\themes\vgc\inc\custom-woo-functions.php:845 Stack trace:

#0 C:\apache\htdocs\wordpress\wp-content\themes\vgc\inc\custom-woo-functions.php(845): number_format('', 2, '.', '')
#1 C:\apache\htdocs\wordpress\wp-content\themes\vgc\inc\custom-woo-functions.php(807): vgc_adjust_price('', NULL)
#2 C:\apache\htdocs\wordpress\wp-content\themes\vgc\template-parts\shop\addons-main.php(85): vgc_option_select('multi-single-ad...', Object(WC_Product_Simple), Array, NULL)
#3 C:\apache\htdocs\gardenvista\wp-includes\template.php(772): require('C:\\apache\\htdoc...')
#4 C:\apache\htdocs\gardenvista\wp-includes\template.php(716): load_template('C:\\apache\\htdoc...', false, Array)
#5 C:\apache\htdocs\gardenvista\wp-includes\general-template.php(204): locate_template(Array, true, false, Array)
#6 C:\apache\htdocs\wordpress\wp-content\themes\vgc\woocommerce\content-single-product.php(241): get_template_part('/template-parts...', 'main')
#7 C:\apache\htdocs\gardenvista\wp-includes\template.php(772): require('C:\\apache\\htdoc...')
#8 C:\apache\htdocs\gardenvista\wp-content\plugins\woocommerce\includes\wc-core-functions.php(284): load_template('C:\\apache\\htdoc...', false)
#9 C:\apache\htdocs\gardenvista\wp-content\plugins\woocommerce\templates\single-product.php(37): wc_get_template_part('content', 'single-product')
#10 C:\apache\htdocs\gardenvista\wp-includes\template-loader.php(106): include('C:\\apache\\htdoc...')
#11 C:\apache\htdocs\gardenvista\wp-blog-header.php(19): require_once('C:\\apache\\htdoc...')
#12 C:\apache\htdocs\gardenvista\index.php(17): require('C:\\apache\\htdoc...')
#13 {main}

thrown in C:\apache\htdocs\wordpress\wp-content\themes\vgc\inc\custom-woo-functions.php on line 845

bobbingwide commented 2 years ago

I believe this problem is caused by bad data. image

In the live site the last 3 options are displayed as 0 + £. Attempting to choose one of these options leads to a JavaScript problem showing a couple of numbers as NaN = Not a Number image

There's a slighty different problem for this product and the Sparrow Cold Frame.

bobbingwide commented 2 years ago

It's not enough to not Fatal when the option is invalid. If you add this option to the cart then it defers the Fatal when you choose the Add to cart button.

Fatal error: Uncaught TypeError: number_format(): Argument #1 ($num) must be of type float, string given in C:\apache\htdocs\wordpress\wp-content\themes\vgc\woocommerce\inc\classes\calculate-price.php:393 Stack trace: #0 C:\apache\htdocs\wordpress\wp-content\themes\vgc\woocommerce\inc\classes\calculate-price.php(393): number_format('', 2, '.', '') #1 C:\apache\htdocs\wordpress\wp-content\themes\vgc\woocommerce\inc\classes\calculate-price.php(105): calculate_price->adjust_price('') #2 C:\apache\htdocs\wordpress\wp-content\themes\vgc\woocommerce\inc\classes\calculate-price.php(62): calculate_price->calculatePrice() #3 C:\apache\htdocs\wordpress\wp-content\themes\vgc\inc\custom-woo-functions.php(80): calculate_price->__construct(Array, Array, '2696.00', '5.5', '4.5', 4452, '0', Object(WC_Product_Simple)) #4 C:\apache\htdocs\gardenvista\wp-includes\class-wp-hook.php(309): calculate_price_on_cart_addition(Array, 4452) #5 C:\apache\htdocs\gardenvista\wp-includes\plugin.php(189): WP_Hook->apply_filters(Array, Array) #6 C:\apache\htdocs\gardenvista\wp-content\plugins\woocommerce\includes\class-wc-cart.php(1138): apply_filters('woocommerce_add...', Array, 4452, 0, 1) #7 C:\apache\htdocs\gardenvista\wp-content\plugins\woocommerce\includes\class-wc-form-handler.php(824): WC_Cart->add_to_cart(4452, 1) #8 C:\apache\htdocs\gardenvista\wp-content\plugins\woocommerce\includes\class-wc-form-handler.php(796): WC_Form_Handler::add_to_cart_handler_simple(4452) #9 C:\apache\htdocs\gardenvista\wp-includes\class-wp-hook.php(307): WC_Form_Handler::add_to_cart_action('') #10 C:\apache\htdocs\gardenvista\wp-includes\class-wp-hook.php(331): WP_Hook->apply_filters(NULL, Array) #11 C:\apache\htdocs\gardenvista\wp-includes\plugin.php(474): WP_Hook->do_action(Array) #12 C:\apache\htdocs\gardenvista\wp-settings.php(609): do_action('wp_loaded') #13 C:\apache\htdocs\gardenvista\wp-config.php(93): require_once('C:\\apache\\htdoc...') #14 C:\apache\htdocs\gardenvista\wp-load.php(50): require_once('C:\\apache\\htdoc...') #15 C:\apache\htdocs\gardenvista\wp-blog-header.php(13): require_once('C:\\apache\\htdoc...') #16 C:\apache\htdocs\gardenvista\index.php(17): require('C:\\apache\\htdoc...') #17 {main} thrown in C:\apache\htdocs\wordpress\wp-content\themes\vgc\woocommerce\inc\classes\calculate-price.php on line 393
bobbingwide commented 2 years ago

There's a slighty different problem for this product and the Sparrow Cold Frame. Where option 3 appears as "0 + £0". HTML is <option value="0" data-price="0" data-addsize="">0 + £0</option>

When this is added to the cart all 6 of the options were added. The query parameter passed was [multi-single-addon-cold-frames:sparrow-cold-frame-34-x-45] => (string) "0"

This was a bug in the calculatePrice() method for multi- options.

bobbingwide commented 2 years ago

I resolved the problem with the Sparrow Cold Frame in development by removing the unwanted options. This issue can be closed when production also updated.

bobbingwide commented 10 months ago

There's still a problem when the product is added to the cart. If you choose any of the options with a label of 0, then when displayed in the cart all 3 of the options are shown as selected. The labels need to be unique within an option.

image

bobbingwide commented 10 months ago

See also https://github.com/bobbingwide/gardenvista/issues/29