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.

Monday, October 26, 2015

PHP Remove special (non printable) characters from text

 

$mystring = " Fund BDM̢۪s were then able to engage with 19 employers, most of whom were subsequently converted to the MTAA Super Clearinghouse.
";
preg_replace("/[^\x0A\x20-\x7E]/",'', $mystring);

echo $mystring;

//The above code will result in

Fund BDMs were then able to engage with 19 employers, most of whom were subsequently converted to the MTAA Super Clearinghouse..
        

Wednesday, October 21, 2015

DISPLAY OUT OF STOCK PRODUCTS ACCORDING TO ADMIN INVENTORY SETTING

 

$isOutOfStockAllowed = Mage::getStoreConfig('cataloginventory/options/show_out_of_stock');
 
  foreach($_productCollection as $_product)
       {
        if(!$isOutOfStockAllowed){
         if(!$_product->isSaleable()){
          continue;
         }
         
        }
        //PRODUCT DISPLAY CODE HERE
        
        }
        

Saturday, October 17, 2015

Facebook page feed time issue

I was implementing facebook page feed for one of my client, the feeds were appearing correct but time was different, actually it was a timezone issue, you have to convert facebook time to local timezone, and to do this i found the perfect way.

step1.
Download and include the js file into your script.

https://gist.github.com/aredo/4153245

step2:

use below code to determine the client timezone:

<script type="text/javascript">
    jQuery(document).ready(function() {
       var timezone = jstz.determine();
var timezonename = timezone.name();  
    });
</script>