List Unsubscribes adding to Customer Blacklist

Discussion in 'Extensions' started by Elliot Cater, Nov 15, 2017.

  1. Elliot Cater

    Elliot Cater Member

    Joined:
    Jul 19, 2016
    Messages:
    34
    Likes Received:
    1
    S.E:
    Expired
    L.T:
    Extended
    L.C:
    1
    Hi

    I'm wanting to add in the functionality to have anyone who unsubscribes from one of a customer's lists, also be added to that customer's blacklist.

    I thought about having a checkbox in the "Actions when unsubscribe" tab of "customer/lists" for this.

    I'm picking through:
    apps/customer/views/lists/form.php
    apps/customer/controllers/ListsController.php
    apps/common/models/Lists.php
    apps/frontend/controllers/ListsController.php


    I've added this code in the "tab-subscriber-action-when-unsubscribe" tab in form.php
    PHP:
    <div class="callout callout-info" style="margin-bottom: 5px; margin-top: 5px;">
      <?php echo Yii::t('lists''When a subscriber will unsubscribe from this list, add them to the customer blacklist');?>
    </div>
    <div class="row">
       <div class="col-lg-6">
          <div class="form-group">
             <?php echo $form->labelEx($list'blacklist_unsubscribers');?>
             <?php echo $form->dropDownList($list'blacklist_unsubscribers'$list->getYesNoOptions(),$list->getHtmlOptions('blacklist_unsubscribers')); ?>
             <?php echo $form->error($list'blacklist_unsubscribers');?>
          </div>
       </div>
    </div>
    I've added the "blacklist_unsubscribers" to the rules function in Lists.php model and I've added the new "blacklist_unsubscribers" field to the mw_lists table (as enum yes/no). The form now shows the error "Property "Lists.blacklist_unsubscribers" is not defined."

    I've been looking at the "welcome_email" property (as that is a similar field and in the same table) but I can't for the life of me see where it is defined...

    Any help would be greatly appreciated.

    Cheers

    Elliot
     
    Last edited: Nov 16, 2017
  2. Elliot Cater

    Elliot Cater Member

    Joined:
    Jul 19, 2016
    Messages:
    34
    Likes Received:
    1
    S.E:
    Expired
    L.T:
    Extended
    L.C:
    1
    Ok - I've cleared the cache folders and now yii has loaded the extra field!

    Next I'm going to change the frontend list controller to run the CustomerEmailBlacklist() function if the list is set to blacklist unsubscribers.

    Not sure how I can package this into an extension so I can upload it to my live system?
     
  3. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,267
    Likes Received:
    2,383
  4. Elliot Cater

    Elliot Cater Member

    Joined:
    Jul 19, 2016
    Messages:
    34
    Likes Received:
    1
    S.E:
    Expired
    L.T:
    Extended
    L.C:
    1
    Thanks, that's great :)

    I have downloaded the extension and studied it but I still need a few small things clarifying:

    The "beforeEnable" function - is this when the extension is installed but not enabled? So if I needed to add a field into the existing database table for the Lists model, this is where I'd do it?

    The "afterDelete" function - is this where I put the code to remove extra database fields and generally clean up anything else associated with the extension on delete?

    I'm also becoming unstuck trying to figure out how I get the extension to override the Lists model, view and controller so I can inject my stuff in there! At first I thought that I'd have to create my own model & controller that extends the original Lists model & controller but then how would they be used/called when a user unsubscribes or the customer activates this feature for their list? Is there a hook or something for that event?

    All I'm trying to achieve is it to add an new drop down menu in the Lists form view, have it update a field in the database and then every time someone unsubscribes have the actionUpdate function run CustomerBlacklistEmail().

    I've got it working by editing core files but the limits and paradigms of the extension system are just out of reach :(

    Cheers

    Elliot
     
  5. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,267
    Likes Received:
    2,383
    Yes, that's a good place to add fields to database.

    Yup.

    You can register your own controllers to be loaded before mailwizz's ones:
    Code:
    Yii::app()->controllerMap['list'] = array(
        'class'     => 'ext-YOUR-EXT-NAME.backend.controllers.MyListsController',
        'extension' => $this,
    );
    
    Then your MyListsController would extend the ListsController from mailwizz. See the landon frontend theme to see how we overwrite the default controller.

    Generally mailwizz has hooks in place that you can connect to so that you don't have to override full controllers/views/models/etc.
    If there's a place where you did changes because there was no hook to connect to, then we can add the hook so you can connect to it ;)
     
  6. Elliot Cater

    Elliot Cater Member

    Joined:
    Jul 19, 2016
    Messages:
    34
    Likes Received:
    1
    S.E:
    Expired
    L.T:
    Extended
    L.C:
    1
    Ah sweet! It's like someone is lifting the fog :D

    The extension system seems similar to Joomla's component system. I really enjoyed making components for Joomla, in fact there's actually online component creators that create a framework like Gii does.

    So the hook...
    Code:
    Yii::app()->hooks->doAction('frontend_lists_after_track_campaign_unsubscribe', $this, $track);
    Does that work for Direct Unsubscribes as well?

    Can't wait to get all this working Woo hoo!
     
  7. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,267
    Likes Received:
    2,383
    Not sure how that works, we're heavily inspired from wordpress's hooks system :D

    Yes, that's triggered for that too ;)
     
  8. Elliot Cater

    Elliot Cater Member

    Joined:
    Jul 19, 2016
    Messages:
    34
    Likes Received:
    1
    S.E:
    Expired
    L.T:
    Extended
    L.C:
    1
    Wow - that's great. So appreciative of all your help. If I would like to add the drop down yes, no switch in the tab-subscriber-action-when-unsubscribe tab-pane (in form.php), is that possible or will I be forced to put it where the hooks are (before_active_form_fields & after_active_form_fields)?

    I'd like to put it in the unsubscriber action tab, as it feels most relevant and OEM there but I suppose it isn't the end of the world if it can't be there.

    All the best

    Elliot
     
  9. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,267
    Likes Received:
    2,383
    The code looks like:
    Code:
    <div class="tab-pane" id="tab-subscriber-action-when-unsubscribe">
        <div class="callout callout-info" style="margin-bottom: 5px; margin-top: 5px;">
            <?php echo Yii::t('lists', 'When a subscriber will unsubscribe from this list, if he exists in any of the lists below, unsubscribe him from them too. Please note that the unsubscribe from the lists below is silent, no email is sent to the subscriber.');?>
        </div>
        <div class="row">
            <div class="col-lg-12">
                <div class="form-group">
                    <div class="list-subscriber-actions-scrollbox">
                        <ul class="list-group">
                            <?php echo CHtml::checkBoxList($listSubscriberAction->modelName . '['. ListSubscriberAction::ACTION_UNSUBSCRIBE .'][]', $selectedSubscriberActions[ListSubscriberAction::ACTION_UNSUBSCRIBE], $subscriberActionLists, $listSubscriberAction->getHtmlOptions('target_list_id', array(
                                'class'        => '',
                                'template'     => '<li class="list-group-item">{beginLabel}{input} <span>{labelTitle}</span> {endLabel}</li>',
                                'container'    => '',
                                'separator'    => '',
                                'labelOptions' => array('style' => 'margin-right: 10px;')
                            ))); ?>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    So where exactly you want your change to appear ?
     
  10. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,267
    Likes Received:
    2,383
    Here's an update, you can modify the tab-content div like:
    Code:
    <div class="tab-content">
        <div class="tab-pane active" id="tab-subscriber-action-when-subscribe">
            <div class="callout callout-info" style="margin-bottom: 5px; margin-top: 5px;">
                <?php echo Yii::t('lists', 'When a subscriber will subscribe into this list, if he exists in any of the lists below, unsubscribe him from them. Please note that the unsubscribe from the lists below is silent, no email is sent to the subscriber.');?>
            </div>
            <div class="row">
                <div class="col-lg-12">
                    <div class="form-group">
                        <?php $hooks->doAction('list_subscriber_actions_subscribe_action_before_html_display', $list); ?>
                        <div class="list-subscriber-actions-scrollbox">
                            <ul class="list-group">
                                <?php echo CHtml::checkBoxList($listSubscriberAction->modelName . '['. ListSubscriberAction::ACTION_SUBSCRIBE .'][]', $selectedSubscriberActions[ListSubscriberAction::ACTION_SUBSCRIBE], $subscriberActionLists, $listSubscriberAction->getHtmlOptions('target_list_id', array(
                                    'class'        => '',
                                    'template'     => '<li class="list-group-item">{beginLabel}{input} <span>{labelTitle}</span> {endLabel}</li>',
                                    'container'    => '',
                                    'separator'    => '',
                                    'labelOptions' => array('style' => 'margin-right: 10px;')
                                ))); ?>
                            </ul>
                        </div>
                        <?php $hooks->doAction('list_subscriber_actions_subscribe_action_after_html_display', $list); ?>
                    </div>
                </div>
            </div>
        </div>
        <div class="tab-pane" id="tab-subscriber-action-when-unsubscribe">
            <div class="callout callout-info" style="margin-bottom: 5px; margin-top: 5px;">
                <?php echo Yii::t('lists', 'When a subscriber will unsubscribe from this list, if he exists in any of the lists below, unsubscribe him from them too. Please note that the unsubscribe from the lists below is silent, no email is sent to the subscriber.');?>
            </div>
            <div class="row">
                <div class="col-lg-12">
                    <div class="form-group">
                        <?php $hooks->doAction('list_subscriber_actions_unsubscribe_action_before_html_display', $list); ?>
                        <div class="list-subscriber-actions-scrollbox">
                            <ul class="list-group">
                                <?php echo CHtml::checkBoxList($listSubscriberAction->modelName . '['. ListSubscriberAction::ACTION_UNSUBSCRIBE .'][]', $selectedSubscriberActions[ListSubscriberAction::ACTION_UNSUBSCRIBE], $subscriberActionLists, $listSubscriberAction->getHtmlOptions('target_list_id', array(
                                    'class'        => '',
                                    'template'     => '<li class="list-group-item">{beginLabel}{input} <span>{labelTitle}</span> {endLabel}</li>',
                                    'container'    => '',
                                    'separator'    => '',
                                    'labelOptions' => array('style' => 'margin-right: 10px;')
                                ))); ?>
                            </ul>
                        </div>
                        <?php $hooks->doAction('list_subscriber_actions_unsubscribe_action_after_html_display', $list); ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    And then hook into 'list_subscriber_actions_unsubscribe_action_before_html_display' and 'list_subscriber_actions_subscribe_action_before_html_display' and add your html, like:
    Code:
    Yii::app()->hooks->addAction('list_subscriber_actions_unsubscribe_action_before_html_display', function($list){
        echo '... your html ...';
    });
    
    Since i added the above hooks in the app, you'll be safe at upgrades too.
     
  11. Elliot Cater

    Elliot Cater Member

    Joined:
    Jul 19, 2016
    Messages:
    34
    Likes Received:
    1
    S.E:
    Expired
    L.T:
    Extended
    L.C:
    1
    Sorry - I couldn't reply, was in a very long soul destroying meeting - but after seeing these new hooks I'm now on top of the world!!

    Absolutely perfect, couldn't ask for more :)

    :D
     
  12. assuncao

    assuncao Member

    Joined:
    Aug 17, 2016
    Messages:
    55
    Likes Received:
    7
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    1
    Did you make this? I'm trying to do the same.
     
  13. Elliot Cater

    Elliot Cater Member

    Joined:
    Jul 19, 2016
    Messages:
    34
    Likes Received:
    1
    S.E:
    Expired
    L.T:
    Extended
    L.C:
    1
    Yes - if you upgrade to 1.5, I can send you an extension tomorrow morning that adds in the functionality.

    Merry Christmas

    Elliot
     
    assuncao likes this.
  14. assuncao

    assuncao Member

    Joined:
    Aug 17, 2016
    Messages:
    55
    Likes Received:
    7
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    1
    @Elliot Cater, yes, I really would like. Thank you very much! Happy New Year!
     
  15. reSh

    reSh New Member

    Joined:
    Oct 6, 2015
    Messages:
    8
    Likes Received:
    0
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    3
    Hello guys,

    i need this function too. How can i get the extension? Can i buy this or download it anywhere?

    Greets reSh
     
  16. Elliot Cater

    Elliot Cater Member

    Joined:
    Jul 19, 2016
    Messages:
    34
    Likes Received:
    1
    S.E:
    Expired
    L.T:
    Extended
    L.C:
    1
    Here we go - this should really be a core function in MW... Especially with the new GDPR (UK rules) coming into force now!
     

    Attached Files:

  17. Ricardo

    Ricardo New Member

    Joined:
    May 28, 2015
    Messages:
    15
    Likes Received:
    0
    S.E:
    Expired
    L.T:
    Extended
    L.C:
    1
    Does anyboy known if this work on Mailwizz v1.5.7 ? I needed that too.
    I create a trigger on mysql, I think it works too.

    CREATE TRIGGER `mw`.`mw_campaign_track_unsubscribe_BEFORE_INSERT` BEFORE INSERT ON `mw_campaign_track_unsubscribe`

    FOR EACH ROW
    BEGIN

    INSERT IGNORE INTO esend.mw_email_blacklist(email,reason,date_added,last_updated) select b.email,'UNSUBSCRIBED',now(),now() from mw_campaign_track_unsubscribe a join mw_list_subscriber b on NEW.subscriber_id = b.subscriber_id;

    END
     

Share This Page