Magento Quick Personalisation

Magento doesn’t have any personalisation features out of the box and a lot of the companies that do personalisation for Magento charge a lot of money. I needed a quick free fix. I recently had to ensure that some content on a my account page within Magento was personalised to that customer. Pretty easy I though grab the customers email address that they used to login with, create a few arrays, and then output different information depending on which array they were in. The code is a little crude but provided me a quick fix, I’m probably now going to take this a little further and see if I can use a database table rather than sticking the email addresses in an array. This code can be used on any template page where the customer is logged in. I know someone would probably tell me this isn’t the safest way to do it so don’t include any sensitive information.

 

This is the code that I used:

<?php

if (Mage::getSingleton(‘customer/session’)->isLoggedIn()) {

//Check that the customer is login and return their credentials
$customer = Mage::getSingleton(‘customer/session’)->getCustomer();

//Get customers email address
$somevariable = $customer->getEmail();

//Email addresses
$array1 = array(
“email@msn.com”,
“email@sky.com”);

//Email addresses
$array2 = array(
“email@btinternet.com”,
“email@mbs.edu”);

//Email addresses
$array3 = array(
“email@gmail.com”,
“email@gmail.com”);

//Email addresses
$array4 = array(
“email@gmail.com”,
“email@gmail.com”);

//Email addresses
$array5 = array(
“email@btinternet.com”,
“email@hotmail.com”);

//Email addresses
$array6 = array(
“email@sky.com”,
“email@gmail.com”);
if (in_array($variable123, $array1, TRUE)){
echo “Content Array 1″;
}

elseif(in_array($variable123, $array2, TRUE)){
echo “Content Array 2″;
}

elseif(in_array($variable123, $array3, TRUE)){
echo “Content Array 3″;
}

elseif(in_array($variable123, $array4, TRUE)){
echo “Content Array 4″;
}

elseif(in_array($variable123, $array5, TRUE)){
echo “Content Array 5″;
}

elseif(in_array($variable123, $array6, TRUE)){
echo “Content Array 6″;
}

else {
echo “Content not in array”;
}
}

?>

 

Magento | | No Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

« »