Tuesday 17 January 2017

Get City Country By IP Address in PHP

/*Get user ip address*/
$ip_address=$_SERVER['REMOTE_ADDR'];

/*Get user ip address details with geoplugin.net*/
$geopluginURL='http://www.geoplugin.net/php.gp?ip='.$ip_address;
$addrDetailsArr = unserialize(file_get_contents($geopluginURL));

/*Get City name by return array*/
$city = $addrDetailsArr['geoplugin_city'];

/*Get Country name by return array*/
$country = $addrDetailsArr['geoplugin_countryName'];

/*Comment out these line to see all the posible details*/
/*echo '<pre>';
print_r($addrDetailsArr);
die();*/

if(!$city){
   $city='Not Define';
}if(!$country){
   $country='Not Define';
}
echo '<strong>IP Address</strong>:- '.$ip_address.'<br/>';
echo '<strong>City</strong>:- '.$city.'<br/>';
echo '<strong>Country</strong>:- '.$country.'<br/>';

Monday 16 January 2017

 Step 1:
Disable Magento Cache from magento back-end.

Just copy paste the below code in header.phtml and run yourmagento once, your attribute will be created and you can see in backend under manage category. Please remove this code once new attribute added.
$setup = new Mage_Eav_Model_Entity_Setup(‘core_setup’);

$setup->addAttribute(‘catalog_category’, ‘sliderimage’, array(
‘group’ => ‘General’,
‘input’ => ‘image’,
‘type’ => ‘varchar’,
‘label’ => ‘Slider Image’,
‘backend’ => ‘catalog/category_attribute_backend_image’,
‘visible’ => 1,
‘required’ => 0,
‘user_defined’ => 1,
‘global’ => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));

Step 2:
Copy Category.php file from app/code/core/Mage/Catalog/Model/Category.php to app/code/local/Mage/Catalog/Model/Category.php
Step 3:
Open app/code/local/Mage/Catalog/Model/Category.php and find text “public function getImageUrl()” and insert below code to create new function for new image attribute to get it’s value with full URL.

Here BannerImage is attribute code:

public function getBannerImageUrl()
{
$url = false;
if ($image = $this->getBannerimage()) {
$url = Mage::getBaseUrl(‘media’).’catalog/category/’.$image;
}
return $url;
}


Step 4:
To call new category image attribute in category view page, please open app/design/frontend/default/YOURTHEMEFOLDER/template/catalog/category/view.phtml
You will get new image attribute with below code: getBannerImageUrl() function name as created above.

$_category->getBannerImageUrl();