Pages

Sunday, August 11, 2013

To Change The Default Magento Logo

In ADMIN end
System -> Configuration->General->Design
Click on “Design” in the left side menu and open the “Header” section
Change the file name in the “Logo Image Src” to the file name you just uplaoded.Here you can also change the logo Alt message

Get Connection & Custom Query Execution in Magento

For database connection
$write = Mage::getSingleton('core/resource')->getConnection('core_write');

$qry=”Select * from tablename”;
$execute=$write->query($qry);
$fetch=$execute->fetch()
To get the Row Count
$count=$execute->rowCount();

Get Magento Urls in Phtml Page

Get Base Url :
Mage::getBaseUrl();
Get Store Url : 
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
Get Skin Url :
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);
$this->getSkinUrl(‘images/imagename.jpg’);
Get Media Url :
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
Get Js Url : 
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);
Get Current Url
Mage::helper(‘core/url’)->getCurrentUrl();
Get Home Url
Mage::helper(‘core/url’)->getHomeUrl();

Get Urls in Cms Pages or Static Blocks in Magento

Get Base Url :
{{store url=”"}}
Get Skin Url :
{{skin url=’images/imagename.jpg’}}
Get Media Url :
{{media url=’/imagename.jpg’}}
Get Store Url : 
{{store url=’mypage.html’}}

How to Call Magento Static Block in CMS Page and phtml in Magento

In PHTML
<?php echo $this->getLayout()->createBlock(‘cms/block’)->setBlockId(‘yourblockid’)->toHtml(); ?>
IN CMS
{{block type=”cms/block”  block_id=”yourblockid“}}

Get Top 10 Products in Magento

$collection= Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect('*')
->setStoreId($storeId)
->addStoreFilter($storeId)

->setOrder(‘ordered_qty’, ’desc’)
->setPageSize(10) ;
foreach($collection as $product)
{
$name=$product->getName();
$productId=$product->getId();
$price=$product->getPrice();
}

Get Customer Details Using Customer Session in Magento

$customer = Mage::getSingleton(‘customer/session’)->getCustomer();
$email = $customer->getEmail(); // To get Email Address of a customer.
$firstname = $customer->getFirstname(); // To get Firstname of a customer.
$lastname= $customer->getLastname(); // To get Lastname of a customer.
$id =$customer->getId(); // To get Customer Id
//Get Details Using Customer Id
$customer = Mage::getModel(‘customer/customer’)->load($id)->getData();

Get Current Category Id in Magento

$layer = Mage::getSingleton(‘catalog/layer’);
$_category = $layer->getCurrentCategory();
$currentCategoryId= $_category->getId();

How do I remove Grid view or List view from my Magento store?

System->Configuration->Catalog->Frontend
You can change the List Mode.

Remove other shipping if Free shipping available in magento

//To get the subtotal in shipping method (onepage checkout)
$subtotal = Mage::getSingleton(‘checkout/session’)->getQuote()->getSubtotal()
If cart total is less than 500 flat rate will enabled and free shipping will be disabled , for this
app/design/frontend/Your-Namespace /MODULE/template/checkout/onepage/shipping_method/available.phtml
<?php
if($subtotal >=500)
{
// Remove any other shipping methods if free shipping is available
if (array_key_exists(‘freeshipping’, $_shippingRateGroups )) {
$_shippingRateGroups = array(‘freeshipping’ => $_shippingRateGroups['freeshipping']);
}
}
?>