sage-woocommerce
sage-woocommerce copied to clipboard
Fatal error: Uncaught Error: Maximum function nesting level of '200' reached, aborting!
Submit a feature request or bug report
- [x] I've read the guidelines for Contributing to Roots Projects
- [ ] This is a feature request
- [x] This is a bug report
- [x] This request isn't a duplicate of an existing issue
- [x] I've read the docs and NPM Debugging Guidelines post and followed them (if applicable)
- [x] This is not a personal support request that should be posted on the Roots Discourse forums
What is the current behavior?
Installing version 1.0.2 with the new action 'woocommerce_before_template_part' leads to the php error Fatal error: Uncaught Error: Maximum function nesting level of '200' reached, aborting!
What might be the solution?
I'm wondering if the additional add_action is needed. In my current setup I included the passing of $data diretly into add_filter('template_include', ...):
add_filter('template_include', function ($template) {
$overwrites = ['single-product', 'archive-product', 'taxonomy-product_cat', 'taxonomy-product_tag'];
if ( ($key = array_search( basename($template, ".php"), $overwrites)) !== FALSE ) {
$blade_file = locate_template( WC()->template_path() . $overwrites[$key] );
}
$template = !empty($blade_file) ? $blade_file : $template;
$data = collect( get_body_class() )->reduce( function ( $data, $class ) use ( $template ) { //use body class to get correct controller data
return apply_filters( "sage/template/{$class}/data", $data, $template ); //get data from controller
}, [] );
if ( $template ) {
echo template( $template, $data );
return get_stylesheet_directory() . '/index.php';
}
return locate_template( 'woocommerce' );
}, 100);
I'm currently not sure whether this has the same result, but maybe it's useful.
Best
Thanks for reporting, @ouun. Can you provide any more details on when this occurs to help us track down the issue? I spun up a very, very simple test site with the WooCommerce sample data and overrode single-product.php and didn't hit the error. @mejta may have better insight into this, as well.
Hi @ouun, I've tried to replicate the issue, but with no success. I have a setup with more than 20 templates overwritten and I cannot run into the issue. It would be helpful if you provide full error/exception and piece of code that demonstrates the issue. Thank you.
@mmirus & @mejta thanks for your replies. I’ll follow up next week with some more details as I currently don’t have access to my computer.
@ouun Any news on this issue?
@mmirus I suggest closing this issue. No reply from author and I cannot reproduce it.
Dear @mejta & @mmirus ,
I have to apologize for never answering. I had to pause the project and just started to follow up and came to this again as I still face the same issue: Fatal error: Uncaught Error: Maximum function nesting level of '200' reached, aborting! in/current/web/wp/wp-includes/functions.php:6090. I'm using the full roots stack here with Trellis, Bedrock & Sage and I'm on local dev env.
The error is thrown by "xdebug" and I already changed the xdebug_max_nesting_levelup to 500. However now I get a "502" or Fatal error: Allowed memory size of 100663296 bytes exhaustederror.
So far I do not understand why the data collection within 'woocommerce_before_template_part' results in the mentioned errors, but using an empty array instead of the following solves it:
$data = collect( get_body_class() )->reduce( function ( $data, $class ) use ( $theme_template ) { //use body class to get correct controller data apply_filters( "sage/template/{$class}/data", $data, $theme_template ); }, [] );
I also tried to set all available classes directly into the filter one by one. E.g. on a single product page I have the following body classes:
product-template-default single single-product postid-33 logged-in admin-bar no-customize-support custom-background woocommerce woocommerce-page woocommerce-no-js v-neck-t-shirt app-data index-data singular-data single-data single-product-data single-product-v-neck-t-shirt-data debug-bar-maximized
I just hardcoded them one by one to the data filter such as for app-data
apply_filters("sage/template/app-data/data", $data) to find out that I had two Conrollers making trouble:
1.) For the class 'index-data' while the Controller template for SingleIndex.php is the untouched example from sage repo.
2.) For 'single-product-data' as the Controller file included a function which was finally repeating itself when called for template parts.
I fixed both but still wonder whether it is not possible to just pass the same $data to all template parts without collecting them again and again.
Best regards,
Philipp
Currently I try to understand the usecase and benefit Not sure that I can follow the logic here but the $data object should be already available from loading the main template. I guess that this is used to make the $data also availabe
Hey @ouun - sorry for the slow response here. I don't have the bandwidth to troubleshoot right now, especially with Sage 10 on the way, but I'm going to reopen this issue so that it's visible down the road. Thanks for sharing the additional info.
@mmirus thanks for your kind folow up. I'm following the github repo and with that the Sage 10 development with very high interest. Go for it, please!
Another note to add to my previous comment: Using Trellis I faced the Error: Maximum function nesting level of '{ A NUMBER}' reached, aborting! later again and solved it using higher nginx_fastcgi_buffers and nginx_fastcgi_buffer_size in the NGINX config. So far it helps and even reduced the single page load time in the local env from >10s to <5s.
As I'm on a Multisite (& Multi-Network) environment not only running with WooCommerce I assume that the default value is simply to low in the Trellis NGINX settings.
I am facing same issue, Any solution?
I am facing same issue, Any solution?
I switched to Sage 10 and built my own integration: https://github.com/ouun/stage-woocommerce For Sage 9 it is too long ago and I can't remember how I continued. Sorry.