Friday, April 1, 2016

Magento get country code for logged in user Using mageworx geoip location

steps:

1. Install the Mageworx geoip location extension

http://www.mageworx.com/geoip-location-magento-extension.html

2.  Use the below code where you want to have the country code of the logged in user:


$rec = Mage::getModel('mageworx_geoip/geoip')->getLocation();

return $locData =$rec->getCode(); //this will return the country code for e.g. IN for India.

Note:: you can use  $rec->getData(); to get all the below information:
IP, CODE ,COUNTRY ,FLAG

Tuesday, March 22, 2016

Add option to customer attribute programmatically In Magento

To programmatically Add option to customer attribute , Add the function given in the reference url to your controller or block:

http://blog.onlinebizsoft.com/magento-programmatically-insert-new-attribute-option/

And replace the below code

 $attribute_code         = $attribute_model->getIdByCode('catalog_product', $arg_attribute);
  

To

 $attribute_code         = $attribute_model->getIdByCode('customer', $arg_attribute);
  

Monday, March 21, 2016

Magento Change Pager Phtml Custom Module



In you block of custom module, for e.g.In my case,  Netgo_Userstatus_Block_Userstatus_List

Just Use the blow code in _prepareLayout() function

  protected function _prepareLayout()
{
        parent::_prepareLayout();
        $pager = $this->getLayout()->createBlock(
            'page/html_pager',
            'netgo_userstatus.userstatus.html.pager'
        )->setTemplate('page/html/newsfeed_pager.phtml')
        ->setCollection($this->getUserstatuss());
        $this->setChild('pager', $pager);
        $this->getUserstatuss()->load();
        return $this;
    }

The Red colored is the extra code that I have added, you can define your phtml file for the pager.

Friday, February 19, 2016

Magento admin change default page size of grid

You have to modify two files for that: Grid.php and Grid.phtml,
Below are the details of files:

In Admin Block File:
/public_html/app/code/core/Mage/Adminhtml/Block/Widget
Grid.php

Search for $_defaultLimit in the file and change the value according to your choice.
protected $_defaultLimit    = 75;

PHTML File:
app/design/adminhtml/default/default/template/widget
grid.phtml

Add your option in the select box.

<select name="<?php echo $this->getVarNameLimit() ?>" onchange="<?php echo $this->getJsObjectName() ?>.loadByElement(this)">
<option value="20"<?php if($this->getCollection()->getPageSize()==20): ?> selected="selected"<?php endif; ?>>20</option>
<option value="30"<?php if($this->getCollection()->getPageSize()==30): ?> selected="selected"<?php endif; ?>>30</option>
<option value="50"<?php if($this->getCollection()->getPageSize()==50): ?> selected="selected"<?php endif; ?>>50</option>
<option value="75"<?php if($this->getCollection()->getPageSize()==75): ?> selected="selected"<?php endif; ?>>75</option>
<option value="100"<?php if($this->getCollection()->getPageSize()==100): ?> selected="selected"<?php endif; ?>>100</option>
<option value="200"<?php if($this->getCollection()->getPageSize()==200): ?> selected="selected"<?php endif; ?>>200</option>
</select>

I have added 75 as additional page size, It will be default pagesize too.