Closed dmschlot closed 1 year ago
Hey @dmschlot, thanks for that detailed issue report. And thanks for the kind words! I’m glad you like it. I couldn’t work without it, either 😅.
I was just wondering, did you already check out the newest release candidate for this integration? Because it might be that is already resolved with that. You should be able to get it with
composer require mindkomm/timber-integration-woocommerce:0.6.0-rc.1
Otherwise, I might have to check again.
@gchtr sorry for the slow response. I just confirmed that yes I was running 0.6.0-rc.1 at the time I wrote the above comment. Also looking at https://github.com/mindkomm/timber-integration-woocommerce/blob/0.6.0/lib/WooCommerce.php I do still see the issue. Line 250 of this file needs to be changed from
if ( ! $product ) {
to
if ( ! $product || $product->get_id() != $post->ID ) {
Thanks, David
Hey @dmschlot
Sorry for the delay and thanks for checking it out and digging into the code to find a solution. Your suggestion was a big hint for what was not working.
However, I realized there are various other problems about the $product
global. Adding your suggestion would be a band-aid for a couple of these problems, but wouldn’t solve the underyling issue. I think I found a fix for a better $product
global handling in https://github.com/mindkomm/timber-integration-woocommerce/commit/e1cc8b2a74dcb5049a787a1ec39ed0dffd7e81d4.
I added the solution as 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.
composer require mindkomm/timber-integration-woocommerce:0.6.1-rc.1
Hi @gchtr chiming in on this issue as well :-)
I'm facing the same issue as @dmschlot (to me it happens also on normal archive pages, not only with the shortcode), and his workaround works for me.
Closing this. Please use the latest 0.7.1 release.
Please open a new issue if you run into other problems.
Problem I am using the 'products' shortcode provided by WooCommerce. This executes class-wc-shortcode-products.php's product_loop(). This code sets the $GLOBALS['post'] but not $GLOBALS['product']. Because of this, and other code, the loop of products prints the same product over and over again (to be more specific, name of product is correct but image and price is from the first product).
It seems the code at the bottom of https://timber.github.io/docs/guides/woocommerce/ attempts to resolve but did not work for me.
Solution Looking into I found this library's WooComerce.php maybe_render_twig_template_part() contains
The above sets the global $product when $product not yet set. This then leads to the global 'product' to always be the first one in a loop. To resolve the condition in the 'if' needs to be changed to:
Your library is fantastic! I love using Twig so its a must when doing WooCommerce. Your library makes it so much easier. If you can please resolve the above that would be AWESOME!
Thanks, David