Sage9 WooCommerce: sage/template/{$class}/data called on each template load

Each time a woocommerce template is loaded, all sage/template/{$class}/data filters get executed.

This affects also public non static methods of controllers as documented in this issue:

<?php

namespace App\Controllers;

use Sober\Controller\Controller;

class TaxonomyProduct_cat extends Controller
{
	public function test()
	{
		echo 'a';
		return '';
	}
}

It seems related to woocommerce_before_template_part action.

Is there a fix or workaround for this?
Does Sage 10, and maybe this PR solve the issue?

Can’t speak on the PR or Woocommerce in particular – but no, Sage 10 does not have this issue.

I successfully update to Sage 10 using also the mentioned fork of sage-woocommerce.

Unfortunately I still have issues with some Composers get instantiated on each template.

class App extends Composer
{
    protected static $views = [
        '*',
    ];

    public function __construct()
    {
        var_dump('App');
    }
}

I’d like to compute some data just once and share to every child template.
I can restrict the App Composer $views to just the main template like this:

protected static $views = [
        'layouts.app',
    ];

Is this the right way?

This topic was automatically closed after 42 days. New replies are no longer allowed.