Replace tags of html template of cron job from the extension

Discussion in 'General discussions' started by test, May 15, 2019.

  1. test

    test New Member

    Joined:
    Nov 28, 2018
    Messages:
    2
    Likes Received:
    0
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    1
    We have extension and its task is to replace some tags in campaigns' templates to some images. It should work when we start CRON Job command send-campaign. And in time of this running, we should change our custom tag to image. But the main point is to change tags during cron job is running and to make some changes to the SendCampaignsCommand without changing core only somehow override it with our extension.
     
  2. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,169
    Likes Received:
    2,361
    @test = there are hooks in the send-campaigns command that helps you do this.
    There is "console_command_send_campaigns_before_send_to_subscriber" which gets triggered right before the email is sent to the subscriber, after the rest of the tags where parsed, so your email template at this point will only have your custom tag in it which is unparsed.
    You can connect to this filter like:
    PHP:
    Yii::app()->hooks->addFilter('console_command_send_campaigns_before_send_to_subscriber', function(
    $emailParams$campaign$subscriber$customer$server
    ){
        
    $emailParams['body'] = str_replace('[WHATEVER]''<img src=".."/>'$emailParams['body']);
        return 
    $emailParams;
    });
    if you open /apps/console/commands/SendCampaignsCommand.php and look for calls to:
    PHP:
    Yii::app()->hooks->applyFilters();
    You will see lots of hooks to which you can connect to from extensions.
     

Share This Page