I recently had to “hide” a fully working Magento site due to an upgrade.
However the client insisted on having a working “sign up to my newsletter” box on the holding page too, and wanted all the collected email addresses to be collected in Magento as normal, and not in Mailchimp or any other newsletter program.
So I rolled up my sleeves and tried to figure out how to do it. This is the quick and dirty way I ended up doing it.
First I created my holding page in a separate folder called holdingpage\index.php
(I based it on an existing page from the Magento site, by copying the source HTML and slicing out bits I didn’t need.)
Then I edited the .htaccess so that this page was always redirected to. (there are several posts out there on how to do it but here’s my take on it)
Change the follwoing line:
DirectoryIndex index.php
to
DirectoryIndex holdingpage/index.php
and also change
RewriteRule .* index.php [L]
to
RewriteRule .* holdingpage/index.php [L]
(obviously if you want to undo these changes at a later date I suggest you just comment out the old line by preceding it with a ‘#’)
Now that seemed to do the trick that everything was going to my new holding page. First task done.
Next I had to figure out how to get that newsletter subscribe working. Now I’m not a huge fan of Magento as it seems to over complicate a lot of stuff (and is mightily slow etc etc) so cover your eyes people if you are a fan of code purity.
I used regular PHP and MySQl to get this done. Turns out the newsletter_subscribers table isn’t one of the ones that is used in all the Magento indexing, so I could just update it using a regular MySQL statement.
I added the following code to the top of my index.php
<?php if($_POST["email"]!=""){ global $con; $con = mysql_connect("DBHOSTNAME","DBUSERNAME","DBPASSWORD"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("DBNAME", $con); $strSQL="INSERT INTO `newsletter_subscriber` (`subscriber_id`, `store_id`, `change_status_at`, `customer_id`, `subscriber_email`, `subscriber_status`, `subscriber_confirm_code`) VALUES (NULL, '1', NULL, '0', '".$_POST["email"]."', '1', 'NULL');"; mysql_query($strSQL); } ?>
Note: I only have 1 store so have hardcoded those values
I added the following block just below the heading area of my holding page to generate a friendly message on sucessful subscription.
<? if($_GET["subscribe"]==1){?> <ul> <li> <ul><li><span> Thank you for subscribing to our newsletter. You'll hear from us soon... </span></li></ul> </li> </ul> <? } ?>
And the subscribe form is just:
<div> <div> <strong><span>Join Our Mailing List</span></strong> </div> <form id="newsletter-validate-detail" method="post" action="/newsletter/subscriber/new/?subscribe=1"> <div> <label for="newsletter"></label> <input type="text" value="enter your email address" title="Sign up for our newsletter" id="newsletter" name="email" onfocus="if(this.value=='enter your email address'){this.value=''}" onblur="if(this.value==''){this.value='enter your email address'}"> <div> <button title="SUBMIT" type="submit"><span><span>SUBMIT</span></span></button> </div> </div> </form> <script type="text/javascript"> //<![CDATA[ var newsletterSubscriberFormDetail = new VarienForm('newsletter-validate-detail'); //]]> </script> </div>
Which the eagle-eyed of you will notice is just the default Magento HTML it generates for a subscribe box. Note: I have addedd subscribe=1 to the action parameter of the form too, which is used to display the message.
I admit its not pretty but it is quick and dirty and most importantly it works!
Nice job. What a pain Magento can be. This will help next time I need to do some maintenance.
Also, I was wondering about sub pages
magento/bargins or magento/about-us etc.