Thursday, April 26, 2012

Important Magento: Edit links on Customer Account page in Magento

Important Magento: Edit links on Customer Account page in Magento: When a user log in to a Magento Store, he/ she is taken to the User Account page. It looks like this: There are various items on t...

Saturday, February 11, 2012

Magento...............

Get adminhtml Front Name

$adminFrontName = (string)Mage::getConfig()->getNode('admin/routers/adminhtml/args/frontName');


Get Product image path:
$productId = 1;
$product = Mage::getModel('catalog/product')->load($productId);
$path = Mage::helper('catalog/image')->init($product, 'image')->resize(75, 75);

 Format a number as price:
$this->formatPrice(10);
 Call a .phtml explicitly:
echo $this->getLayout()->createBlock('sales/order_recent')->setTemplate('sales/order/recent.phtml')->toHtml();
 Get Currency Code:
Mage::app()->getStore()->getCurrentCurrencyCode();
 Get Currency Symbol:
Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol();


To load the product Tier price details in the product list view

$_productCollection=$this->getLoadedProductCollection();
$_productCollection->addTierPriceData();


Wednesday, November 2, 2011

How to use Git


Friday, September 2, 2011

Calculate Postal Code Distance Using Google API


This is simple function to calculate the distance between two different Canadian postal codes.

$query = "http://maps.google.co.uk/maps/geo?q=".urlencode($code)."&output=json&key=".$mapsApiKey;

 For this i used http://maps.google.co.uk- (use domian nearest your region)
<?php

/**
 * @author jayje
 * @copyright 2011
 */




$add1=getLatLong('L8R 3L4');
$add2=getLatLong(10001);
$lat1=$add1['Latitude'];
$lon1=$add1['Longitude'];

$lat2=$add2['Latitude'];
$lon2=$add2['Longitude'];

echo "<br>kilometers=";
echo distance($lat1, $lon1, $lat2, $lon2, 'k');

 function getLatLong($code){
 $mapsApiKey = 'ABQIAAAA8JnBykA-EPiMmKdOR--UcRT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQ8npfo6U4N7PRuya0RBiyaKD8mRA';
 $query = "http://maps.google.co.uk/maps/geo?q=".urlencode($code)."&output=json&key=".$mapsApiKey;

 $data = file_get_contents($query);
 // if data returned
 if($data){
  // convert into readable format
  $data = json_decode($data);
  $long = $data->Placemark[0]->Point->coordinates[0];
  $lat = $data->Placemark[0]->Point->coordinates[1];
  return array('Latitude'=>$lat,'Longitude'=>$long);
 }else{
  return false;
 }
}
function distance($lat1, $lon1, $lat2, $lon2, $unit) {

  $theta = $lon1 - $lon2;
  $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
  $dist = acos($dist);
  $dist = rad2deg($dist);
  $miles = $dist * 60 * 1.1515;
  $unit = strtoupper($unit);

  if ($unit == "K") {
    return ($miles * 1.609344);
  } else if ($unit == "N") {
      return ($miles * 0.8684);
    } else {
        return $miles;
      }
}

?>