How to Integrate Live Chat in your magento store



If you look at the right-bottom of this page, you will notice a nice looking chat widget. Yes that’s the Zopim Live Chat.

If you want to interact with your visitors, give support to them, know the statistics of the visits, get offline messages etc. then Zopim Live Chat seems to be very promising choice.

Integration of Zopim Live Chat

If you want to add Zopim Live Chat to your Magento Store, you don’t need to use any third party modules as it is so simple & straight forward to use.

Integration Steps:

  1. Sign up with Zopim

    Visit Zopim site to sign up/create a account. Once you complete the sign up form then you will get a confirmation link in your mail for verification. Once confirmed your account is ready to use the Zopim Live Chat widget.
    Related Snaps:

  2. zopim-chat-step1


  3. Grap the Widget Code

    Login to the Zopim Dashboard page with the credentials used during sign up. After login, click on the Settings tab on the top right then you can see the following screen:
    When you are in Settings section,then you can see two tabs on the left: ‘Embed widget on my site‘ & ‘Customize widget‘.

    Embed widget on my site‘ -> When you click on this tab you will see the script ready for copy-paste in Magento.
    Customize widget‘ -> Click on this tab if you want to customize the look and feel, default text, position etc of your chat widget.

  4. Insert the Widget Code in Magento

    After getting the Widget code(Zopim Dashboard > Settings > Embed widget on my site) from Zopim Site, login to the Magento and go to:
    System > Configuration > General > Design > Footer > Miscellaneous HTML > Paste the widget code here..

  5. dashboard-settings

   4. You’re done 🙂

Refresh the cache and load the frontend page, you will see the sexy chat widget ready for interaction


Magento Design Patterns : Magento Uses 12 Design patterns


1. Model View Controller Pattern

Model View Controller, MVC for short, is a design pattern where business, presentation and coupling logic are separated. Magento heavily utilizes XML as templating-logic and HTML mixed with PHP files for its views. Models are backed by Varien’s ORM. Most business logic happens in the models whereas the controllers map the model-data to the views.

Because Magento its views are “fat” – they often contain a lot of logic – its not rare that views have an additional PHP class (the Block system) which will help with rendering.

2. Front Controller Pattern

The front controller pattern makes sure that there is one and only one point of entry. All requests are investigated, routed to the designated controller and then processed accordingly to the specification. The front controller is responsible of initializing the environment and routing requests to designated controllers.

Magento has only one point of entry ( index.php) which will initialize the application environment ( Mage::app()) and route the request to the correct controller.

3. Factory Pattern

As implied by the name, the factory pattern is responsible of factorizing (instantiating) classes. It’s widely used through the Magento code base and leverages the autoloading system in Magento. By defining an alias in a module its config.xml you are letting the factory know where it can find classes.

There are various factory-helper methods in the Mage core class and one of them is getModel(). It accepts an alias for a class and will then return an instance of it. Instead of having include calls scattered through the code base, the factory pattern will instantiate classes in an uniform way.

4. Singleton Pattern

Another way to retrieve an instance of a class, is to call Mage::getSingleton(). It accepts a class alias and before returning an instance, it checks the internal registry whether this class has already been instantiated before – this results in a shared instance. An example of where this is mandatory, is the session storage which should be shared through the code base instead of creating it anew every time.

5. Registry Pattern

All the singletons are stored in the internal registry: a global scoped container for storing data. It is not only for internal use. The Mage::register($key, $value), ::registry($key) and ::unregister($key) methods can be respectively used for storing, retrieving and removing data from the registry. The registry is often used for transferring data between scopes when they cannot be passed on, otherwise.

6. Prototype Pattern

Where the factory pattern (#3 on our list) stops, is where the prototype pattern continues. It defines that instances of classes can retrieve a specific other class instance depending on its parent class (the prototype). A notable example is the Mage_Catalog_Model_Product class which has a getTypeInstance method to retrieve the specific Mage_Catalog_Model_Product_Type with a specific subset of methods and properties not applicable to all products.

For example, the Mage_Downloadable_Model_Product_Type ultimately extends the Mage_Catalog_Model_Product_Type. If you are iterating over an order and want to call a specific method of a downloadable product, you will need to factorize it first with the getTypeInstance method of the original product.

7. Object Pool Pattern

The object pool pattern is simply a box with objects so that they do not have to be allocated and destroyed over and over again. It’s not used a lot in Magento other than for heavy tasks where resources can get limited soon, like importing products. The object pool (managed by Varien_Object_Cache) can be accessed with Mage::objects().

8. Iterator Pattern

The iterator pattern defines that there is a shared way to iterate over a container with objects. In Magento, this is handled by the Varien_Data_Collection which on its turn uses various baked-in PHP classes (like ArrayIterator) for having a more OO-interface to arrays. This ensures that model-collections will always have a common API to iterate over without being dependent of the actual models.

9. Lazy Loading Pattern

Lazy loading ensures that loading data is delayed until the point when it is actually needed. This results in less resources being used. One of the lazy loading behaviors of Magento is that of collections. If you were to retrieve a collection of products with Mage::getModel(‘catalog/product’)->getCollection(), the database will only be touched when you actually access the collection by, for example, iterating over it or retrieving the count of models found.

10. Service Locator Pattern

The service locator pattern abstracts away the retrieval of a certain service. This allows for changing the service without breaking anything (as it adheres to its abstract foundation) but also fetching the service as seen fit for its purpose.

Ryan exemplifies this with database connections. Another example is that of Magento its caching mechanism where Mage::getCache() is a service locator by-proxy for the cache storage supplied by Zend or other vendors.

11. Module Pattern

Anyone familiar with Magento development has stumbled upon the module pattern. It basically defines that different domains are grouped into separate modules which function independent of each other and can be plugged-in to the main system as deemed appropriate. In an ideal situation, an implementation of the module pattern would make sure that each element can be removed or swapped. One of the protagonists of the module pattern in PHP is the Composer package manager.

Though Magento heavily relies on a modular architecture, its not modular to the bone. Certain functionality is heavily tied to the core and can not be easily changed. There is also the heavy usage of the super-global Mage core-class which introduces all sorts of system-wide dependencies not easily overseen.

12. Observer Pattern

Magento its event-driven architecture is a result of an implementation of the observer pattern. By defining observers (or listeners), extra code can be hooked which will be called upon as the observed event fires. Magento uses its XML-data storage to define observers. If an event is fired with Mage::dispatchEvent($eventName, $data), the data storage will be consulted and the appropriate observers for $event will be fired.


Difference between Mage::getModel() and Mage::getSingleton() in Magento


Mage::getModel() will create a new instance of an object each time even such object exists in configuration.


$prod1 = Mage::getModel('catalog/product');
$prod2 = Mage::getModel('catalog/product');

$prod1 and $prod2 both have different instant of same object and also occupy different memory .


Mage::getSingleton() will first check the same class instance is exits or not in memory. If the instance is created then it will return the same object from memory. So Mage::getSingleton() faster then Mage::getModel().

$prod1 = Mage::getSingleton('catalog/product');
$prod2 = Mage::getSingleton('catalog/product');

$prod1 and $prod2 both will share same memory of OS and return only one instance each time.

MySQL is the second most widely used open-source relational database management system in the world. It has become so popular because of its consistent fast performance, high reliability and ease of use. This article presents some of the best practices in MySQL.

1.Use CHAR (1) over VARCHAR(1)

If you are string a single character, use CHAR(1) instead of VARCHAR(1) because VARCHAR(1) will take extra byte to store information

2.Avoid using regional date formats

When you use DATETIME or DATE datatype always use YYYY-MM-DD date format or ISO date format that suits your SQL Engine. Other regional formats like DD-MM-YYY, MM-DD-YYYY will not be stored properly.

3.Always use proper datatype

Use datatypes based on the nature of data. If you use irrelevant datatypes it may consume more space or may lead to errors.

Example: Using varchar (20) to store date time values instead of DATETIME datatype will lead to errors during date time related calculations and there is also possible case of storing invalid data.

4.Use CHAR datatype to store only fixed length data

Example: Using char(1000) instead of varchar(1000) will consume more space if the length of data is less than 1000

5. Index key columns

Make sure to index the columns which are used in JOIN clauses so that the query returns the result fast.

If you use UPDATE statement that involves more than one table make sure that all the columns which are used to join the tables are indexed

6. Do not use functions over indexed columns

Using functions over indexed columns defeats the purpose of index. Suppose you want to get data where first two character of customer code is AK, do not write

SELECT columns FROM table WHERE left (customer_code,2)=’AK’

but rewrite it using

SELECT columns FROM table WHERE customer_code like ‘AK%’

which will make use of index which results to faster response time.

7. Use SELECT * only if needed

Do not just blindly use SELECT * in the code. If there are many columns in the table, all will get returned which will slow down the response time particularly if you send the result to a front end application.

Explicitly type out the column names which are actually needed.

8. Use ORDER BY Clause only if needed

If you want to show the result in front end application, let it ORDER the result set. Doing this in SQL may slow down the response time in the multi user environment.

9. Choose proper Database Engine

If you develop an application that reads data more often than writing (ex: search engine), choose MyISAM storage engine.

If you develop an application that writes data more often than reading (ex: real time bank transactions), choose INNODB storage engine.

Choosing wrong storage engine will affect the performance

10. Use EXISTS clause wherever needed

If you want to check the existence of data, do not use

If (SELECT count(*) from Table WHERE col=’smart’)>0

instead, use EXISTS clause

If EXISTS(SELECT * from Table WHERE col=’smart’)

which is faster in response time.

MySQL Can aborting a query with Ctrl-C harm the table?

Q :Can aborting queries harm the column that the query was operating on? If so, how can I recover from the problem?

A : If the transaction wasn’t completed, no. MySQL does ALTER TABLE by creating a new table and then updates the reference to the old table. You shouldn’t have altered your original table if you interrupted the original ALTER TABLE query.

The easiest way to terminate a renegade query is to use the MySQL shell as the root user:

This will give you a list of the current connections and a process ID for each one. To terminate any given query, such as number 19, use:

KILL 19;
Usually this will undo and roll back the query.

Validate Real Email Address Using MX record? send test mail to that real email address and if your message doesn’t bounce and it is safe to assume* that the address is real email address.

1.Ping an Email Address to Validate it! 

When you send an email to someone, the email message goes first to an SMTP server which then looks for the MX (Mail Exchange) records of the email recipient’s domain.

2.Enable telnet in Windows. Or if you already have the PuTTY utility, skip this step.

3.Open the command prompt and type the following command:

nslookup –type=mx
This command will extract and list the MX records of a domain as shown below. Replace with the domain of the email address that you are trying to verify. MX preference=30, exchanger = MX preference=20, exchanger = MX preference=5, exchanger = MX preference=10, exchanger = MX preference=40, exchanger =

a: Connect to the mail server:

telnet 25
b: Say hello to the other server

c: Identify yourself with some fictitious email address

mail from:<>

d: Type the recipient’s email address that you are trying to verify:

rcpt to:<>

The server response for ‘rcpt to’ command will give you an idea whether an email address is valid or not. You’ll get an “OK” if the address exists else a 550 error like: — The email account that you tried to reach does not exist. — The email account that you tried to reach is disabled.
That’s it! If the address is valid, you may perform a reverse email search to find the person behind the address

MX records to validate email addresses

function MXRecordVerify($emailaddress){
        list($user, $domain) = explode('@', $emailaddress);
        $arr= dns_get_record($domain,DNS_MX);
                return $arr[0]['target'];
$emailaddress= '';

if(MXRecordVerify($emailaddress)) {
        echo('This MX records exists; I will accept this email as valid.');
else {
        echo('No MX record exists;  Invalid email.');

Connect POP3 mailbox using PHP

Use the following process to connect to the inbox of a specific account:

$emailbox = imap_open(“{mail.domainname:110/pop3}INBOX”, ‘username’, ‘password’);

$emailinfo = imap_check($emailbox);

$nummessages = $emailinfo->Nmsgs;

if (stripos(imap_body($emailbox, $emailinfo->Nmsgs), ‘trigger phrase’) !== false) {

// Trigger detected



imap_open – returns a stream handler, it creates a connection to the mail server and returns it’s handler (the parameters are pretty obvious, the first one is the server data: host, port,protocol and folder, the second is the mailbox username and the third one is the password)

imap_check – returns mailbox data, this object’s Nmsgs property returns the number of new messages

imap_body – return the message with the number from the second parameter

imap_close – closes the stream



Run below file in your root directory it will fix your issue.

require_once ‘app/Mage.php’;
umask( 0 );
Mage :: app( “default” );
Mage::log(“Started Rebuilding Search Index At: ” . date(“d/m/y h:i:s”));
$sql = “truncate catalogsearch_fulltext;”;
$mysqli = Mage::getSingleton(‘core/resource’)->getConnection(‘core_write’);
$process = Mage::getModel(‘index/process’)->load(7);
Mage::log(“Finished Rebuilding Search Index At: ” . date(“d/m/y h:i:s”));



Magento has a very powerful admin configuration system. It allows you to create config forms to be able to configure your custom modules from admin panel, also to enable users to modify it.

t’s quite simple to do – and it should only take you a few minutes to implement this. But, the options are endless. You can add all sorts of custom configurable options that you can edit in the admin panel very easily.

Here my simplified module:


<?xml version=”1.0″?>

<title>My Module Section</title>



<?xml version=”1.0″ encoding=”UTF-8″?>
<mymodule translate=”label” module=”mymodule”>
<mymodule translate=”label” module=”mymodule”>
<label>My Module</label>
<schedep translate=”label”>
<label>My Module Settings</label>

<active translate=”label”>



class SWT_Mymodule_Helper_Data extends Mage_Core_Helper_Abstract {





class SWT_Mymodule_Model_Mymodule extends Mage_Core_Model_Abstract

protected function _construct()

protected function _beforeSave()
return parent::_beforeSave();