Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Mailchimp newsletter Everywhere add on


Recommended Posts

@Gyakutsuki

ok, I will, thanks.

In testing the features of this addon, I found a minor issue that's an easy fix. When the option for "subscribed" is selected in Admin > Modules > Header Tags > Newsletter Mailchimp V3, and an email is submitted, the success message is the same as for "pending" which says that the customer is to "..click the confirmation link that will be emailed to you shortly." However with that "subscribed" option there is nothing emailed to the customer to verify their opt-in.

I've only installed and am testing on the footer module.

osCommerce: made for programmers, ...because store owners do not want to be programmers.

https://trends.google.com/trends/explore?date=all&geo=US&q=oscommerce

Link to comment
Share on other sites

I will look when I have the time and if the BS works with php 7.1.  It was not the case when this contribution was wroten


Regards
-----------------------------------------
Loïc

Contact me by skype for business
Contact me @gyakutsuki for an answer on the forum

 

Link to comment
Share on other sites

@Gyakutsuki

Loic,

The add-on works with PHP 7.1.7 ...that's what I am running the BS Edge on.

The fix for the message issue is:

1) /includes/languages/english/modules/header_tags/ht_mailchimp.php ADD the following two definitions:

  define('MODULES_HEADER_TAGS_MAILCHIMP_SUCCESS_MESSAGE_PENDING', 'Success!  Please click the confirmation link that will be emailed to you shortly.');
  define('MODULES_HEADER_TAGS_MAILCHIMP_SUCCESS_MESSAGE_SUBSCRIBED', 'Success!  Your information was submitted.');

 

2a) /includes/modules/header_tags/ht_mailchimp.php FIND the following code (on line 57):

    function execute() {
      global $oscTemplate;
	  

ADD just below it:

	  $email_optin_success = (MODULES_HEADER_TAGS_MAILCHIMP_STATUS_CHOICE == 'pending' ? MODULES_HEADER_TAGS_MAILCHIMP_SUCCESS_MESSAGE_PENDING : MODULES_HEADER_TAGS_MAILCHIMP_SUCCESS_MESSAGE_SUBSCRIBED);

 

2b) in the same file FIND both instances of:

MODULES_HEADER_TAGS_MAILCHIMP_SUCCESS_MESSAGE

and REPLACE them with:

$email_optin_success

 

 

Edited by Demitry

osCommerce: made for programmers, ...because store owners do not want to be programmers.

https://trends.google.com/trends/explore?date=all&geo=US&q=oscommerce

Link to comment
Share on other sites

I found another minor error. The footer template id names are ending with "hd" for header instead of "ft" for footer. All except the email field.

What this does is, ...it does not clear the text fields after the contact info was submitted.

 

osCommerce: made for programmers, ...because store owners do not want to be programmers.

https://trends.google.com/trends/explore?date=all&geo=US&q=oscommerce

Link to comment
Share on other sites

Hey,.. just to follow up...

From my prior post, ..those were arrays and though the module works with the current /exe/api/mailchimp_v3/subscribe.php file, this is the way this file should look.

 

<?php
/**
 * Gyakutsuki
 * subscribe.php
 * @copyright Copyright 2016
 * @copyright Portions Copyright osCommerce
 * @license GNU Public License V2.0
 * @version $Id:
 */

  chdir('../../../');

  require('includes/application_top.php');

  include('ext/api/mailchimp_v3/MailChimp.php');

  $key = MODULES_HEADER_TAGS_MAILCHIMP_API;

  if (isset($_POST['anonymous'])) {
    $list_id = MODULES_HEADER_TAGS_MAILCHIMP_LIST_ANONYMOUS;
	
    $merge_vars = array('FNAME' => '',
                        'LNAME' => '');

  } else {
    $list_id = MODULES_HEADER_TAGS_MAILCHIMP_LIST_CUSTOMERS;

    $merge_vars = array('FNAME' => $_POST['firstname'],
                        'LNAME' => $_POST['lastname']);
				  
  }
			
  $array = array('email_address' => $_POST['email'],
                 'merge_fields'  => $merge_vars,
                 'status'        => MODULES_HEADER_TAGS_MAILCHIMP_STATUS_CHOICE);


  if (MODULES_HEADER_TAGS_MAILCHIMP_STATUS_CHOICE == 'pending') {
    $status = 'pending';
  } else {
    $status = 'subscribed';
  }

  $MailChimp = new \MailChimp($key);

// add the email to your list
  $result = $MailChimp->post('/lists/' . $list_id . '/members', $array);

//send
  $result = json_encode($result);

// If being called via ajax, run the function, else fail - console
  if ( MODULES_HEADER_TAGS_MAILCHIMP_DEBUG == 'True') {
    if ($_POST['ajax']) {
      var_dump($result); // send the response back
    } else {
      var_dump('Method not allowed - please ensure JavaScript is enabled in this browser');
    }
  } else {
    echo $result;
  }

 

I added spam bot-trap with my version and it works great!! Love this module!

Demitry

 

osCommerce: made for programmers, ...because store owners do not want to be programmers.

https://trends.google.com/trends/explore?date=all&amp;geo=US&amp;q=oscommerce

Link to comment
Share on other sites

@Demitry

Happy you like, you can share what you made with the spam bot-trap, some people can be interested.

Edited by Gyakutsuki


Regards
-----------------------------------------
Loïc

Contact me by skype for business
Contact me @gyakutsuki for an answer on the forum

 

Link to comment
Share on other sites

Spam Bot Trap

Ok, so there are a number of different solutions to use for blocking spam bots from submitting garbage emails to your opt-in form, but the one I decided on was the bait-trap type. That entails creating a couple of fields that spam bots cannot resist,.. then hiding these fields from the human user using CSS.

I then set up a conditional statement to filter the human user submissions from those of bots. The human submissions are added to the Mailchimp list and the bot submissions end up in the abyss of the digital world of 0’s and 1’s.

All that, and a fake success message to reinforce the bot that their spam submission was actually added to the site’s email list. Don’t think that today’s bots need a confirmation message? ..never underestimate technology. Today’s spiders & bots are much more sophisticated and can determine when their submission was rejected. And that, may initiate a more sophisticated attempt at submitting spam data.

I chose to use two types of fields (though one would likely be enough) and some tasty keywords that spam bots cannot help but salivate over.

This spam bot trap install includes my instructions from a prior post on this forum thread that differentiates the customer success message via the store owner selecting to automatically add that submitted email to the list OR requiring a 2nd tier approval opt-in emailed to the end user. If you choose “pending” for that 2nd tier approval opt-in emailed to the end user, then you likely don’t need this spam bot trap. However, the more hoops you have a customer jump through, the less opt-ins you’ll have.

The install instructions here are for the BS Edge footer module, however, the code changes are made to support the BS Edge header module as well. To add this to the header module you will need to make additional changes to the header module template (similar to those of the footer module template). I only tested this on the footer module and chose that one because I prefer to have this email opt-in in the footer on my site.

The following 5 files will require changes. Be sure to BACK-UP your site files before making ANY changes to your site.

1) /includes/languages/english/modules/header_tags/ht_mailchimp.php
FIND this line:

  define('MODULES_HEADER_TAGS_MAILCHIMP_SUCCESS_MESSAGE', 'Success!  Please click the confirmation link that will be emailed to you shortly.');

REPLACE it with this:

  define('MODULES_HEADER_TAGS_MAILCHIMP_SUCCESS_MESSAGE_PENDING', 'Success!  Please click the confirmation link that will be emailed to you shortly.');
  define('MODULES_HEADER_TAGS_MAILCHIMP_SUCCESS_MESSAGE_SUBSCRIBED', 'Success!  Your information was submitted.');
  define('MODULES_HEADER_TAGS_MAILCHIMP_SUCCESS_MESSAGE', 'Success!  Your contact information was submitted.');

Note: To make testing easier, I made the success message slightly different for MODULES_HEADER_TAGS_MAILCHIMP_SUCCESS_MESSAGE than that of the .. _SUBSCRIBED message.

 

2) /includes /modules/header_tags/ht_mailchimp.php
    a) FIND this code:

    function execute() {
      global $oscTemplate;
	  

ADD just after it:

	  $email_optin_success = (MODULES_HEADER_TAGS_MAILCHIMP_STATUS_CHOICE == 'pending' ? MODULES_HEADER_TAGS_MAILCHIMP_SUCCESS_MESSAGE_PENDING : MODULES_HEADER_TAGS_MAILCHIMP_SUCCESS_MESSAGE_SUBSCRIBED);
	  
	  // fake success message for bot opt-ins
	  if (isset($_POST['url']) && $_POST['url'] == '' && !isset($_POST['terms_of_use'])) {
		  $alert_type = 'danger';
		  $alert_msg = MODULES_HEADER_TAGS_MAILCHIMP_ERROR_MESSAGE;
	  } else {
		  $alert_type = 'success';
		  $alert_msg = MODULES_HEADER_TAGS_MAILCHIMP_SUCCESS_MESSAGE;
	  }
	  

 

    b) FIND BOTH instances of this:

MODULES_HEADER_TAGS_MAILCHIMP_SUCCESS_MESSAGE

REPLACE them with this:

$email_optin_success

 

    c) FIND BOTH instances of this:

          resultmessage = \'<div class="alert alert-danger alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>' . MODULES_HEADER_TAGS_MAILCHIMP_ERROR_MESSAGE . '</div>\'; // display the message

REPLACE them with this:

          resultmessage = \'<div class="alert alert-' . $alert_type . ' alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>' . $alert_msg . '</div>\'; // display the message

 

    d) FIND BOTH instances of this:

        $(\'#messagehd\').html(resultmessage); // display the message
        $(\'#fnamehd\').val(""); // reset input field
        $(\'#lnamehd\').val(""); // reset input field
        $(\'#emailhd\').val(""); // reset input field

REPLACE them with this:

        $(\'#messageft\').html(resultmessage); // display the message
        $(\'#fnameft\').val(""); // reset input field
        $(\'#lnameft\').val(""); // reset input field
        $(\'#urlft\').val(""); // reset input field
        $(\'#emailft\').val(""); // reset input field

 

3) /includes /modules/content/footer/templates/footer_mailchimp.php
FIND this code:

<?php
    echo $form;
    if (!empty(MODULES_HEADER_TAGS_MAILCHIMP_LIST_CUSTOMERS) && (MODULE_FOOTER_MAILCHIMP_DISPLAY_NAME == 'True')) {
      echo tep_draw_input_field('firstname', NULL, 'id="fnamehd" placeholder="' . MODULE_FOOTER_MAILCHIMP_OPTIONAL . ENTRY_FIRST_NAME . '"') . ' ';
      echo tep_draw_input_field('lastname', NULL, 'id="lnamehd" placeholder="' . MODULE_FOOTER_MAILCHIMP_OPTIONAL . ENTRY_LAST_NAME . '"') . ' ';
      echo tep_draw_input_field('email', NULL, 'required aria-required="true" id="emailft" placeholder="' . ENTRY_EMAIL_ADDRESS . '"', 'email') . ' ';
      echo tep_draw_button(MODULE_FOOTER_MAILCHIMP_SUBMIT, 'fa fa-pencil-square-o', null, null, array('params' => 'id="SendButtonft"'), 'btn-success btn-sm');
    } elseif (!empty(MODULES_HEADER_TAGS_MAILCHIMP_LIST_ANONYMOUS)) {
      echo tep_draw_input_field('email', NULL, 'required aria-required="true" id="emailft" placeholder="' . ENTRY_EMAIL_ADDRESS . '"', 'email') . ' ';
      echo tep_draw_button(MODULE_FOOTER_MAILCHIMP_SUBMIT, 'fa fa-pencil-square-o', null, null, array('params' => 'id="SendButtonft"'), 'btn-success btn-sm') . tep_draw_hidden_field('anonymous', 'anonymous');
    }
    if (MODULE_FOOTER_MAILCHIMP_DISPLAY_PRIVACY == 'True') {
      echo tep_draw_button(MODULE_FOOTER_MAILCHIMP_PRIVACY, 'fa fa-user', tep_href_link('privacy.php'), null, null, 'btn-info btn-xs pull-right');
    }
    echo $endform;
    echo '<br><div class="message" id="messageft"></div>';
?>

REPLACE it with this:

<?php
    echo $form;
    if ((MODULES_HEADER_TAGS_MAILCHIMP_LIST_CUSTOMERS != '') && (MODULE_FOOTER_MAILCHIMP_DISPLAY_NAME == 'True')) {
      echo '<span class="website-url">Website URL:<br /><input type="text" name="url" id="urlft" placeholder="Website URL" /></span>';
      echo tep_draw_input_field('firstname', NULL, 'id="fnameft" placeholder="' . MODULE_FOOTER_MAILCHIMP_OPTIONAL . ENTRY_FIRST_NAME . '"') . ' ';
      echo tep_draw_input_field('lastname', NULL, 'id="lnameft" placeholder="' . MODULE_FOOTER_MAILCHIMP_OPTIONAL . ENTRY_LAST_NAME . '"') . ' ';
      echo tep_draw_input_field('email', NULL, 'required aria-required="true" id="emailft" placeholder="' . ENTRY_EMAIL_ADDRESS . '"', 'email') . ' ';
      echo '<div class="accept-email-optin-terms">I accept the <a href="' . tep_href_link('terms_conditions.php') . '">Terms &amp; Conditions</a>: <input type="checkbox" name="terms_of_use" id="termsft" /></div>';
      echo tep_draw_button(MODULE_FOOTER_MAILCHIMP_SUBMIT, 'fa fa-pencil-square-o', null, null, array('params' => 'id="SendButtonft"'), 'btn-success btn-sm');
    } elseif ((MODULES_HEADER_TAGS_MAILCHIMP_LIST_ANONYMOUS != '')) {
      echo '<span class="website-url">Website URL:<br /><input type="text" name="url" id="urlft" placeholder="Website URL" /></span>';
      echo tep_draw_input_field('email', NULL, 'required aria-required="true" id="emailft" placeholder="' . ENTRY_EMAIL_ADDRESS . '"', 'email') . ' ';
      echo '<div class="accept-optin-terms">I accept the <a href="' . tep_href_link('terms_conditions.php') . '">Terms &amp; Conditions</a>: <input type="checkbox" name="terms_of_use" id="termsft" /></div>';
      echo tep_draw_button(MODULE_FOOTER_MAILCHIMP_SUBMIT, 'fa fa-pencil-square-o', null, null, array('params' => 'id="SendButtonft"'), 'btn-success btn-sm') . tep_draw_hidden_field('anonymous', 'anonymous');
    }
    if (MODULE_FOOTER_MAILCHIMP_DISPLAY_PRIVACY == 'True') {
      echo tep_draw_button(MODULE_FOOTER_MAILCHIMP_PRIVACY, 'fa fa-user', tep_href_link('privacy.php'), null, null, 'btn-info btn-xs pull-right');
    }
    echo $endform;
    echo '<br><div class="message" id="messageft"></div>';
?>

Note: if your Term & Conditions (or Terms of Use) file is named differently than terms_conditions.php, change the name of that file to that of your own (2 instances in the code above).

 

4) /ext/api/mailchimp_v3/subscribe.php
FIND this code:

  if ( isset($_POST['anonymous'])) {
    $list_id = MODULES_HEADER_TAGS_MAILCHIMP_LIST_ANONYMOUS;
    $merge_vars = [
                    'FNAME' => '',
                    'LNAME' => ''
                  ];

  } else {
    $list_id = MODULES_HEADER_TAGS_MAILCHIMP_LIST_CUSTOMERS;

    $merge_vars = [
                    'FNAME' => $_POST['firstname'],
                    'LNAME' => $_POST['lastname']
                  ];
  }

  $array = [
              'email_address' => $_POST['email'],
              'merge_fields'  => $merge_vars,
              'status'        => MODULES_HEADER_TAGS_MAILCHIMP_STATUS_CHOICE
            ];


  if (MODULES_HEADER_TAGS_MAILCHIMP_STATUS_CHOICE == 'pending') {
    $status = 'pending';
  } else {
    $status = 'subscribed';
  }

  $MailChimp = new \MailChimp($key);


// add the email to your list
  $result = $MailChimp->post('/lists/' . $list_id . '/members', $array);

REPLACE it with this:

  if (isset($_POST['anonymous'])) {
    $list_id = MODULES_HEADER_TAGS_MAILCHIMP_LIST_ANONYMOUS;
	
    $merge_vars = array('FNAME' => '',
                        'LNAME' => '');

  } else {
    $list_id = MODULES_HEADER_TAGS_MAILCHIMP_LIST_CUSTOMERS;

    $merge_vars = array('FNAME' => $_POST['firstname'],
                        'LNAME' => $_POST['lastname']);
				  
  }
			
  $array = array('email_address' => $_POST['email'],
                 'merge_fields'  => $merge_vars,
                 'status'        => MODULES_HEADER_TAGS_MAILCHIMP_STATUS_CHOICE);


  if (MODULES_HEADER_TAGS_MAILCHIMP_STATUS_CHOICE == 'pending') {
    $status = 'pending';
  } else {
    $status = 'subscribed';
  }

  $MailChimp = new \MailChimp($key);

// add the email to your list
  if (isset($_POST['url']) && $_POST['url'] == '' && !isset($_POST['terms_of_use'])) { // submit contact info when it is not a bot
      $result = $MailChimp->post('/lists/' . $list_id . '/members', $array);
  } else { // when it's a bot, leave out the path and list id 
      $result = $MailChimp->post('', $array);
  }

 

5) /user.css
ADD to the end of this file:

.website-url, .accept-email-optin-terms { position:absolute; left:-20000px; }
.accept-email-optin-terms { z-index:-100; }

Note: You could add this code contained within the <style></style> tags at the top of the template file (file via #3 above), however, I believe it’s better to keep that CSS code outside of that template file.

 

To test this feature, you will need to comment-out the CSS code in /user.css file OR, you could hold off adding that code in #5 (which will hide these two fields) until you complete testing the added spam bot-trap feature.

The footer template form code also has a couple of error fixes same as the subscribed.php file. And I corrected the fields ID’s so that they clear upon submission.

I tried using the tep_draw_input_field() for the Website URL field, but for some reason, it was not working for me. I have an idea as to why, but just did not want to waste more time fiddling with it.

If anyone can find a way to improve this, please do so and share it.

Demitry

 

Edited by Demitry

osCommerce: made for programmers, ...because store owners do not want to be programmers.

https://trends.google.com/trends/explore?date=all&amp;geo=US&amp;q=oscommerce

Link to comment
Share on other sites

Thank you Loic,

One minor correction:

Correction on 2) d)
2) /includes /modules/header_tags/ht_mailchimp.php
    d) FIND this code (for the header module):

        $(\'#messagehd\').html(resultmessage); // display the message
        $(\'#fnamehd\').val(""); // reset input field
        $(\'#lnamehd\').val(""); // reset input field
        $(\'#emailhd\').val(""); // reset input field

REPLACE it with this:

        $(\'#messagehd\').html(resultmessage); // display the message
        $(\'#fnamehd\').val(""); // reset input field
        $(\'#lnamehd\').val(""); // reset input field
        $(\'#urlhd\').val(""); // reset input field
        $(\'#emailhd\').val(""); // reset input field

 

    e) FIND this code (for the footer module):

        $(\'#messageft\').html(resultmessage); // display the message
        $(\'#fnameft\').val(""); // reset input field
        $(\'#lnameft\').val(""); // reset input field
        $(\'#emailft\').val(""); // reset input field

REPLACE it with this:

        $(\'#messageft\').html(resultmessage); // display the message
        $(\'#fnameft\').val(""); // reset input field
        $(\'#lnameft\').val(""); // reset input field
        $(\'#urlft\').val(""); // reset input field
        $(\'#emailft\').val(""); // reset input field

 

The error there is the ending “hd” for header, and “ft” for footer in the field id’s.  Basically, this is to correct my error above.. so that the header fields clear after submission. Like I said, I did not install or test the header Mailchimp module.

Demitry

 

Edited by Demitry

osCommerce: made for programmers, ...because store owners do not want to be programmers.

https://trends.google.com/trends/explore?date=all&amp;geo=US&amp;q=oscommerce

Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...
  • 1 month later...

@Gyakutsuki What about adding List Group
"Groups are a powerful tool that targets subscribers by their interests or preferences within a single list, so you don't have to manage multiple lists with overlapping subscribers. Groups can be used for any data, like a favorite food, a preferred store location, or anything you want to use to filter your list."

Do you think it is possible ?

BR
Omar

Get the latest Responsive osCommerce CE (community edition) here .

Link to comment
Share on other sites

  • 4 months later...

This is just a simplified version, but install the plugin as supposed and than add this:

After:
  if (isset($_POST['action']) && ($_POST['action'] == 'process') && isset($_POST['formid']) && ($_POST['formid'] == $sessiontoken)) {
    $process = true;

Add:
 if (MODULE_FOOTER_MAILCHIMP_STATUS == 'True' && isset($_POST['newsletter']) && $_POST['newsletter'] == 1) {
  include('ext/api/mailchimp_v3/MailChimp.php');
  $key = [your api key];
  $list_id = [your email list id];
  $array = array('email_address' => $_POST['email_address'],
        'merge_fields'  => array('FNAME' => $_POST['firstname'],
            'LNAME' => $_POST['lastname']),
        'status'        => 'subscribed');
 
  $MailChimp = new MailChimp($key);
  $result = $MailChimp->post('/lists/' . $list_id . '/members', $array);
 }


Replace
[your api key]            with your api key like '123456789'
[your email list id]   with your email list id like '98765'

Link to comment
Share on other sites

@cDGo IT Consultancy

Thank you Domé, that does look interesting. I will add it and see how it works. Thank you for sharing that.

 

osCommerce: made for programmers, ...because store owners do not want to be programmers.

https://trends.google.com/trends/explore?date=all&amp;geo=US&amp;q=oscommerce

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...