<?xml version="1.0" encoding="ISO-8859-1"?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
	<channel>
		<title>Zen Cart Support - Blogs</title>
		<link>http://www.zen-cart.com/blog.php</link>
		<description>This is the support site for the popular Zen Cart e-commerce shopping cart software.</description>
		<language>en</language>
		<lastBuildDate>Fri, 24 May 2013 04:25:25 GMT</lastBuildDate>
		<generator>vBulletin</generator>
		<ttl>60</ttl>
		<image>
			<url>http://www.zen-cart.com/images/styles/zencart/misc/rss.jpg</url>
			<title>Zen Cart Support - Blogs</title>
			<link>http://www.zen-cart.com/blog.php</link>
		</image>
		<item>
			<title>Hey Look, We have a Blog system</title>
			<link>http://www.zen-cart.com/entry.php?1-Hey-Look-We-have-a-Blog-system</link>
			<pubDate>Tue, 09 Oct 2012 20:31:19 GMT</pubDate>
			<description>One of the many benefits of the upgrade to vBulletin 4 is that it gives us this shiny blog system. However because it is nice and shiny, for now we are keeping it all to ourselves. :D 
 
It may be in the future we open up the system more to our user base, but for now, you will just have to put up...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">One of the many benefits of the upgrade to vBulletin 4 is that it gives us this shiny blog system. However because it is nice and shiny, for now we are keeping it all to ourselves. :D<br />
<br />
It may be in the future we open up the system more to our user base, but for now, you will just have to put up with the ramblings of the Zen Cart development team. <br />
<br />
Generally we hope to Blog about stuff that would not normally be relevant within the Forum context. Some stuff about PA-DSS, or thoughts about general trends in E-Commerce, maybe even a rant or two. <br />
<br />
Watch this space :D</blockquote>

]]></content:encoded>
			<dc:creator>wilt</dc:creator>
			<guid isPermaLink="true">http://www.zen-cart.com/entry.php?1-Hey-Look-We-have-a-Blog-system</guid>
		</item>
		<item>
			<title>Creating an Observer Class: send a specialized additional email during Create Account</title>
			<link>http://www.zen-cart.com/entry.php?4-Creating-an-Observer-Class-send-a-specialized-additional-email-during-Create-Account</link>
			<pubDate>Fri, 07 Sep 2012 03:42:51 GMT</pubDate>
			<description><![CDATA[*Task:* 
 
* Storeowner wants to send the customer an email with a unique code when the customer creates an account. 
* The code pattern is "ABC00001", where ABC is fixed text, and 00001 is the customer number, with leading zeros up to exactly 5 digits. 
* There is no need to build a database of...]]></description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore"><b>Task:</b><br />
<ul><li style="">Storeowner wants to send the customer an email with a unique code when the customer creates an account.</li><li style="">The code pattern is &quot;ABC00001&quot;, where ABC is fixed text, and 00001 is the customer number, with leading zeros up to exactly 5 digits.</li><li style="">There is no need to build a database of already-issued codes, since the customer ID number is already unique per customer.</li><li style="">The store is using v1.5.0 code. </li></ul><br />
<br />
<b>The thinking and coding process:<br />
</b>First, since this must happen during account-creation, it makes sense to consider looking at the /includes/modules/create_account.php script which handles those activities.<br />
<br />
Since the intention is to see whether an Observer class can be used for this, I <b>started by scanning the file for any notifier hooks. These can be identified in either of two ways: calls to $zco_notifier-&gt;notify() for procedural code or $this-&gt;notify() from inside any class method.</b><br />
<br />
We want a notifier point that fires sometime after a customer has submitted their user information and it's been validated.<br />
<br />
So, at the end of the validation code there's this one:<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:36px;">    $zco_notifier-&gt;notify('NOTIFY_FAILURE_DURING_CREATE_ACCOUNT');</pre>
</div>… but we're not interested in a failure case, so we keep looking:<br />
<br />
The next one is this:<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:36px;">    $zco_notifier-&gt;notify('NOTIFY_MODULE_CREATE_ACCOUNT_ADDED_CUSTOMER_RECORD', array_merge(array('customer_id' =&gt; $_SESSION['customer_id']), $sql_data_array));</pre>
</div>And, looking closely at the code immediately above it, we see that that part of the code has just finished building the new customer data for the database, inserted that record, and set the customer ID into the session, effectively logging them in.  This is perfect! And what's even better is that the $sql_data_array has also been passed, so we can make use of that to customize the email with the customer's name and email address.<br />
<br />
So, now we start with creating an observer class.  We start with the basic structure:<br />
<div class="bbcode_container">
	<div class="bbcode_description">PHP Code:</div>
	<div class="bbcode_code"style="height:192px;"><code><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/**<br />&nbsp;*&nbsp;Observer&nbsp;class&nbsp;for&nbsp;sending&nbsp;an&nbsp;extra&nbsp;email&nbsp;during&nbsp;customer-creation/welcome&nbsp;process<br />&nbsp;*/<br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">send_extra_email_at_welcome&nbsp;</span><span style="color: #007700">extends&nbsp;</span><span style="color: #0000BB">base&nbsp;</span><span style="color: #007700">{<br /><br />&nbsp;&nbsp;function&nbsp;</span><span style="color: #0000BB">__construct</span><span style="color: #007700">()&nbsp;<br />&nbsp;&nbsp;{<br />&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;function&nbsp;</span><span style="color: #0000BB">update</span><span style="color: #007700">(&amp;</span><span style="color: #0000BB">$class</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$eventID</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$paramsArray&nbsp;</span><span style="color: #007700">=&nbsp;array())<br />&nbsp;&nbsp;{<br />&nbsp;&nbsp;}<br />&nbsp;}</span>
</span>
</code></code></div>
</div>You'll see here that we've given the class a name of <b>send_extra_email_at_welcome</b>.  This name will be used later in the auto_loader to activate this observer class. The name itself just needs to be unique from any other class used in the store.<br />
<br />
Next we need to set up the constructor to watch the <i>NOTIFY_MODULE_CREATE_ACCOUNT_ADDED_CUSTOMER_RECORD</i> hook we identified earlier.  Since the notifier hook is activated via a $zco_notifier call, we set the observer up to attach to that $zco_notifier-&gt;notify() call:<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:84px;">  function __construct() 
  {
    global $zco_notifier;
    $zco_notifier-&gt;attach($this, array('NOTIFY_MODULE_CREATE_ACCOUNT_ADDED_CUSTOMER_RECORD'));
  }</pre>
</div>We have a few main tasks to perform when this notifier hook is called:<br />
a) create a formatted &quot;code&quot; based on the customer number<br />
b) assemble email text with the code<br />
c) send the email<br />
<br />
Let's look at these one at a time:<br />
a) create the formatted code from the customer number. We'll use the PHP function str_pad() to add enough zeros to make a 5-digit value from the customer number:<br />
<div class="bbcode_container">
	<div class="bbcode_description">PHP Code:</div>
	<div class="bbcode_code"style="height:72px;"><code><code><span style="color: #000000">
<span style="color: #0000BB">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/**<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Here&nbsp;we&nbsp;take&nbsp;the&nbsp;customer&nbsp;number,&nbsp;and&nbsp;add&nbsp;enough&nbsp;zeros&nbsp;to&nbsp;the&nbsp;left&nbsp;of&nbsp;it&nbsp;to&nbsp;make&nbsp;it&nbsp;be&nbsp;5&nbsp;digits&nbsp;long.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$code&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">str_pad</span><span style="color: #007700">(</span><span style="color: #0000BB">$_SESSION</span><span style="color: #007700">&#91;</span><span style="color: #DD0000">'customer_id'</span><span style="color: #007700">&#93;,</span><span style="color: #0000BB">5</span><span style="color: #007700">,</span><span style="color: #DD0000">'0'</span><span style="color: #007700">,</span><span style="color: #0000BB">STR_PAD_LEFT</span><span style="color: #007700">);&nbsp;<br /></span><span style="color: #0000BB"></span>
</span>
</code></code></div>
</div>and then add the ABC prefix to the beginning of it:<br />
<div class="bbcode_container">
	<div class="bbcode_description">PHP Code:</div>
	<div class="bbcode_code"style="height:72px;"><code><code><span style="color: #000000">
<span style="color: #0000BB">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/**<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Then&nbsp;the&nbsp;'ABC'&nbsp;prefix&nbsp;is&nbsp;added&nbsp;to&nbsp;it:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$code&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'ABC'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$code</span><span style="color: #007700">;&nbsp;<br /></span><span style="color: #0000BB"></span>
</span>
</code></code></div>
</div>b) Put together some email text, using the code. The first line here is the plain-text content. The $html_msg array will contain the same content, but formatted as HTML, in case the customer has opted to receive html-formatted messages in their preferences during signup.<br />
<div class="bbcode_container">
	<div class="bbcode_description">PHP Code:</div>
	<div class="bbcode_code"style="height:48px;"><code><code><span style="color: #000000">
<span style="color: #0000BB">&nbsp;&nbsp;&nbsp;&nbsp;$email_text&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'Here&nbsp;is&nbsp;your&nbsp;unique&nbsp;code:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$code</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$html_msg</span><span style="color: #007700">&#91;</span><span style="color: #DD0000">'EMAIL_MESSAGE_HTML'</span><span style="color: #007700">&#93;&nbsp;.=&nbsp;</span><span style="color: #0000BB">nl2br</span><span style="color: #007700">(</span><span style="color: #0000BB">$email_text</span><span style="color: #007700">);&nbsp;<br /></span><span style="color: #0000BB"></span>
</span>
</code></code></div>
</div>We'll need a subject line for the email:<br />
<div class="bbcode_container">
	<div class="bbcode_description">PHP Code:</div>
	<div class="bbcode_code"style="height:48px;"><code><code><span style="color: #000000">
<span style="color: #0000BB">&nbsp;&nbsp;&nbsp;&nbsp;$email_subject&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'Your&nbsp;unique&nbsp;customer&nbsp;code!'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$html_msg</span><span style="color: #007700">&#91;</span><span style="color: #DD0000">'EMAIL_SUBJECT'</span><span style="color: #007700">&#93;&nbsp;=&nbsp;</span><span style="color: #0000BB">$email_subject</span><span style="color: #007700">;&nbsp;<br /></span><span style="color: #0000BB"></span>
</span>
</code></code></div>
</div>c) To send the email, we need to get the customer's email address. The call to $zco_notifier-&gt;notify() included some extra parameters, which show up in this observer class via the $paramsArray variable:<br />
<div class="bbcode_container">
	<div class="bbcode_description">PHP Code:</div>
	<div class="bbcode_code"style="height:36px;"><code><code><span style="color: #000000">
<span style="color: #0000BB">&nbsp;&nbsp;&nbsp;&nbsp;$customer_email_address&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$paramsArray</span><span style="color: #007700">&#91;</span><span style="color: #DD0000">'customers_email_address'</span><span style="color: #007700">&#93;;&nbsp;<br /></span><span style="color: #0000BB"></span>
</span>
</code></code></div>
</div>Similarly, in this case we happen to also have access to the customer's firstname/lastname, based on whatever they supplied during signup. Here we concatenate both values into a single string:<br />
<div class="bbcode_container">
	<div class="bbcode_description">PHP Code:</div>
	<div class="bbcode_code"style="height:36px;"><code><code><span style="color: #000000">
<span style="color: #0000BB">&nbsp;&nbsp;&nbsp;&nbsp;$customer_name&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$paramsArray</span><span style="color: #007700">&#91;</span><span style="color: #DD0000">'customers_firstname'</span><span style="color: #007700">&#93;&nbsp;.&nbsp;</span><span style="color: #DD0000">'&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$paramsArray</span><span style="color: #007700">&#91;</span><span style="color: #DD0000">'customers_lastname'</span><span style="color: #007700">&#93;;&nbsp;<br /></span><span style="color: #0000BB"></span>
</span>
</code></code></div>
</div>And now we send the email, using all the data we've prepared:<br />
<div class="bbcode_container">
	<div class="bbcode_description">PHP Code:</div>
	<div class="bbcode_code"style="height:36px;"><code><code><span style="color: #000000">
<span style="color: #0000BB">&nbsp;&nbsp;&nbsp;&nbsp;zen_mail</span><span style="color: #007700">(</span><span style="color: #0000BB">$customer_name</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$customer_email_address</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$email_subject</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$email_text</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">STORE_NAME</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">EMAIL_FROM</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$html_msg</span><span style="color: #007700">);&nbsp;<br /></span><span style="color: #0000BB"></span>
</span>
</code></code></div>
</div><b> When we put it all together, the finished code looks like this:</b><br />
<div class="bbcode_container">
	<div class="bbcode_description">PHP Code:</div>
	<div class="bbcode_code"style="height:372px;"><code><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/**<br />&nbsp;*&nbsp;Observer&nbsp;class&nbsp;for&nbsp;sending&nbsp;an&nbsp;extra&nbsp;email&nbsp;during&nbsp;customer-creation/welcome&nbsp;process<br />&nbsp;*/<br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">send_extra_email_at_welcome&nbsp;</span><span style="color: #007700">extends&nbsp;</span><span style="color: #0000BB">base&nbsp;</span><span style="color: #007700">{<br /><br />&nbsp;&nbsp;function&nbsp;</span><span style="color: #0000BB">__construct</span><span style="color: #007700">()&nbsp;<br />&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;global&nbsp;</span><span style="color: #0000BB">$zco_notifier</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$zco_notifier</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">attach</span><span style="color: #007700">(</span><span style="color: #0000BB">$this</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #DD0000">'NOTIFY_MODULE_CREATE_ACCOUNT_ADDED_CUSTOMER_RECORD'</span><span style="color: #007700">));<br />&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;function&nbsp;</span><span style="color: #0000BB">update</span><span style="color: #007700">(&amp;</span><span style="color: #0000BB">$class</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$eventID</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$paramsArray&nbsp;</span><span style="color: #007700">=&nbsp;array())<br />&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/**<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Here&nbsp;we&nbsp;take&nbsp;the&nbsp;customer&nbsp;number,&nbsp;and&nbsp;add&nbsp;enough&nbsp;zeros&nbsp;to&nbsp;the&nbsp;left&nbsp;of&nbsp;it&nbsp;to&nbsp;make&nbsp;it&nbsp;be&nbsp;5&nbsp;digits&nbsp;long.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$code&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">str_pad</span><span style="color: #007700">(</span><span style="color: #0000BB">$_SESSION</span><span style="color: #007700">&#91;</span><span style="color: #DD0000">'customer_id'</span><span style="color: #007700">&#93;,</span><span style="color: #0000BB">5</span><span style="color: #007700">,</span><span style="color: #DD0000">'0'</span><span style="color: #007700">,</span><span style="color: #0000BB">STR_PAD_LEFT</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/**<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Then&nbsp;the&nbsp;'ABC'&nbsp;prefix&nbsp;is&nbsp;added&nbsp;to&nbsp;it:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$code&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'ABC'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$code</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/**<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Now&nbsp;build&nbsp;and&nbsp;send&nbsp;the&nbsp;email&nbsp;to&nbsp;the&nbsp;customer<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$email_text&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'Here&nbsp;is&nbsp;your&nbsp;unique&nbsp;code:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$code</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$html_msg</span><span style="color: #007700">&#91;</span><span style="color: #DD0000">'EMAIL_MESSAGE_HTML'</span><span style="color: #007700">&#93;&nbsp;.=&nbsp;</span><span style="color: #0000BB">nl2br</span><span style="color: #007700">(</span><span style="color: #0000BB">$email_text</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$email_subject&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'Your&nbsp;unique&nbsp;customer&nbsp;code!'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$html_msg</span><span style="color: #007700">&#91;</span><span style="color: #DD0000">'EMAIL_SUBJECT'</span><span style="color: #007700">&#93;&nbsp;=&nbsp;</span><span style="color: #0000BB">$email_subject</span><span style="color: #007700">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$customer_name&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$paramsArray</span><span style="color: #007700">&#91;</span><span style="color: #DD0000">'customers_firstname'</span><span style="color: #007700">&#93;&nbsp;.&nbsp;</span><span style="color: #DD0000">'&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$paramsArray</span><span style="color: #007700">&#91;</span><span style="color: #DD0000">'customers_lastname'</span><span style="color: #007700">&#93;;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$customer_email_address&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$paramsArray</span><span style="color: #007700">&#91;</span><span style="color: #DD0000">'customers_email_address'</span><span style="color: #007700">&#93;;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">zen_mail</span><span style="color: #007700">(</span><span style="color: #0000BB">$customer_name</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$customer_email_address</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$email_subject</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$email_text</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">STORE_NAME</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">EMAIL_FROM</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$html_msg</span><span style="color: #007700">);<br />&nbsp;&nbsp;}<br />}</span>
</span>
</code></code></div>
</div>We'll store this code into a new file, named <b>/includes/classes/observers/class.send_extra_email_at_welcome.php</b><br />
<br />
<br />
Finally, to turn the whole thing on, we add the auto_loader code to tell Zen Cart to load the observer class and instantiate it.  The file will be uploaded to: <b>/includes/auto_loaders/config.send_extra_email_at_welcome.php</b> :<br />
<div class="bbcode_container">
	<div class="bbcode_description">PHP Code:</div>
	<div class="bbcode_code"style="height:96px;"><code><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$autoLoadConfig</span><span style="color: #007700">&#91;</span><span style="color: #0000BB">190</span><span style="color: #007700">&#93;&#91;&#93;&nbsp;=&nbsp;array(</span><span style="color: #DD0000">'autoType'</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">'class'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'loadFile'</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">'observers/class.send_extra_email_at_welcome.php'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$autoLoadConfig</span><span style="color: #007700">&#91;</span><span style="color: #0000BB">190</span><span style="color: #007700">&#93;&#91;&#93;&nbsp;=&nbsp;array(</span><span style="color: #DD0000">'autoType'</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">'classInstantiate'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'className'</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">'send_extra_email_at_welcome'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'objectName'</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">'send_extra_email_at_welcome'</span><span style="color: #007700">);</span>
</span>
</code></code></div>
</div>The value of 190 is used to essentially process all of this at the end of the normal autoloader stack.<br />
The load file points to the class file created earlier. And the className matches the class name in the class file we made, and the objectName is basically the instantiation object built to fire the observer when appropriate … it usually is just the same as the className.<br />
<br />
That's it.  With both of those files in place, when the customer creates a new account, they will receive an extra email (in addition to the normal Welcome email) in which they are told their unique customer code.<br />
<br />
<br />
----------<br />
<br />
<b> What about making it multi-language capable?</b><br />
To do this, we must change the language text into defined constants.<br />
So, we'll take these two lines:<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:48px;">    $email_text = 'Here is your unique code: ' . $code;
    $email_subject = 'Your unique customer code!';</pre>
</div>and make language defines for them:<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:48px;">  define('EMAIL_SUBJECT_EXTRA_EMAIL_WELCOME', 'Your unique customer code!');
  define('EMAIL_TEXT_EXTRA_EMAIL_MESSAGE', 'Here is your unique code: ');</pre>
</div>and change the code to use those constants in place of the text.<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:48px;">    $email_text = EMAIL_TEXT_EXTRA_EMAIL_MESSAGE . $code;
    $email_subject = EMAIL_SUBJECT_EXTRA_EMAIL_WELCOME;</pre>
</div>Now those define statements can be placed into new files in corresponding language folders so they can be translated to suit whatever language the customer has selected while visiting the site.  The define statements would go into a file at <i>/includes/languages/NAME_OF_A_LANGUAGE_HERE/extra_definitions/send_extra_email_at_welcome.php</i>.<br />
<br />
<br />
This blog post was inspired from the more specific use-case discussed on the forum at: <a href="http://www.zen-cart.com/showthread.php?199729-How-to-assign-unique-account-numbers-OR-usernames&amp;p=1148601#post1148601" target="_blank">http://www.zen-cart.com/showthread.p...01#post1148601</a></blockquote>

]]></content:encoded>
			<dc:creator>DrByte</dc:creator>
			<guid isPermaLink="true">http://www.zen-cart.com/entry.php?4-Creating-an-Observer-Class-send-a-specialized-additional-email-during-Create-Account</guid>
		</item>
		<item>
			<title>How do I rebuild my site on the new version, instead of upgrading?</title>
			<link>http://www.zen-cart.com/entry.php?3-How-do-I-rebuild-my-site-on-the-new-version-instead-of-upgrading</link>
			<pubDate>Mon, 03 Sep 2012 23:12:37 GMT</pubDate>
			<description><![CDATA[TL;DR / Executive Summary:  
Are you looking for a quick way to understand *best practices when upgrading* your Zen Cart site?  The easiest way to view it is as "a rebuild while keeping all the existing data."   
 
This article contains 3 sections: 
 1. What an upgrade is, and what it is not. 
2....]]></description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore"><i>TL;DR / Executive Summary: </i><br />
Are you looking for a quick way to understand <b>best practices when upgrading</b> your Zen Cart site?  The easiest way to view it is as &quot;a rebuild while keeping all the existing data.&quot;  <br />
<br />
This article contains 3 sections:<br />
<i> 1. What an upgrade is, and what it is not.<br />
2. An overview of how to rebuild a site using the new version, instead of upgrading.<br />
3. How to upgrade while keeping the store live, and not losing any sales/customer/product data.</i><br />
<br />
<br />
<b><font size="4">What is an upgrade anyway?</font></b><br />
<br />
I've observed a number of misconceptions about what it means to upgrade a Zen Cart store from one ZC version to another.  <br />
<br />
Some people come at it from the angle of having used other frameworks that do things in different ways, or from any of a number of popular CMS systems that are architected differently perhaps with more of a plugin-style architecture where code or feature customizations are housed externally. In all of these cases the idea of &quot;upgrading&quot; comes with many preconceptions, and when the person discovers that upgrading in Zen Cart is done differently, they dig their heels in and object and complain that it should work the same as &quot;XYZ&quot; other software application.<br />
Curiously, the same behavior is exhibited when someone comes to Zen Cart looking to set up a store or template, and discovers that ZC doesn't use Smarty or some other templating system that they're already familiar with, and they find that frustrating … because they have to learn another way of doing things.<br />
<br />
<i>It's not wrong. It's just different.</i><br />
<br />
The v1.x.x architecture of Zen Cart does &quot;separate the business logic from the presentation logic&quot;, which thankfully allows most upgrades to have minimal impact on templates specifically. But when it comes to other core components, many times a number of core files must be touched. And while this in itself is not usually a big deal, it does get complicated when someone has installed a number of 3rd-party addons which have altered core code functionality.  It's also particularly complicated when a new version NEEDS to change a LOT of files in order to integrate new features that have been in high demand. While v2 is being built to have more of a plugin architecture, the v1.x series requires a little bit of care when upgrading.<br />
<br />
Anyway, back to the misconceptions…<br />
<br />
In summary, a Zen Cart upgrade in version 1.x.x …<br />
<ul><li style="">is NOT merely a &quot;replace these 5 files&quot; exercise.  (There are often 20-50 files affected)</li><li style="">is NOT a magical &quot;click this button and you're suddenly on the new version&quot;. (There is no reliable &quot;one-click upgrade&quot; feature yet. Stay tuned for v2.)</li><li style=""><b>IS</b> a quick <b>rebuild</b> of your site   (quick meaning that it's way faster than when you built it the first time, since you already have a frame of reference)</li><li style=""><b>DOES keep your existing data</b> intact </li></ul><br />
 <br />
<b> The EASIEST way to conceptualize an upgrade is that it's an accelerated re-build of your site, using the new version, and keeping all your existing store data/configuration.</b><br />
<br />
Now … DON'T LET THAT word &quot;rebuild&quot; scare you!  IT WILL NOT TAKE AS LONG to upgrade as it did to build your site in the first place!!<br />
Maybe the first time you set up your store it took you a few weeks … mostly because you were starting green, had no idea what a template was or where to put your graphics or product images, etc. But since your existing site is now a map of all the things you've done to customize your site, the rebuild is a much shorter exercise.<br />
<br />
<br />
<font size="4"><b>How do I rebuild my site on the new version, instead of upgrading?</b></font><br />
<br />
Well, an upgrade *is* basically a rebuild.  At least, that's what I find to be the simplest approach to take when upgrading.<br />
<br />
In a nutshell, an upgrade is simply this:<br />
<br />
<b>a) make a list of all your existing customizations</b><br />
    - This includes all your addons/plugins, templates, custom features, etc<br />
    - There are handy file-comparison tools that help you quickly see any changes/additions/deletions you've made<br />
    - If you've already made good notes about your own customizations over the years, these notes will be very handy checklists/references for the next stage<br />
<br />
<b>b) re-make those on the new version</b><br />
     - installing updated addons/plugins designed for the new version, if necessary<br />
     - adding any small templating changes from the new version into a new copy of your existing template, or maybe using a new template altogether if that suits<br />
     - re-making your custom coding changes into the new version's files<br />
     - sometimes it might mean merging changes from the new version's core files into your own customized files, and/or vice-versa. This is no different than what you need to do when installing two addons that touch the same files, since their unique changes need to be merged together before they can be safely used together anyway.<br />
<br />
<b>c) upgrade the database to the new version </b><br />
     The zc_install script is used to do this in an automated way. Just a couple clicks to take care of keeping all your data intact and bringing its data structure up-to-date to work with the new version.<br />
<br />
<b>And of course, doing all of this in a TEST COPY of your site first, not on your live site directly,</b> lets you ensure that everything is working and nothing is missed, before putting it all onto the live site. This way, when it comes time to actually touch your live site, you can do it in just a few minutes instead of potentially having your store down for much longer while testing/checking addons and customizations, etc.<br />
<br />
<br />
<br />
<font size="4"><b>How do I do an upgrade and still keep my live store running in the meantime?</b></font><br />
<br />
You're a busy storeowner. You know you need to keep the business running while you safely test your upgrade, and you don't want to lose any data in the process.<br />
<br />
The SMARTEST way to do that is this:<br />
<br />
a)<b> keep your live store running, as-is.</b> With its own admin. Its own database. Its own folder of files on the server. Everything as-is.<br />
<br />
b) <b>build your new store in a temporary location</b>. THIS IS ONLY FOR TESTING AND PREPARING FOR LIVE DEPLOYMENT. <br />
This separate testing area will use a complete copy of your live site, in another subdirectory of your site, AND another database.<br />
This is done following the main upgrade procedure as described in steps a), b), c) above, and in more detail at this FAQ article: <a href="http://www.zen-cart.com/content.php?148-how-do-i-upgrade-my-zen-cart-site" target="_blank">http://www.zen-cart.com/content.php?...-zen-cart-site</a>  <br />
REMEMBER: Any settings you adjust in your Admin, and any SQL scripts you run against your database will need to be re-done after &quot;going live&quot;. SO TAKE REALLY GOOD NOTES so you know all the things you need to do again.<br />
Same with any addons that you install. You'll need to re-run their installation process and configure them, since their setup won't be present in that database until you do. (See next step to understand these last 2 statements better.)<br />
<br />
c) <b>once you're ready to &quot;go live&quot;, your temporary &quot;new&quot; store will be out-of-date</b> because you'll have new customers, new orders, new payments, new products, etc in the live store.<br />
So, you simply upgrade your live shop (since it has the most current data):<br />
(THIS IS *AFTER* YOU'VE BUILT AND TESTED YOUR &quot;TEST&quot; SITE IN PREPARATION)<br />
You can do this upgrade now on your live site BECAUSE you've already done all the testing and preparation in a temporary space. <br />
This is the only scenario when you should upgrade your live site directly!<br />
<br />
Pick a time when your live store is less-busy. This might be a typically &quot;slow day&quot;, or an evening or a weekend, depending on your business. Follow these steps:<br />
      <br />
<ol class="decimal"><li style="">Put your live shop down for maintenance  (Admin-&gt;Configuration-&gt;Website Maintenance-&gt;first option, turn it on)</li><li style="">Backup your live database for safekeeping <a href="http://www.zen-cart.com/content.php?144-how-can-i-do-a-database-backup-with-phpmyadmin" target="_blank">http://www.zen-cart.com/content.php?...ith-phpmyadmin</a><br />
It's also wise to backup all your existing  php files/folders, images, etc … everything in your hosting account.</li><li style="">Replace all the Zen Cart php files/folders/images/everything in your live store with the new files (except the configure.php files which usually stay the same)<br />
Be sure to also delete any files that don't belong anymore.</li><li style="">Upload all the files for the zc_install folder, and run zc_install/index.php and choose database-upgrade</li><li style="">Re-do any admin settings and SQL changes, new addons/modules, etc relevant to the new setup.<br />
Refer to the list of notes you took while you did any additional customizing in your temporary site</li><li style="">Turn off down-for-maintenance</li><li style="">Do a test transaction to be sure checkout works<br />
And browse around all the pages to make sure things are working correctly.</li><li style="">Do another backup of everything for peace-of-mind.</li><li style="">Take a deep breath. :) </li></ol><br />
 <br />
<br />
<i>TIP: You *could* do a &quot;trial run&quot; of this whole upgrade process by making ANOTHER copy of your live site and doing<br />
 this upgrade to that site. Then you'll have either a checklist of additional things you'd missed, or you'll have simply the peace-of-mind of knowing that your live upgrade will go smoothly.<br />
In fact, this is what I always do!</i><br />
<br />
d) You can <b>then delete your temporary site</b> (files and database) because it's no longer needed. It was only ever used for &quot;staging&quot; to prepare yourself for the actual live upgrade of the live shop.<br />
<br />
<br />
<u><b> ADDENDUM:</b></u><br />
If you are considering changing webservers or hosting companies, do ALL of your upgrade activities BEFORE or AFTER the move. NOT DURING. If you confuse the picture by doing an upgrade at the same time, then you make it nearly impossible to determine whether your problems are the result of &quot;moving&quot; or a result of errors in &quot;upgrading&quot;. So, always upgrade before OR after, but never &quot;during&quot; a move.<br />
More about moving to another server here: <a href="http://www.zen-cart.com/content.php?142-i-want-to-move-my-zen-cart-installation-to-another-host-or-a-different-server" target="_blank">http://www.zen-cart.com/content.php?...fferent-server</a></blockquote>

]]></content:encoded>
			<dc:creator>DrByte</dc:creator>
			<guid isPermaLink="true">http://www.zen-cart.com/entry.php?3-How-do-I-rebuild-my-site-on-the-new-version-instead-of-upgrading</guid>
		</item>
		<item>
			<title>Is your code safe to use on PHP 5.3?</title>
			<link>http://www.zen-cart.com/entry.php?2-Is-your-code-safe-to-use-on-PHP-5-3</link>
			<pubDate>Sun, 02 Sep 2012 21:04:31 GMT</pubDate>
			<description><![CDATA[When PHP 5.3 was released, some older features were retired (some removed, some "deprecated", etc). 
 
And if your custom code or your addons/plugins are using those features, things will break and you'll encounter the dreaded "white screen of death"...]]></description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">When PHP 5.3 was released, some older features were retired (some removed, some &quot;deprecated&quot;, etc).<br />
<br />
And if your custom code or your addons/plugins are using those features, things will break and you'll encounter <a href="http://www.zen-cart.com/content.php?124-blank-page" target="_blank">the dreaded &quot;white screen of death&quot;</a>.<br />
<br />
<b>What do you need to change?<br />
</b><br />
Here's the list I generally follow, along with how I usually remedy it:<br />
<br />
<b>ereg</b>('searchtext', 'a_string', $optionalVar)  becomes  <b>preg_match</b>('<b>/</b>searchtext<b>/</b>', 'a_string', $optionalVar)<br />
<br />
<b>eregi</b>('searchtext', 'a_string', $optionalVar)  becomes  <b>preg_match</b>('<b>/</b>searchtext<b>/i</b>', 'a_string', $optionalVar)<br />
<br />
<b>ereg_replace</b>('searchtext',.....) becomes  <b>preg_replace</b>('<b>/</b>searchtext<b>/</b>',....);<br />
or if the 'searchtext' parameter is just a single character then just change <b>ereg_replace</b> with <b>str_replace</b><br />
<br />
<b>eregi_replace</b>('searchtext',.....) becomes <b>preg_replace</b>('<b>/</b>searchtext<b>/i</b>',....);<br />
<br />
<br />
<b>split</b>('x', $var) <br />
- if 'x' is a single character, then <b>split</b>( becomes <b>explode</b>(<br />
- if 'x' is multiple characters, then <b>split</b>('chars', $var) becomes <b>preg_split</b>('<b>/</b>chars<b>/</b>', $var)<br />
<br />
<u>&quot;short open tags&quot;<br />
</u>Normally PHP files start with a &lt;?php tag <br />
or individual PHP statements start with &lt;?php<br />
But some commonly-used &quot;shortcuts&quot; require the use of &quot;short open tags&quot;, such as just <b>&lt;?</b> instead of &lt;?php.<br />
However, in PHP 5.3 the &quot;short open tags&quot; support is turned off by default, and if your code uses these &quot;short&quot; tags, you will cause errors, resulting in a blank page.<br />
So, if your code uses <b>&lt;?</b> followed by a space, change those to <b>&lt;?php</b><br />
If it uses <b>&lt;?=</b> then change those to <b>&lt;?php echo</b><br />
<br />
<br />
That's the bulk of it. Making those changes should accommodate the majority of issues you might encounter when moving from PHP 5.2 to PHP 5.3<br />
<br />
<br />
If you're working with very old code, or stuff that was inherited or ported from other systems, the following could be relevant to you as well:<br />
<br />
<u>Some very old things<br />
</u>The following session-related functions have been obsolete for quite awhile. Zen Cart has never used them, but people using old code converted from old OSC addons might still try to make use of them. <br />
- session_register()<br />
- session_unregister()<br />
- session_is_registered()<br />
Instead, write new logic to handle sessions in a contemporary way.<br />
<br />
$HTTP_POST_VARS and $HTTP_GET_VARS and $HTTP_SERVER_VARS, etc are all officially deprecated. Also never used by Zen Cart, but used extensively in old OSC addons. They should be replaced with their $_POST, $_GET, $_SERVER, etc superglobal equivalents.  And never need to be declared as globals. See below.<br />
<br />
<u>Global vars<br />
</u>Another pattern I've seen carried forward from old OSC addons is the choice to explicitly declare $_POST or $_GET as global inside a function/method.  But, $_POST and $_GET (and other $_XXXXX superglobals) are already global.<br />
So, in a PHP statement that starts with global and includes one of these superglobals, that superglobal can be removed from that statement. And if no other variables are mentioned, the whole statement can be removed.<br />
ie: global $var1, $_POST, $var2; becomes global $var1, $var2;<br />
or global $_POST; would just be removed altogether.<br />
<br />
<br />
-------------------------------<br />
Related reading:<br />
<a href="http://www.php.net/manual/en/migration53.deprecated.php" target="_blank" rel="nofollow">http://www.php.net/manual/en/migration53.deprecated.php</a></blockquote>

]]></content:encoded>
			<dc:creator>DrByte</dc:creator>
			<guid isPermaLink="true">http://www.zen-cart.com/entry.php?2-Is-your-code-safe-to-use-on-PHP-5-3</guid>
		</item>
	</channel>
</rss>
