Sunday, September 25

How to add Newsletter Subscription Page in Magento

Magento has a nice inbuilt feature of Newsletter Subscription , but sometimes you may need to call it to a separate or CMS page. So, in order to do that, you can just use this code,

{{block type="newsletter/subscribe" template="newsletter/subscribe.phtml"}}

Just place it on your CMS page and clear your cache. Thats done.

Hope it Helps... Thanks

Saturday, September 17

How to Describing Flat Catalog in Magento

Difference between EAV and Flat Catalog

In EAV database model, data are stored in different smaller tables rather than storing in a single table.

Like,
product name is stored in catalog_product_entity_varchar table
product id is stored in catalog_product_entity_int table
product price is stored in catalog_product_entity_decimal table

EAV database model is used by Magento for easy upgrade and development as this model gives more flexibility to play with data and attributes.

When flat catalog is enabled in Magento then all the above product attributes (id, name, price) are kept in one table named like catalog_product_flat. Then Magento fetches product data from the flat table rather than joining all the other smaller tables.

There are two types of Flat Catalog:
1) Flat Catalog Product
2) Flat Catalog Category

- Flat Categories are recommended for any Magento installation for improved performance.
- Flat Products is designed and recommended for catalogs that have over 1000 SKU’s.

Enable Flat Catalog Category:

- Go to Admin Panel->System->Cache Management->Rebuild Flat Catalog Category
- Go to Admin Panel->System->Configuration->Catalog->Frontend->Use Flat Catalog Category = Yes

Enable Flat Catalog Product:

- Go to Admin Panel->System->Cache Management->Rebuild Flat Catalog Product
- Go to Admin Panel->System->Configuration->Catalog->Frontend->Use Flat Catalog Product = Yes

Remember that, initially the selection list of

Admin Panel->System->Configuration->Catalog->Frontend->Use Flat Catalog Product
OR,
Admin Panel->System->Configuration->Catalog->Frontend->Use Flat Catalog Product

is non-editable. You have to rebuild Flat Catalog from Cache Management. Only then the selection list becomes editable.

Hope it Helps... Thanks...

Tuesday, September 13

How to Change Decimal Point for Price Format in Magento

Sometime you need to play with the price format. magento default add 2 precision format for the price. now if you want to remove precision or want to keep 3 decimal point for price then you need to do following

1) Open /lib/zend/Currency.php file

2) Find 'precision' => 2 near line no. 78

here is the place, you need to change precision decimal

Change 'precision' => 0 if you want to keep 0 decimal


Hope it Helps... Thanks.....

How to Read and Write to the Database in Magento

Here is the script to read and write to the database in magento

READ QUERIES

// Prepare the SQL
$sql = "SELECT * FROM mytable";
// Execute the SQL and return the results in to $getData
$getData = Mage::getSingleton('core/resource')->getConnection('core_read')->fetchAll($sql);
// Parse the results
for($i=0; $i < count($getData); $i++){
    /* your code */
}
WRITE/UPDATE Queries
// $write is an instance of Zend_Db_Adapter_Abstract
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
// Prepare the SQL statement
$sql  = "insert into tablename values (?, ?, ?)";
// Execute the SQL
$write->query($sql);
 
while ($row = $write->fetch() ) {
  /* your code */
}

Hope it Helps.. Thnaks....

How to Add a javascript file to your magento page templates

Customising your magento store can be a good way to set your store apart from the competition so adding features that require javascript files is a common task when building a project. Learn how to include a javscript file into your magento page templates with this quick how to.The default layout template load is made primarily through the page.xml file located at the following url for custom themed installs /app/design/frontend/your-instance-name/your-theme-name/layout/page.xml , or for the default theme at /app/design/frontend/default/default/layout/page.xml.

Find the following block encapsulator and simply add the following command inside the block



Then upload you updated page.xml file.

With that done, you need to now upload your javascript file to /skin/frontend/your-instance-name/your-theme-name/js/yourscriptname.js, or for the default theme /skin/frontend/default/default/js/yourscriptname.js

Hope it Helps... Thanks....

Thursday, September 8

How to Remove Product from cart on checkout page or by coding in magento

From magento cart you can delete product by clicking on delete button from cart page , but if you wish to delete any cart item in checkout page or by coding then you have write

$session= Mage::getSingleton('checkout/session');
$quote = $session->getQuote();

$cart = Mage::getModel('checkout/cart');
$cartItems = $cart->getItems();
foreach ($cartItems as $item)
{
    $quote->removeItem($item->getId())->save();
}

By writing the above code your all cart item will be delete.If you wish to delete a particular product from the cart session then instead of writing $item->getId() pass your Id of the product.


for example
foreach ($cartItems as $item)
{
    if($item->getId()== 2)
    {
        $quote->removeItem($item->getId())->save();
    }
} 

Hope it Helps... Thanks...

How to adding new menu in magento admin panel

Here I have Created a new Module to Add new tab in admin panel of magento.
My Namesapce Name is Anjan and My Module name is Systab
As you know to make a module first we need to make a .XML file with Namespace_Module name under app/etc/modules/ folder. So My File name will be Anjan_Systab.xml

Now I will write the following code inside this xml



    
        
            true
            local
        
    
 

As My CodePool is local which is written in Anjan_Systab.xml I will create a Folder with name Anjan inside app/code/local/, then again will create another folder with name Systab inside Anjan Folder.Now I will create an etc folder inside the Systab Folder. Inside the etc folder I will create config.xml and will write the following code



    
        
            0.1.0
        
    
    
        
            
                standard
                
                    Anjan_Systab
                    systab
                
                                    
        
        
            
                
                    systab.xml
                
            
        
    
    
        
            
                admin
                
                    Anjan_Systab
                    systab
                
            
        
    
    
        
            
                My Tab
                71
                
                    
                        Manage Profile
                        0
                        systab/adminhtml_systab
                    
                
            
        
        
            
                
                    Allow Everything
                
                
                    
                        
                            
                                
                                    
                                        
                                            System Configuration Tab
                                        
                                    
                                
                            
                        
                        
                            System Configuration Tab
                            10
                        
                    
                
            
        
        
            
                
                    systab.xml
                
            
        
    
    
        
            
                Anjan_Systab_Model
                systab_mysql4
            
            
                Anjan_Systab_Model_Mysql4
                
                    
                        systab
Anjan_Systab core_setup core_write core_read Anjan_Systab_Block Anjan_Systab_Helper

Now Clear your magento cache and login to you admin panel You can see one Tab Named My Tab has been successfully created.

Hope it Helps... Thanks....

How to add new tab under system configuration in magento

n the last post I have showned , how to add new Tab in magento admin panel. Now in this post I will add new Tab under System->Configuration.To add so, You need to create a new module. Click here to create an admin Module then make some changes which is written here.

create a system.xml file inside etc folder of your module, Then write the following code to add a tab



    
        
            
            200
        
    
    
        
            separator-top
            
            systab
            100
            1
            1
            1
            
                
                    
                    text
                    10
                    1
                    1
                    1
                    
 
                            select
                            adminhtml/system_config_source_yesno
                            1
                            1
                            1
                            1
                        

                            
                            select
                            adminhtml/system_config_source_yesno
                            1
                            1
                            1
                            1
                        

                            
                            select
                            adminhtml/system_config_source_yesno
                            1
                            1
                            1
                            1
                        
                    

            
        
    
 

Now important things which needs to do. Go to your System->Cache Management then clear your all cache. Now go to System->Permissions->Roles. Clcik on Administrators, from Role Resources Tab select Resource Access All from the drop down and save. Now go to System ->Configuration .You can see a new tab has added in the left side.

Hope it Helps... Thanks....

How to create Special Product & Feature Product in magento

This is what I used many times while developed magento sites. I have made Feature products , Special Producst, Hot products etc by the custom attribute. To do so I am going to make some Special Product which will show on frontend, for this I will create a custom attribute Special Product whose code name will be special. First Log in to admin panel then Catalog->Attributes -> Manage Attributes . Now click on Add new Attribute, I n the Attribute Code field write special and from Catalog Input Type for Store Owner select Yes/No from the drop down, Choose NO from the Default Value .Now click on Manage Label / Options then in the Admin field write Special Product then click on Save Attribute button to save the attribute.

Now go to Catalog-> Attributes -> Manage Attribute Sets . Click on your Attribute set (e.g : - I choose Default attribute set) then add the Special attribute from Unassigned Attributes to Groups by drag and drop. Now go to any products which have same attribute set in which the Special Attribute is assign, There you can see that Special Product Option has came with yes/no drop down. Now make some product Yes as Special product.

Now go to frontend and write the below code where you want to fetch the Special Product.

$storeId = Mage::app()->getStore()->getId();
$resource = Mage::getSingleton('core/resource');
$read = $resource->getConnection('catalog_read');
$categoryProductTable = $resource->getTableName('catalog/category_product');
$productEntityIntTable = (string)Mage::getConfig()->getTablePrefix() . 'catalog_product_entity_int';
$eavAttributeTable = $resource->getTableName('eav/attribute');
// Query database for special product
$select = $read->select()
->distinct()
->from(array('cp'=>$categoryProductTable),'cp.product_id')
->join(array('pei'=>$productEntityIntTable), 'pei.entity_id=cp.product_id', array())
->joinNatural(array('ea'=>$eavAttributeTable))
->where('pei.value=1')
->where('ea.attribute_code="special"');// Write your attribute code instead of Special
$rows = $read->fetchAll($select);
// Save all product Id which have the Special Product Yes
foreach($rows as $row)
{
$product[] =$row['product_id'];
} 

Inside the $product variable you have all product Id which are Special Product . Now write the Below code to get Details of the Each product

    $val) { $productobject = Mage::getModel('catalog/product'); $productmodel = $productobject->load($val); echo "
  • ";
    echo "

    ".$productmodel->getName()."

    ";
    echo "";
    echo "

    ".$productmodel->getDescription()."

    ";
    echo "

    ".$productmodel->getFinalPrice()."

    ";
    ?>

    ";
    ?>

You can see all the Special Product has come to your frontend. By this way you can make Feature Product

Hope it Helps.. Thanks....

How To Create a custom url redirect in Magento using URL Rewrite Management

To make magento more SEO friendly, It needs to redirect to a custom url, By default magento have this feature but if you have created any module whose url like modulename/id/3, then you needs to redirect it to a SEO friendly url. To redirect the url to a "301 Permanent redirect" you just login to your admin panel, then go to -> Catalog -> URL Rewrite Management, from the drop down select Custom ,follow the below screenshot to make it more easy.

1) In the Id path give your current url (e.g: review/product/list/id/14/category/3)
2) In Request Path write same as Id path (e.g: review/product/list/id/14/category/3)
3) In Target Path give oyu custom Url with domain name (e.g:- http://www.mysite.com/mobile.html)



Hope it Helps... Thanks....