8/28/2014

Used Little-Known Way to Improve eCommerce Conversions


When an online shopper lands on a website, a substantial amount of trust needs to be build in order to get their sale.
With the number of sites available, it’s difficult for them to know which ones are safe and whether entering their personal information could result in fraud.

6/16/2013

What is Helper in Magento

Magento's Helper classes contain utility methods that will allow you to perform common tasks on objects and variables. For example:
$helper = Mage::helper('catalog');
You'll notice we've left off the second part of the grouped class name. Each Module has a default Data Helper class. The following is equivalent to the above:
$helper = Mage::helper('catalog/data');
Most Helpers inherit form Mage_Core_Helper_Abstract, which gives you several useful methods by default.

$translated_output =  $helper->__('Magento is Great'); //gettext style translationsif($helper->isModuleOutputEnabled()): //is output for this module on or off?

What is Singleton in Magento

First, before we get to Magento, it's important to understand that PHP has a radically different process model than Java.  A PHP singleton (regardless of Magento's involvement) is a single instance of a class per HTTP Request.  A PHP program isn't persistent in memory the same way a Java program is, so adjust your expectations of a "singleton" accordingly.  

Next, it's important to understand that Magento is a framework built on top of PHP, using PHP, and in many cases the original Magento developers wanted to push things towards a more Java like architecture.  So, you're going to see things that look familiar, are familiar, but likely differ in some major way from what you're used to because they still need to hew to PHP's version of the universe.

Magento uses a factory pattern to instantiate Helpers, Blocks, and "Model" classes.  The string

core/session

is a class alias.  This alias is used to lookup a class name in Magento's configuration. In short, this string is converted into path expressions that search Magento's configuration files to derive a classname, based on the context (helper, block, model) it was called in. For a longer version, see my Magento's Class Instantiation Autoload article.

The concept of a "Model" is a little fuzzy in Magento.  In some cases models are used as domain, or service models.  In other cases they're used as a more traditional middleware database persistence models.  After working with the system for a few years, I think the safest way to think about Models is they're Magento's attempt to do away with direct class instantiation.

There's two ways to instantiate a model class.

Mage::getModel('groupname/classname');
Mage::getSingleton('groupname/classname');

The first form will get you a new class instance.  The second form will get you a singleton class instance.  This particular Magento abstraction allows you to create a singleton out of any Magento model class, but only if you stick to Magento's instantiation methods.  That is, if you call

Mage::getSingleton('groupname/classname');

then subsequent calls to

Mage::getSingleton('groupname/classname');

will return that singleton instance.  (This is implemented with a registry pattern). However, there's nothing stopping you from directly instantiating a new instance of the class with either

$o = Mage::getModel('groupname/classname');
$o = new Mage_Groupname_Model_Classname();

Which brings us to sessions.  PHP's request model, like HTTP, was originally designed to be stateless.  Each request comes into the system with, and only with, information from the user.  As the language (and the web) moved towards being an application platform, a system that allowed information to be persisted was introduced to replace the homegrown systems that were cropping up.  This system was called sessions.  PHP sessions work by exposing a super global $SESSIONS array to the end-user-programmer that allow information to be stored on a per web-user basis.  Sessions are implemented by setting a unique ID as a cookie on the user end, and then using that cookie as a lookup key (also standard practice for web applications)

In turn, the Magento system builds an abstraction on top of PHP's session abstraction.  In Magento, you can create a "session model" that inherits from a base session class, set data members on it, and save/load those data members just as you would with a database persistence model.  The difference is information is stored in the session instead of the database store. When you see

core/session
customer/session

these are two different session models, with each one storing different data. One belongs to the Mage_Core module, the other belongs to the Mage_Customer model.  This systems allows modules to safely set and manipulate their own session data, without accidentally stepping on another module's toes, and provide logical class methods for manipulating that data.

Hopefully that answers the questions you asked, as well as the ones you didn't.

6/04/2013

Catalog Search not returning expected results in Magento

Many customers complain about Magento's default catalog search results. Here is the solution to get better results from Magento Catalog Search.

1. Copy app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php to app/code/local/Mage/CatalogSearch/Model/Resource/ folder and open file.

2. Navigate to function prepareResult() and find below set of code:

$words = Mage::helper('core/string')->splitWords($queryText, true, $query->getMaxQueryWords());
foreach ($words as $word) {
$like[] = $helper->getCILike('s.data_index', $word, array('position' => 'any'));
}

and replace it with:

$like[] = '`s`.`data_index` LIKE :likew';
$bind[':likew'] = '%' . $queryText . '%';

Next replace

$likeCond = '(' . join(' OR ', $like) . ')';

with

$likeCond = '(' . join(' AND ', $like) . ')';

3. Login to Admin Panel of your magento. Navigate to System --> Configuration.

4. Now click on  Catalog --> Catalog tab on left. In Catalog Search panel, set Search Type to like.

5. Just reindex all data and your store's search should be working fine now.
 
This process was tested on magento version 1.7.0 and  above.

2/16/2013

Magento: Redirect to login page if user not login

Here is simple magento code to redirect to login page, if user is not logged in:

<?php
    $redirect_url = Mage::getUrl('customer/account/login/');
    $current_url = Mage::helper('core/url')->getCurrentUrl();
    if((!$this->helper('customer')->isLoggedIn()) && ($current_url != $redirect_url)){
        Mage::app()->getFrontController()->getResponse()->setRedirect($redirect_url);
    }
?>

Use this code and enjoy.. :)

12/05/2012

Magento: How to setup multiple currency shop

To setup Multiple currencies for magento store is very easy. To do so, just follow below steps:


1. Login to admin panel of your website.
2. Go to System --> Configuration, then select Currency Setup from General tab.



        Then select values for Base currency, Default display currency and Allowed currencies and Save Config button.



Note: Press Control key of key board while selecting multiple options from Allowed Currencies section.

Magento still does not know about currency rates for newly selected currencies. To let magento know about currency interchange rates, follow step #3.

3. Go to System --> Manage Currency --> Rates.



        Just click on Import button on top right side. Now click on Save Currency Rates button.



Note: You can provide values manually also, but it is recommended to import rates from web service.

That's all.. refresh magento cache and you are done. Now on frontend prices of products can be displayed in the currencies you configured.

Magento: How To Set Up Multiple Languages in Magento


In order to configure a different language for your store, you need to follow a simple procedure:

1. First go to http://www.magentocommerce.com/translations, where you will find various language translations packs for default Magento interface.
        Download the language pack for the desired language, extract and paste the extracted files to respective places in your Magento directory.
         or
You can install it directly by searching and installing through Magento Connect.

2. Now go to Admin Panel, then go to System --> Manage Stores.



        Click on Create Store View button.
Select Store, provide appropriate value for Name and code, and select Enabled from Status dropdown. Click on Save Store View button.

3. Now go to System --> Configuration and Select Store View (which you created in step #2).
Clicking on General tab (on left side), you will see Locale Options on right side. Select installed Language from Locale dropdown. Save Config.



and you are done. Just Clear Magento Cache Storage and see reflection on frontend of you website.