magento2 – Plugin beforeGetUrl to modifiy links for Catalog Products

I have grouped products “containing” simple products. I have had to make the simple products visible but while I am ok for them to appear in certain lists, I want the link to go to the parent page not to the (very incomplete) simple product page.

I started by creating a helper with a new URL function and overriding the various templates to use it , but there are a lot of templates and it will be a pain to maintain.

It seems to always be $product->getUrlModel()->getUrl($product, $additional) behind all the getProductUrl so CatalogModelProductUrl I should be able to create a “before” plugin for getUrl that swaps to the parent when it detects particular conditions.

But it seems my plugin is not happening – even when I just make it log a line then pass on things unchanged. So either I am missing an understanding or it is another class that cannot be modified?

In app/code/Mystuff/FixGrouped/etc/frontend/di.xml

<type name="CatalogModelProductUrl">
    <plugin sortOrder="1" name="FixGroupedPluginModelProductUrl" 
     type="MystuffFixGroupedPluginModelProductUrl" disabled="false" />
</type>

and in app/code/Mystuff/FixGrouped/Plugin/Model/Product/Url.php

namespace MystuffFixGroupedPluginModelProduct;

use MagentoCatalogModelProductUrl;

class Url 
{
       public function beforeGetUrl(MagentoCatalogModelProductUrl $subject, MagentoCatalogModelProduct $product, array $params)
     {
          $logger = MagentoFrameworkAppObjectManager::getInstance()->get(PsrLogLoggerInterface::class);
          $logger->info('Mystuff plugin beforeGetUrl active');
          // here it would swap for parent if require
          return ($product, $params);
    }

}

So it changes nothing but puts a line in the log. No lines ever appear in the log.

So what am I missing?
– i’ve not written it right?
– getUrl is not called in a context that works with plugin?

I couldnt find any beforeGetUrl on this class out there so it is not reassuring