Monday, February 25, 2013

MAgento : Add custom action to Sales Order Grid

Here we use an event core_block_abstract_prepare_layout_before
1. Add following script in config.xml
<events>
<core_block_abstract_prepare_layout_before>
        <observers>
                <bdaction_block_abstract_prepare_layout_before>
                        <type>singleton</type>
                        <class>Bd_Test_Model_Observer</class>
                        <method>addMassCustomAction</method>
                </bdaction_block_abstract_prepare_layout_before>
        </observers>
</core_block_abstract_prepare_layout_before>
</events>
2.Create a observer class like Bd_Test_Model_Observer
then add a method
public static function addMassCustomAction($observer)
{
    $block = $observer->getEvent()->getBlock();
    if(get_class($block) =='Mage_Adminhtml_Block_Widget_Grid_Massaction'
        && $block->getRequest()->getControllerName() == 'sales_order')
    {
        $block->addItem('customaction', array(
        'label' => 'Custom Action',
        'url' => Mage::helper('adminhtml')->getUrl('module/controller/action'),
        ));
    }
}
3.At last create that controller and action method

Sunday, February 24, 2013

Magento : Session Storage


Typically, database servers are less utilised than web servers. Performance can usually be improved by moving session handling from the web server filesystem into the database server. Magento asks you whether you prefer a file or database session save type, but this is very easy to change in the XML. Open up /var/www/app/etc/local.xml, locate the <session_save> tags, and change the value so it looks like this (the default is <![CDATA[files]]>):

<session_save><![CDATA[db]]></session_save>
Another alternative is to use memcache for storing the sessions - this isn’t as persistent as the database store, but may be faster:

<session_save><![CDATA[memcache]]></session_save>
You can add details of your memcache server in the session save path:

<session_save_path><![CDATA[tcp://127.0.0.1:20?persistent=1&weight;=2&timeout;=10&retry;_interval=10]]></session_save_path>

Magento : Changing the Admin URL


We can improve security by changing the default URL from 'admin' to something more obscure, such as 'bdadmin'. This will decrease the probability that a malicious user will hit upon your admin log-in page by guessing that the admin site is located at domain.com/admin/, or that automated scripts scanning for Magento admin pages will find it.
To change the admin address you first need to stop Apache and clear the cache:
root# /etc/init.d/apache2 stop
root# rm -rf /var/www/var/cache/*
root# rm -rf /var/www/var/session/*
Then open up the /var/www/app/etc/local.xml file, locate the <frontName> tag, and change the 'admin' part it to something a lot more random,
eg:  <frontName><![CDATA[gJpf2VK5]]></frontName>
Then set Apache running again (bearing in mind your site will be down for the duration of this operation!):
root# /etc/init.d/apache2 start

Saturday, February 23, 2013

Magento: Get the list of events from magento


Use following code in action of magento
$eventAreas = array('global','frontend','adminhtml');
foreach ($eventAreas as $eventArea) {
    $eventConfig = Mage::app()->getConfig()
                       ->getNode(sprintf('%s/events', $eventArea));
    foreach($eventConfig->children() as $key=>$value)
    {
        foreach($value->observers->children() as $key1=>$value1)
        {
            $observer_method = array((string)$eventArea,
            (string)$key,
            (string)$key1,
            (string)Mage::app()->getConfig()
                        ->getModelClassName($value1->class),
            (string)$value1->method);
             echo '<pre>';
             print_r($observer_method);
             echo '</pre>';
        }
    }
}

Magento : Add SEO content in footer

There are following unique pages as category, product and cms pages.
Here, we will create an attribute for these pages as
1.CMS Page

<?php
$installer = $this;
$installer->startSetup();
$installer->run('
    ALTER TABLE '. $this->getTable("cms_page") .
         ' ADD column seo_footer_cms_content text NULL;
');
$installer->endSetup();
?>
2.Category Page


<?php
$installer = $this;
$installer->startSetup();
$installer->addAttribute('catalog_category', 'seo_footer_category_content', array(
                        'type'              => 'text',
                        'backend'           => '',
                        'frontend'          => '',
                        'label'             => 'SEO Footer Content',
                        'input'             => 'textarea',
                        'class'             => '',
                        'source'            => '',
                        'global'            => 0,
                        'visible'           => 1,
                        'required'          => 0,
                        'user_defined'      => 1,
                        'default'           => '',
                        'searchable'        => 0,
                        'filterable'        => 0,
                        'comparable'        => 0,
                        'visible_on_front'  => 0,
                        'unique'            => 0,
                        'position'          => 1,
                    ));
$installer->endSetup();
?>
3.Product page

<?php
$installer = $this;
$installer->startSetup();
$installer->addAttribute('catalog_product', 'seo_footer_product_content', array(
                        'type'              => 'text',
                        'backend'           => '',
                        'frontend'          => '',
                        'label'             => 'SEO Footer Content',
                        'input'             => 'textarea',
                        'class'             => '',
                        'source'            => '',
                        'global'            => 0,
                        'visible'           => 1,
                        'required'          => 0,
                        'user_defined'      => 1,
                        'default'           => '',
                        'searchable'        => 0,
                        'filterable'        => 0,
                        'comparable'        => 0,
                        'visible_on_front'  => 0,
                        'unique'            => 0,
                        'position'          => 1,
                    ));                
$installer->endSetup();
?>

Now you can see corresponding attribute of product and category in admin.
But for cms page we have to add following code (use adminhtml_cms_page_edit_tab_meta_prepare_form event). Lets add below code in config.xml

<adminhtml>
    <events>
        <adminhtml_cms_page_edit_tab_meta_prepare_form>
            <observers>
                <bd_cms_page_edit_tab_meta>
                    <type>singleton</type>
                    <class>Bd_Attributes_Model_Observer</class>
                    <method>createCMSAttribute</method>
                </bd_cms_page_edit_tab_meta>
            </observers>
        </adminhtml_cms_page_edit_tab_meta_prepare_form>
    </events>
</adminhtml>
now create createCMSAttribute function in Bd/Attribures/Model/Observer.php file

public function createCMSAttribue($observer)
{
    $form = $observer->getEvent()->getForm();
    $fieldset = $form->getElement('meta_fieldset');
    $fieldset->addField('seo_footer_cms_conten', 'editor', array(
        'name' => 'seo_footer_cms_content',
        'label' => Mage::helper('cms')->__('SEO Footer Content'),
        'title' => Mage::helper('cms')->__('SEO Footer Content'),
        'style'     => '',
        'wysiwyg'   => false,
        'disabled'  => 0
    ));
}

To show the content in the footer we need to add the following code in footer.phtml

<?php
   $routeName=Mage::app()->getFrontController()->getRequest()->getRouteName();
   $currentCategory = Mage::registry('current_category');
   $currentProduct = Mage::registry('current_product');
   if ($currentProduct):
    echo $currentProduct->getSeoFooterProductContent();
   elseif ($currentCategory):
    echo $currentCategory->getSeoFooterCategoryContent();
   elseif( $routeName == 'cms'):
    $page = Mage::getSingleton('cms/page');  
    echo $page->getSeoFooterCmsContent();
  endif;
  ?>










Tuesday, February 12, 2013

How to completely uninstall and reinstall Firefox?

You can reinstall firefox with the following command:

sudo apt-get install --reinstall firefox