mindkomm / timber-integration-woocommerce

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

Custom context not passed to default template render function #21

Closed edwardjosephbennett closed 3 years ago

edwardjosephbennett commented 3 years ago

Hi,

Not sure if this is intentional or not, but I think I've noticed a bug in the way the default template plugin renders templates.

In order to take full advantage of using this plugin I have been using:

\Timber\Integrations\WooCommerce\WooCommerce::render_default_template();

in my woocommerce.php file so that I get the recommended files. I have noticed though, that when using this function, that any custom context that I have defined within the woocommerce.php file is not pulled into this function, even though the context is defined at the top of your function using $context = Timber::get_context();.

Steps to reproduce:

Potential fix:

Add a variable to pass into the function, and then check if it's been passed in and merge the two together.

    public static function render_default_template($customContext = array()) {
        $context = Timber::get_context();

        if(!empty($customContext)) {
            $context = array_merge($context, $customContext);
        }

If this is intentional, then please ignore me 😄 If not, happy to introduce a PR to fix.

Thanks, Ed

gchtr commented 3 years ago

Do you mean like here?

https://github.com/mindkomm/timber-integration-woocommerce/blob/72a724bfa238e75f5371c8464957a14d4b1dde58/lib/WooCommerce.php#L352-L353

This is in the latest release candidate.

(I still have to check one thing or two before I can make an official release, but I hope to get that out soon.)

edwardjosephbennett commented 3 years ago

Ahhh perfect! I didn't think to check the latest releases 👍 Is that pre-release safe to use even though it's not got an official release yet?

gchtr commented 3 years ago

Sorry for the late reply! I usually make a pre-release to use it in our client projects and see whether everything works out fine before releasing an official version. I’d say those pre-releases are pretty safe to use.

I just released version 0.6.0. You can update the integration with

composer update mindkomm/timber-integration-woocommerce