mindkomm / timber-integration-woocommerce

WooCommerce integration for Timber
MIT License
109 stars 20 forks source link

Fatal Error / Warning on single product #24

Closed langhenet closed 1 year ago

langhenet commented 3 years ago

Hi!

I'm testing out this integration (I like the way it allows you to use twig partials intead of overriding the complete wc templates!) but I'm fighting against a couple of issues...

  1. in the docs it says that the use of the woocommerce.php is optional, but if I don't create one, the single product will throw a fatal error
Fatal error: Uncaught Error: Call to a member function is_on_sale() on string
in P:\glocal\dev_clienti\wp-content\plugins\woocommerce\templates\single-product\sale-flash.php on line 25

Call Stack:

include()
wp-content/plugins/woocommerce/includes/wc-core-functions.php:345
wc_get_template()
wp-content/plugins/woocommerce/includes/wc-template-functions.php:1609
woocommerce_show_product_sale_flash()
wp-includes/class-wp-hook.php:292
WP_Hook::apply_filters()
wp-includes/class-wp-hook.php:316
WP_Hook::do_action()
wp-includes/plugin.php:484
do_action()
wp-content/plugins/woocommerce/templates/content-single-product.php:43
require()
wp-includes/template.php:732
load_template()
wp-content/plugins/woocommerce/includes/wc-core-functions.php:284
wc_get_template_part()
wp-content/plugins/woocommerce/templates/single-product.php:37
include()
wp-includes/template-loader.php:106
require_once()
wp-blog-header.php:19
require()
index.php:17
  1. if I do create the file (with the render_default_template call), when the single product has some content in it, it will throw a warning (and a notice), and content is not displayed in the tab:
Warning | count(): Parameter must be an array or an object that implements Countable in wp-includes/post-template.php:319 | Plugin: woocommerce
Notice | Trying to access array offset on value of type null in wp-includes/post-template.php:325 | Plugin: woocommerce

I'm on the latest wc (5.5.1).

I've tried the integration with my theme, but also with the Timber starter, facing the same 2 issues.

Any help / advice would be much appreciated :-)

Thanks!

langhenet commented 3 years ago

If it's of more help, here's the call stack for the warning

wp-includes/post-template.php:319
get_the_content()
wp-includes/post-template.php:244
the_content()
wp-content/plugins/woocommerce/templates/single-product/tabs/description.php:30
wc_get_template()
wp-content/plugins/woocommerce/includes/wc-template-functions.php:1761
woocommerce_product_description_tab()
wp-content/plugins/woocommerce/templates/single-product/tabs/tabs.php:47
wc_get_template()
wp-content/plugins/woocommerce/includes/wc-template-functions.php:1544
woocommerce_output_product_data_tabs()
wp-includes/class-wp-hook.php:303
do_action_ref_array('woocommerce_after_single_product_summary')
wp-content/themes/timber-starter/vendor/mindkomm/timber-integration-woocommerce/lib/WooCommerce.php:456
Timber\I\W\WooCommerce->Timber\I\W\{closure}()
wp-content/themes/timber-starter/vendor/twig/twig/src/Environment.php(418) : eval()'d code:85
__TwigTemplate_934fcef5ad4a9993bf1d6c9dd28107bc312d6cebf476eeabaa3ecdb3882c3c66->block_content()
wp-content/themes/timber-starter/vendor/twig/twig/src/Template.php:182
Twig\Template->displayBlock()
wp-content/themes/timber-starter/vendor/twig/twig/src/Environment.php(418) : eval()'d code:74
__TwigTemplate_c2ef67348d5d5901ac42b05ad9304639da94daece14209cb091911200dd934e3->doDisplay()
wp-content/themes/timber-starter/vendor/twig/twig/src/Template.php:405
Twig\Template->displayWithErrorHandling()
wp-content/themes/timber-starter/vendor/twig/twig/src/Template.php:378
Twig\Template->display()
wp-content/themes/timber-starter/vendor/twig/twig/src/Environment.php(418) : eval()'d code:42
__TwigTemplate_934fcef5ad4a9993bf1d6c9dd28107bc312d6cebf476eeabaa3ecdb3882c3c66->doDisplay()
wp-content/themes/timber-starter/vendor/twig/twig/src/Template.php:405
Twig\Template->displayWithErrorHandling()
wp-content/themes/timber-starter/vendor/twig/twig/src/Template.php:378
Twig\Template->display()
wp-content/themes/timber-starter/vendor/twig/twig/src/Template.php:390
Twig\Template->render()
wp-content/themes/timber-starter/vendor/twig/twig/src/TemplateWrapper.php:45
Twig\TemplateWrapper->render()
wp-content/themes/timber-starter/vendor/timber/timber/lib/Loader.php:79
Timber\Loader->render()
wp-content/themes/timber-starter/vendor/timber/timber/lib/Timber.php:334
Timber\Timber::compile()
wp-content/themes/timber-starter/vendor/timber/timber/lib/Timber.php:383
Timber\Timber::fetch()
wp-content/themes/timber-starter/vendor/timber/timber/lib/Timber.php:410
Timber\Timber::render()
wp-content/themes/timber-starter/vendor/mindkomm/timber-integration-woocommerce/lib/WooCommerce.php:404
Timber\I\W\WooCommerce::render_default_template()
wp-content/themes/timber-starter/woocommerce.php:8
gchtr commented 3 years ago

Hey @langhenet

Thanks for checking out the integration and for taking the time to fill out an issue with an error call stack!

I could reproduce your issues and I think I found the solution for both your problems. I added it in a pre-release in 0.6.1-rc.1, because I want to test it out a bit more myself. I’d be glad if you could check it out and tell me whether it’s working now.

composer require mindkomm/timber-integration-woocommerce:0.6.1-rc.1
langhenet commented 3 years ago

Hi @gchtr, sorry for the delay in my answer, I missed the notification.

First of all thanks for your answer :-) I've tried with the new RC.

Apparently it solves the fatal on single when there is no woocommerce.php.

Without the woocommerce.php file, woocommerce will use the twig partials in the views/woocommerce/ folder, but not for the single product, which, I guess, is the right behaviour according to the updated documentation in the RC, correct?

When woocommerce.php is present, it still throws the notice, but I've found a workaround by adding a single-product/tab/description.twig file with

{% set heading = __('Description', 'woocommerce')
    |apply_filters('woocommerce_product_description_heading')
    |e('esc_html')
%}

{% if heading %}
    <h2>{{ heading }}</h2>
{% endif %}

{{ post.content }}

which prevents the notice :-)


I'm not a PHP wizard but i'd like to contribute to this repository in any way possible...

gchtr commented 3 years ago

Without the woocommerce.php file, woocommerce will use the twig partials in the views/woocommerce/ folder, but not for the single product, which, I guess, is the right behaviour according to the updated documentation in the RC, correct?

Yes, that’s correct. At least for the moment. Maybe I can optimize that in the future.

I think I’m having a hard time reproducing your issue.

Can you tell me what WooCommerce-related template files (both PHP and Twig) you have in your theme?

Do you have any WooCommerce PHP template files other than woocommerce.php? And do you a have Twig file for the singular product view (views/woocommerce/single.twig or views/woocommerce/single-product.twig)?

gchtr commented 1 year ago

I finally stumbled into the same issue as you and found a solution that should work. See the latest 0.7.1 release: https://github.com/mindkomm/timber-integration-woocommerce/releases/tag/0.7.1.