Friday, July 13, 2012

How to add breadcrumb on contact us page in magento

If want to add breadcrumbs on the contact us page ,
open the layout file of your theme contacts.xml and serach the following code between
 the
   <contacts_index_index translate="label">
.......
......
</contacts_index_index>

and add the following line of code


<reference name="breadcrumbs">
        <action method="addCrumb">
            <crumbName>Home</crumbName>
            <crumbInfo>
                <label>Home</label>
                <title>Home</title>
                <link>/</link>
            </crumbInfo>
        </action>
        <action method="addCrumb">
            <crumbName>Contacts</crumbName>
            <crumbInfo>
                <label>Contact Us</label>
                <title>Contact Us</title>
            </crumbInfo>
        </action>
    </reference>


Tuesday, July 10, 2012

How to remove customer data only from session in magento

If you want to remove only customer data from the magento session you can try like

Mage::getSingleton('customer/session')->unsetAll() ;


and enjoy!!!!!!!

Thursday, April 19, 2012

Magento User Sessions Mixed Up ,full page cache

One day I faced a new problem in magento enterprise edition. When a new user create account and goes to my account section the welcome message display right ...but when user goes to others CMS pages the welcome messages change with another name. I was very frestrated with this problem and after digging 1 hour finally I overcome this probelm.
The realy problem was that ful page caching was on in admin caching section.

admin->system->caching management


I disable that one and everything become correct.

Hope this will help someone.

Cheers!!!!!!!!

Friday, April 6, 2012

How to show cutomer street address in Admin Grid like street1 and Street2 :Solved

Hi
I search everywhere to show the street address in customer grid in admin end But no found any solution for this.
Finally I review the code and make a new way to do this .

1. copy file Grid.php form ...app\code\core\Mage\Adminhtml\Block\Customer\Grid.php  to .....app\code\local\Mage\Adminhtml\Block\Customer\Grid.php



2. open the customer 's Grid.php in ....app\code\local\Mage\Adminhtml\Block\Customer\Grid.php

and add the follwing code in _prepareColumns() function

\\\\\\\\\\\\\\\\\\\\\


 $this->addColumn('street1', array(
          'header'    => Mage::helper('customer')->__('Street 1'),
          'index'     => 'entity_id',
 'renderer'=> new Mage_Adminhtml_Block_Customer_Renderer_Street1()
         ));
$this->addColumn('street2', array(
          'header'    => Mage::helper('customer')->__('Street 2'),
          'index'     => 'entity_id',
 'renderer'=> new Mage_Adminhtml_Block_Customer_Renderer_Street2()
         ));


\\\\\\\\\\\\\\\\\\\\\\\

2. make a directory in  ....app\code\local\Mage\Adminhtml\Block\Customer\     named  Renderer

and create two files in  ....app\code\local\Mage\Adminhtml\Block\Customer\Renderer\

Street1.php
for code
\\\\\\\\\\\\\\\\

class Mage_Adminhtml_Block_Customer_Renderer_Street1 extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{

public function render(Varien_Object $row)
{
$value =  $row->getData($this->getColumn()->getIndex());

 $customer = Mage::getModel('customer/customer')
 ->load($value); //put customer id here

$data = array();

 foreach ($customer->getAddresses() as $address)
 {

    $data = $address->getStreet(1);

 

 }
 if(empty($data))
 {
 return '';
 }else{
 return $data;
 }



}

}


\\\\\\\\\\\\\\\\\

and second one is Street2.php

\\\\\\\\\\\\\\\\\\\\\\\\\\\\

class Mage_Adminhtml_Block_Customer_Renderer_Street2 extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{

public function render(Varien_Object $row)
{
$value =  $row->getData($this->getColumn()->getIndex());

 $customer = Mage::getModel('customer/customer')
 ->load($value); //put customer id here

$data = array();

 foreach ($customer->getAddresses() as $address)
 {

    $data = $address->getStreet(2);

    //var_dump($data);

 }
if(empty($data))
 {
 return '';
 }else{
 return $data;
 }

}

}

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\


and that all done.


Enjoy!!

Thursday, April 5, 2012

Store view is not listing in admin magento: SOLVED

In magento 1.6.X there may be a that multiple store listing not comes in admin end.
i comes to accross this issue and find out the solution
go to file ...app\code\core\Mage\Adminhtml\Block\Widget\Grid.php


and replace this code



public function getRowUrl($item)
    {
        $res = parent::getRowUrl($item);
        return ($res ? $res : '#');
    }

with



public function getRowUrl($item)
    {
        $res = parent::getUrl($item);
        return ($res ? $res : '#');
    }


and enjoy!!!!!!!

Monday, April 2, 2012

Change toolbar select to label magento


  <div style="float:left;width: 54%;">
    <div class="amount" style="float: left; ">
            <?php if($this->getLastPageNum()>1): ?>
                <?php echo $this->__('Viewing Items %s-%s of %s ', $this->getFirstNum(), $this->getLastNum(), $this->getTotalNum()) ?>
            <?php else: ?>
<?php echo $this->__('Viewing Items %s-%s of %s ', $this->getFirstNum(), $this->getLastNum(), $this->getTotalNum()) ?>
            <?php endif; ?>
        </div>

        <div class="limiter" style="float: right; padding-right: 34px;">
            <label><?php echo $this->__('View') ?></label> &nbsp;&nbsp;
           <?php $cnt=1;?>
            <?php foreach ($this->getAvailableLimit() as  $_key=>$_limit): ?>
                <a href="<?php echo $this->getLimitUrl($_key) ?>">
                    <?php echo $_limit ?>
                </a><?php echo ($cnt==4?'':'&nbsp;|&nbsp')?>
<?php $cnt++; ?>
  <?php endforeach; ?>
           &nbsp; <?php //echo $this->__('per page') ?>
        </div>

    </div>

Friday, March 23, 2012

How to call a .phtml block file into another .phtml file in magento

you can call a .phtml block file into another .phtml  like

<?php echo $this->getLayout()->createBlock('catalog/product_list_related')->setTemplate('catalog/product/list/related.phtml')->toHtml();
 

?>

Wednesday, March 21, 2012

How to get product attribute in .phtml file


you can Access the product attribute in the .phtml file like...

<?php echo $_product->getResource()->getAttribute('Attribute_code')->getFrontend()->getValue($_product); ?>

Tuesday, February 14, 2012

How To Excute Custom Query In Magento


Magento has provide us very good features for handling or interacting with Database tables. Magento give all the data by default but some time we need to get or insert some custom data.So for this we need to write custom query.
1
2
3
4
5
6
7
<?php
// fetch read database connection that is used in Mage_Core module
$read= Mage::getSingleton('core/resource')->getConnection('core_read');
 
// fetch write database connection that is used in Mage_Core module
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
?>

How to excute custom query in magento

1
2
3
4
5
6
7
8
9
10
<?php
// fetch read database connection that is used in Mage_Core module
$read= Mage::getSingleton('core/resource')->getConnection('core_read');
 
$value=$read->query("SELECT ....");
$row = $value->fetch();
 
echo "<pre>";print_r($row);echo "</pre>"; // As Array
 
?>

Insert custom data in magento tabel

1
2
3
4
5
6
7
<?php
// fetch write database connection that is used in Mage_Core module
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
 
// now $write is an instance of Zend_Db_Adapter_Abstract
$write->query("insert into tablename values ('1','demo','data')");
?>
OR you can wite same as below
1
2
3
4
5
6
<?php
$connection = Mage::getSingleton('core/resource')->getConnection('core_write');
// insert
$sql = "INSERT INTO `test_table` (`id`,`name`,`data`) VALUES ('1','demo','data')";
$connection->query($sql);
?>