Forums / Managing Customers and Orders / July 2014 Canada Anti-Spam Legislation (CASL) Twitch CASL

July 2014 Canada Anti-Spam Legislation (CASL) Twitch CASL

Views: 19,421

Results 1 to 20 of 25
4 Jun 2014, 3:51 PM
#1
twitchtoo avatar

twitchtoo

Totally Zenned

Join Date:
Apr 2007
Location:
Ontario, Canada
Posts:
1,733
Plugin Contributions:
14

July 2014 Canada Anti-Spam Legislation (CASL) Twitch CASL

Twitch CASL - This is the first step towards compliance for the new CASL anti spam law in Canada. (Takes effect July 1st, 2014)

Tested and working with Zen 1.39h and 1.51.

Add to Database:
Table - cust_casl

Columns - cust_casl_id, date_checked, casl_purpose, ip_address

Attachment 14126

When a customer creates a new account...
Add to includes/modules/YOUR_TEMPLATE/create_account.php

// bof Twitch CASL only record if they checked the box
if ($newsletter == '1') { 
    $sql = "insert into " . TABLE_CUST_CASL . "
                          (cust_casl_id, date_checked, casl_purpose, ip_address)
              values ('" . (int)$_SESSION['customer_id'] . "', now(), 'Yes, I would like to receive emails from YOUR_COMPANY_HERE regarding upcoming promotions', '". $_SERVER['REMOTE_ADDR'] . "')";

    $db->Execute($sql);
} 
// eof Twitch CASL

(replace YOUR_COMPANY_HERE with your company name)

When a customer changes their newsletter settings via account_edit...
Add to includes/modules/pages/account_newsletters/header_php.php

// bof Twitch CASL only record if they checked the box
//
    // load cust_id from casl if exists
    $casl_query = "SELECT cust_casl_id
                   FROM   " . TABLE_CUST_CASL . "
                   WHERE  cust_casl_id = '" . (int)$_SESSION['customer_id'] . "' ";
    $casl_check = $db->Execute($casl_query);

if ($casl_check == '') { // no record found for this customer

    if ($newsletter_general == '1') { // add the casl record ONLY if they checked the box

        $sql = "insert into " . TABLE_CUST_CASL . "
               (cust_casl_id, date_checked, casl_purpose, ip_address)
        values ('" . (int)$_SESSION['customer_id'] . "', now(), 'Yes, I would like to receive emails from YOUR_COMPANY_HERE regarding upcoming promotions', '". $_SERVER['REMOTE_ADDR'] . "')";

        $db->Execute($sql);
    } // end checked box - insert new

} else { // if casl customer record already exists, update the date_checked and ip_address ONLY if the box is checked

    if ($newsletter_general == '1') { // add the casl record ONLY if they checked the box
        $sql = "update " . TABLE_CUST_CASL . "
                set date_checked = now(), ip_address = '". $_SERVER['REMOTE_ADDR'] . "'
                where cust_casl_id = '" . (int)$_SESSION['customer_id'] . "' ";
        $db->Execute($sql);
    } // end checked box update

} // end CASL check
//
// eof Twitch CASL only record if they checked the box

(replace YOUR_COMPANY_HERE with your company name)

Twitch.
https://www.twitchtoo.com Do you work for free? Please donate.
June 7.2026 - NOW AVAILABLE - Twitch Base8 - Obsidian

4 Jun 2014, 3:53 PM
#2
twitchtoo avatar

twitchtoo

Totally Zenned

Join Date:
Apr 2007
Location:
Ontario, Canada
Posts:
1,733
Plugin Contributions:
14

Re: July 2014 Canada Anti-Spam Legislation (CASL) Twitch CASL

Understanding how this code works:
**
New Customer** - When a new customer signs up and does not click the newsletter checkbox, nothing happens. When they check the box the customer_id, date and time, static text displayed that they are agreeing to, ip address are recorded in the CUST_CASL table.

Existing Customer - When an existing customer logs into their account, goes to 'My Account' and selects 'Subscribe or unsubscribe from newsletter' they land on a page with a checkbox showing their previous newsletter setting.

**Scenario A **- The newsletter box was never checked
-> All of the required fields will be added to the CUST_CASL table if they check the box.

Scenario B - The newsletter box was previously checked - remains checked - and they click update
-> The current date and time, current ip address will be updated in the existing customer field.

Note: If they previously did check the newsletter box, then they uncheck the box, the CASL records will remain intact. This ensures that any customer complaints can be traced back to a date, time and ip address for legal means.

As always, backup your site before making changes, read and follow the regulations provided by the Government of Canada related to CASL compliance for your own business, donations are appreciated :)

Twitch.
https://www.twitchtoo.com Do you work for free? Please donate.
June 7.2026 - NOW AVAILABLE - Twitch Base8 - Obsidian

12 Jun 2014, 3:22 PM
#3
twitchtoo avatar

twitchtoo

Totally Zenned

Join Date:
Apr 2007
Location:
Ontario, Canada
Posts:
1,733
Plugin Contributions:
14

Re: July 2014 Canada Anti-Spam Legislation (CASL) Twitch CASL

To display the database records for those that have checked the newsletter box located at:

Admin -> Customers -> Select Customer -> Click Edit

In 'Options - Send me Discounts and Deals through email.' below the newsletter dropdown in admin/customers.php

Look for:

            <td class="main"><?php echo ENTRY_NEWSLETTER; ?></td>
            <td class="main">
<?php
  if ($processed == true) {
    if ($cInfo->customers_newsletter == '1') {
      echo ENTRY_NEWSLETTER_YES;
    } else {
      echo ENTRY_NEWSLETTER_NO;
    }
    echo zen_draw_hidden_field('customers_newsletter');
  } else {
    echo zen_draw_pull_down_menu('customers_newsletter', $newsletter_array, (($cInfo->customers_newsletter == '1') ? '1' : '0'));
  }

?></td>

Add this code after the trailing </td>:

<?php // bof Twitch CASL ?>
<tr> <td> </td> 
<td> 
<?php 
// Display db records in admin
    $casl_query = "SELECT *
                   FROM   " . TABLE_CUST_CASL . "
                   WHERE  cust_casl_id = '" . (int)$customers_id . "' ";
    $casl_check = $db->Execute($casl_query);

     if ($casl_check->fields['cust_casl_id'] == (int)$customers_id  ) {
    // output the db record
        echo '<strong>Customer ID: </strong>' . $casl_check->fields['cust_casl_id'] . ' ' ;
        echo '<strong>Date Last Checked: </strong>' . $casl_check->fields['date_checked'] . ' ' ;
        echo '<strong>Agreement: </strong>' . $casl_check->fields['casl_purpose'] . ' ' ;
        echo '<strong>Location: </strong>' . $casl_check->fields['ip_address'] . ' ' ;

     } else { 
    // No record found meaning the customer has not checked the newsletter box
        echo 'No CASL record found. Customer has not checked newsletter subscribe box.';

    }
?>
</td>
<td> </td>
</tr>
<?php // eof Twitch CASL ?>

Twitch.
https://www.twitchtoo.com Do you work for free? Please donate.
June 7.2026 - NOW AVAILABLE - Twitch Base8 - Obsidian

19 Jun 2014, 9:47 PM
#4
verzea avatar

verzea

New Zenner

Join Date:
Nov 2007
Posts:
11
Plugin Contributions:
0

Re: July 2014 Canada Anti-Spam Legislation (CASL) Twitch CASL

Hi, I tried to do all of these steps for 1.51 and it's not working. After I made the DB changes by adding a new table with the 4 columns, I added the code lines in those files. The result is that I've got an error message every time when I make (confirm) a new account and also when I try to update the mail newsletter settings for an existing account. Can you be more specific where in those two files (create_account.php and header_php.php) should I add the code lines? Please help, first of July is coming.

19 Jun 2014, 9:52 PM
#5
verzea avatar

verzea

New Zenner

Join Date:
Nov 2007
Posts:
11
Plugin Contributions:
0

Re: July 2014 Canada Anti-Spam Legislation (CASL) Twitch CASL

Is there other place where I need to modify the code or there are some hidden settings to do before?

20 Jun 2014, 1:47 PM
#6
twitchtoo avatar

twitchtoo

Totally Zenned

Join Date:
Apr 2007
Location:
Ontario, Canada
Posts:
1,733
Plugin Contributions:
14

Re: July 2014 Canada Anti-Spam Legislation (CASL) Twitch CASL

verzea:

Hi, I tried to do all of these steps for 1.51 and it's not working. After I made the DB changes by adding a new table with the 4 columns, I added the code lines in those files. The result is that I've got an error message every time when I make (confirm) a new account and also when I try to update the mail newsletter settings for an existing account. Can you be more specific where in those two files (create_account.php and header_php.php) should I add the code lines? Please help, first of July is coming.

In includes/modules/YOUR_TEMPLATE/create_account.php after the following code:

    $sql = "insert into " . TABLE_CUSTOMERS_INFO . "
                          (customers_info_id, customers_info_number_of_logons,
                           customers_info_date_account_created, customers_info_date_of_last_logon)
              values ('" . (int)$_SESSION['customer_id'] . "', '1', now(), now())";

    $db->Execute($sql);

(around line 319) you can add the Twitch CASL code.

In includes/modules/pages/account_newsletters/header_php.php after the following code:

    $sql = "UPDATE " . TABLE_CUSTOMERS . "
            SET    customers_newsletter = :customersNewsletter
            WHERE  customers_id = :customersID";

    $sql = $db->bindVars($sql, ':customersID',$_SESSION['customer_id'], 'integer');
    $sql = $db->bindVars($sql, ':customersNewsletter',$newsletter_general, 'integer');
    $db->Execute($sql);
  }

(around line 43) you can add the Twitch CASL code.

Twitch.
https://www.twitchtoo.com Do you work for free? Please donate.
June 7.2026 - NOW AVAILABLE - Twitch Base8 - Obsidian

20 Jun 2014, 1:54 PM
#7
twitchtoo avatar

twitchtoo

Totally Zenned

Join Date:
Apr 2007
Location:
Ontario, Canada
Posts:
1,733
Plugin Contributions:
14

Re: July 2014 Canada Anti-Spam Legislation (CASL) Twitch CASL

verzea:

Is there other place where I need to modify the code or there are some hidden settings to do before?

There are no hidden settings. The database tables must be set exactly as listed in the original post #1. Next the Twitch CASL code needs to be cut and paste into the various php files in the locations posted in post #3 and #6.

If you are still having errors, it's best to contact me directly via email, or to this thread - with a copy of the error message or the most recent error listed in your /logs folder.

Or if you'd like I can check it for you, make email contact with me first then we'll share usernames and passwords for admin/FTP.

Twitch.
https://www.twitchtoo.com Do you work for free? Please donate.
June 7.2026 - NOW AVAILABLE - Twitch Base8 - Obsidian

20 Jun 2014, 3:59 PM
#8
verzea avatar

verzea

New Zenner

Join Date:
Nov 2007
Posts:
11
Plugin Contributions:
0

Re: July 2014 Canada Anti-Spam Legislation (CASL) Twitch CASL

The message is: WARNING: An Error occurred, please refresh the page and try again.

-the DB table looks identical
-the code is placed on the right place
-when I create a new account as a Canadian, once I checked the Newsletter and hit created I received this error
-if I log in with a different account (Canadian as well) and check My Account / Newsletter Subscription (which is already "on") and hit Update button, again, the error message

Thanks in advance :)

(it looks that nothing is written on the DB for the table zen_cust_casl)

20 Jun 2014, 4:10 PM
#9
twitchtoo avatar

twitchtoo

Totally Zenned

Join Date:
Apr 2007
Location:
Ontario, Canada
Posts:
1,733
Plugin Contributions:
14

Re: July 2014 Canada Anti-Spam Legislation (CASL) Twitch CASL

verzea:

The message is: WARNING: An Error occurred, please refresh the page and try again.

-the DB table looks identical
-the code is placed on the right place
-when I create a new account as a Canadian, once I checked the Newsletter and hit created I received this error
-if I log in with a different account (Canadian as well) and check My Account / Newsletter Subscription (which is already "on") and hit Update button, again, the error message

Thanks in advance :)

(it looks that nothing is written on the DB for the table zen_cust_casl)

Check your PM, I need access to trace this problem.

Twitch.
https://www.twitchtoo.com Do you work for free? Please donate.
June 7.2026 - NOW AVAILABLE - Twitch Base8 - Obsidian

20 Jun 2014, 6:59 PM
#10
dchquilling avatar

dchquilling

New Zenner

Join Date:
Sep 2006
Location:
New Brunswick, Canada
Posts:
12
Plugin Contributions:
0

Re: July 2014 Canada Anti-Spam Legislation (CASL) Twitch CASL

verzea,

Did you define the new table in database_tables.php?
If not, add the following line at the end of file:

define('TABLE_CUST_CASL', DB_PREFIX . 'cust_casl');

Deborah Hartin

20 Jun 2014, 7:06 PM
#11
twitchtoo avatar

twitchtoo

Totally Zenned

Join Date:
Apr 2007
Location:
Ontario, Canada
Posts:
1,733
Plugin Contributions:
14

Re: July 2014 Canada Anti-Spam Legislation (CASL) Twitch CASL

dchquilling:

verzea,

Did you define the new table in database_tables.php?
If not, add the following line at the end of file:

define('TABLE_CUST_CASL', DB_PREFIX . 'cust_casl');

Verzea this will correct the error in your .logs folder:

[20-Jun-2014 10:54:01 America/Denver] PHP Fatal error: 1146:Table 'your_table_name_here.TABLE_CUST_CASL' doesn't exist :: SELECT cust_casl_id
FROM TABLE_CUST_CASL
WHERE cust_casl_id = '3403' in /home1/your_site/public_html/store/includes/classes/db/mysql/query_factory.php on line 120

Twitch.
https://www.twitchtoo.com Do you work for free? Please donate.
June 7.2026 - NOW AVAILABLE - Twitch Base8 - Obsidian

20 Jun 2014, 7:19 PM
#12
verzea avatar

verzea

New Zenner

Join Date:
Nov 2007
Posts:
11
Plugin Contributions:
0

Re: July 2014 Canada Anti-Spam Legislation (CASL) Twitch CASL

Thanks. much appreciated!

20 Jun 2014, 7:45 PM
#13
verzea avatar

verzea

New Zenner

Join Date:
Nov 2007
Posts:
11
Plugin Contributions:
0

Re: July 2014 Canada Anti-Spam Legislation (CASL) Twitch CASL

I've double checked and it works only one part (creation of a new account). If you have an existing Canadian account an hit Update under Newsletter preferences, nothing happens (no data into the db cust_casl table and no notification under Admin/Customers Info).

20 Jun 2014, 7:55 PM
#14
twitchtoo avatar

twitchtoo

Totally Zenned

Join Date:
Apr 2007
Location:
Ontario, Canada
Posts:
1,733
Plugin Contributions:
14

Re: July 2014 Canada Anti-Spam Legislation (CASL) Twitch CASL

verzea:

I've double checked and it works only one part (creation of a new account). If you have an existing Canadian account an hit Update under Newsletter preferences, nothing happens (no data into the db cust_casl table and no notification under Admin/Customers Info).

You have errors in your /logs folder that indicate the /admin changes to were not installed correctly or previous problems existed.

I'll need access again to provide support.

Twitch.
https://www.twitchtoo.com Do you work for free? Please donate.
June 7.2026 - NOW AVAILABLE - Twitch Base8 - Obsidian

30 Jun 2014, 3:11 PM
#15
hfxracing avatar

hfxracing

New Zenner

Join Date:
May 2011
Location:
Nova Scotia
Posts:
39
Plugin Contributions:
0

Re: July 2014 Canada Anti-Spam Legislation (CASL) Twitch CASL

I like what you are doing with this I would like this to replace the newsletter feature. For me it's customer on or off my mailing list the catch is I want the cart to e-mail me when the customer updates the account. I have been looking for hours I can seem to find that option. If you have an existing customer & they go to their account or if they click the unsubscribed link or re add it the cart does not tell me they have done so. I use a CRM (customer relations manager)for all my customer contacts. With this new law I need to know not only buy customer saying remove me via e-mail but also for the accounts on the website. Does this e-mail the admin or would it be hard to add that in?

30 Jun 2014, 4:37 PM
#16
twitchtoo avatar

twitchtoo

Totally Zenned

Join Date:
Apr 2007
Location:
Ontario, Canada
Posts:
1,733
Plugin Contributions:
14

Re: July 2014 Canada Anti-Spam Legislation (CASL) Twitch CASL

hfxracing:

I like what you are doing with this I would like this to replace the newsletter feature. For me it's customer on or off my mailing list the catch is I want the cart to e-mail me when the customer updates the account. I have been looking for hours I can seem to find that option. If you have an existing customer & they go to their account or if they click the unsubscribed link or re add it the cart does not tell me they have done so. I use a CRM (customer relations manager)for all my customer contacts. With this new law I need to know not only buy customer saying remove me via e-mail but also for the accounts on the website. Does this e-mail the admin or would it be hard to add that in?

This would need to be an add on feature that could be turned on or off in admin. As well a downloadable list of subscribed folks and unsubscribed folks. Ideally the notification email would use the same code path as any other notifications in a stock cart.

Twitch.
https://www.twitchtoo.com Do you work for free? Please donate.
June 7.2026 - NOW AVAILABLE - Twitch Base8 - Obsidian

30 Jun 2014, 5:40 PM
#17
hfxracing avatar

hfxracing

New Zenner

Join Date:
May 2011
Location:
Nova Scotia
Posts:
39
Plugin Contributions:
0

Re: July 2014 Canada Anti-Spam Legislation (CASL) Twitch CASL

I can work a little with code any suggestions on where to start I really need my cart to tell me the account has changed from either subscribed to unsubscribed.

28 Aug 2014, 11:54 AM
#18
twitchtoo avatar

twitchtoo

Totally Zenned

Join Date:
Apr 2007
Location:
Ontario, Canada
Posts:
1,733
Plugin Contributions:
14

Re: July 2014 Canada Anti-Spam Legislation (CASL) Twitch CASL

hfxracing:

I can work a little with code any suggestions on where to start I really need my cart to tell me the account has changed from either subscribed to unsubscribed.

There are two options:
1 - Email notification to the admin - There are several points at which this data would need to be transmitted via email.

  • Create Account
  • Edit Account
  • Admin Customer Edit

2 - Display/Compile a downloadable list in admin - This could output to common file formats for import to MailChimp, Constant Contact or similar.

Consider the number of notifications you want/need given the scale of your current customer base.

Twitch.
https://www.twitchtoo.com Do you work for free? Please donate.
June 7.2026 - NOW AVAILABLE - Twitch Base8 - Obsidian

28 Aug 2014, 4:05 PM
#19
twitchtoo avatar

twitchtoo

Totally Zenned

Join Date:
Apr 2007
Location:
Ontario, Canada
Posts:
1,733
Plugin Contributions:
14

Re: July 2014 Canada Anti-Spam Legislation (CASL) Twitch CASL

Twitch CASL 14.a for Zen Cart 1.53 will be released by days end.

Finally a complete plugin with install instructions!

CASL features:

  • SQL update to build complete CASL table during install now included

  • Records CASL data during create account

  • Records if the newsletter switch checked or not checked by admin

  • Records if the newsletter switch is checked or not *checked *by user

  • Records CASL data if record was not found

  • CASL record remains even if customer is deleted - index id, date, time, agreement and ip address stored.

  • SQL update to import all customers from existing databases included

Backwards compatible with Zen Cart 1.51 - Line numbers will be off a bit.

Twitch.
https://www.twitchtoo.com Do you work for free? Please donate.
June 7.2026 - NOW AVAILABLE - Twitch Base8 - Obsidian

28 Mar 2015, 2:06 AM
#20
twitchtoo avatar

twitchtoo

Totally Zenned

Join Date:
Apr 2007
Location:
Ontario, Canada
Posts:
1,733
Plugin Contributions:
14

Re: July 2014 Canada Anti-Spam Legislation (CASL) Twitch CASL

Twitch CASL 16a for Zen Cart v1.54 is complete.

Check the forum *plugins *or my website for your copy.

Canadian shopping carts please note that compliance with CASL is mandatory!!

Twitch.
https://www.twitchtoo.com Do you work for free? Please donate.
June 7.2026 - NOW AVAILABLE - Twitch Base8 - Obsidian