Thursday, June 9, 2016

fetch top 3 bestsellers products programmatically

Mage::getResourceModel('reports/product_collection')->addOrderedQty()->addAttributeToSelect('*')->setPage(1, 3)->load();

Wednesday, June 8, 2016

steps to increase the performance of magento


  1. Enable Gzip compression
  2. Combine external CSS/JS into one file
  3. Disable modules which are not used
  4. MySQL Query Caching
  5. Enable Magento caching
  6. Disable the Magento log
  7. Image Optimization

set different themes for logged in users or set different themes on runtime

 if(Mage::getSingleton('customer/session')->isLoggedIn())
{
Mage::getDesign()->setPackageName('packagename')->setTheme('themename');
}

Thursday, November 19, 2015

Get cms page url in magento

<?php
$pageid=1;
echo Mage::helper('cms/page')->getPageUrl($pageid); ?>

Or
In controller or .phtml file:
<?php echo $this->getUrl('whats_new');?>

or
<?php echo Mage::helper('cms/page')->getPageUrl('url_key'); ?>

Or
In CMS Page
{{store _direct="url_key"}}

Wednesday, November 4, 2015

Call Newsletter form anywhere in magento

<?php 
echo $this->getLayout()->createBlock('newsletter/subscribe')->setTemplate('newsletter/subscribe.phtml')->toHtml(); 
?>

Friday, October 16, 2015

Call one .phtml file into another .phtml file in magento

<?php
echo $this->getLayout()->createBlock('core/template')->setTemplate('mobilebanners/index.phtml')->toHtml();

?>

Ratings and Reviews count in magento

<?php
$storeId = Mage::app()->getStore()->getId();
$reviewSummaryData = Mage::getModel('review/review_summary')
->setStoreId($storeId)
->load($_product->getId());
$reviewUrl=Mage::getUrl('review/product/list', array('id'=> $_product->getId()));
?>
<div class="ratings">
<div class="rating-box">
<div class="rating" style="width:<?php echo $reviewSummaryData['rating_summary'] ?>%">
</div>
<?php //echo $reviewSummaryData['reviews_count'];?>
</div>
<span class="amount"> <?php echo $this->__('%d Review(s)', $reviewSummaryData->getReviewsCount()) ?></span>
</div>

Thursday, October 15, 2015

get Product URL by Id

$product_id = 85;
$_product = Mage::getModel('catalog/product')->load($product_id);
$product_url = $_product->getProductUrl();

Redirect to CMS page from phtml file

<?php echo $this->getUrl('privacy-policy'); ?>
privacy-policy is the url-key of your cms page

or
<?php echo Mage::helper('cms/page')->getPageUrl('url_key') ?>


Redirect to Category listing Page

<?php
$category = Mage::getModel('catalog/category')->load(3);
echo $category->getUrl();
?>

Wednesday, September 9, 2015

Magetno - Get add to cart url for any product

$_productId = '1222';
$_product = Mage::getModel('catalog/product')->load($_productId);
$_carturl = Mage::helper('checkout/cart')->getAddUrl($_product);

Fatal error: Class Zend\Stdlib\Parameters contains 1 abstract method... magento 2

Fatal error: Class Zend\Stdlib\Parameters contains 1 abstract method and must therefore be declared abstract or implement the remaining met...