0

I have the following problem: Inside of four different store views, we have the opportunity for the customer, to change between different assortments. This is basically just a filter in the Layered Navigation. It works pretty decent. Depending on which assortment the customer has chosen, the logo of the Order Email should change to the specific assortment.

But whatever I try to write a module OR plugin to override the Magento\Email\Model\AbstractTemplate -> getLogoUrl(), it just doesn't work. I know already, that it's a protected method and that a plugin won't work to override it. So I've tried to create a module which is overriding the whole method. Unfortunately the method is inside of an abstract class and it just doesn't work. Right now I am just trying to log into the debug log file. If I put the logging lines directly into the:

/var/www/vhosts/gildegruppe.com/dev/vendor/magento/module-email/Model/AbstractTemplate.php

it works and prints my test into the debug.log file. But if I create a:

<preference for="Magento\Email\Model\AbstractTemplate" type="VENDOR\MODULE\Model\Emaillogo" />

and the Emaillogo.php contains this:

<?php

namespace VENDOR\MODULE\Model;

class Emaillogo
{
  public function getLogoUrl($store)
  {
      $logger = \Magento\Framework\App\ObjectManager::getInstance()->get('\Psr\Log\LoggerInterface');
      $logger->info("TEST: Fake");

  // ...

it will compile, but there is no output in the debug.log. What am I missing here?

1

The preference mechanism doesn't work on abstract classes :)

When you have such a scenario, you should look for public methods that use the protected ones and alter the behavior there with a plugin. For example, in the class you mentioned, I found the method getProcessedTemplate() which uses the protected methods responsible with setting the logo - you could register a plugin and change the behavior by altering the $variables['logo_url'] content.

However, I would really consider checking whether such a solution is needed here. If you intend to use this globally or just in the order email template.

Also, if the assortments are pointing to the different store views, then you have and admin configuration which allows you to set the email logos per store view (admin -> Content -> Design -> Configuration -> Choose from the grid the line which has the storeview name populated in the 'Store View' column -> Click Edit -> then scroll to Transactional Email -> Logo Image -> Upload desired image). So basically no code needed, but this ofc, works if my initial assumption is correct (different assortments point to different storeviews).

2
  • Hey Diana :) Oh maybe there was some missunderstanding regarding the assortment. Within several store views, I have several assortments, based on the customer. So it's nothing out of the box and I couldn't just use the typical logo per store-view logic :) The problem is still persistent tho, even in the getProcessedTemplate. Direct inserted PHP works and prints logs, but not the overwritten part :( – Keenora Fluffball Feb 22 at 15:03
  • I see. so maybe you need to intervene to a higher (deeper?) level of the code before the template is even processed. I would suggest adding a debugger and breakpoints throughout the code when the email is sent or the method is invoked and work your way back from there. – Diana Botean Feb 22 at 15:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.