Sunday, July 8, 2012

how to check home page in magento?

if(Mage::getSingleton('cms/page')->getIdentifier() == 'home' &&Mage::app()->getFrontController()->getRequest()->getRouteName() == 'cms' )

how to view all brands in magento containing products?

View all brands in magento

How to view recent sold product of current category in magento?


load(3);
$_productCollection = $cats->getProductCollection() ->addAttributeToFilter('visibility',4);
$intNumRecord = Mage::getStoreConfig('banner/carousel_configuration/bestseller_number_product');
$_productCollection = $_productCollection ->setPageSize($intNumRecord);
if($_productCollection->count()) { ?>
load($_products->getId());?>

how to view popular products in magento? or maximum sold products in store


getStore()->getStoreId(); $this->_productCollection = Mage::getResourceModel('reports/product_collection');
if ($this->getTimeLimit())
{
$product = Mage::getModel('catalog/product');
$todayDate = $product->getResource()->formatDate(time());
$startDate = $product->getResource() ->formatDate(time() - 60 * 60 * 24 * $this ->getTimeLimit());
$this->_productCollection = $this->_productCollection ->addOrderedQty($startDate, $todayDate);
}
else
{
$this->_productCollection = $this->_productCollection ->addOrderedQty();
}
$intNumRecord = Mage::getStoreConfig('banner/carousel_configuration/bestseller_number_product');
$this->_productCollection = $this->_productCollection ->addAttributeToSelect('*') ->setStoreId($storeId) ->addStoreFilter($storeId) ->setOrder('ordered_qty', 'desc') ->setPageSize($intNumRecord);
$_productCollection = $this->_productCollection ->setPageSize($intNumRecord);
if($_productCollection->count())
{ ?>
load($_products->getId());?>getShortDescription();if(strlen($strproductdescription)>82) $strproductdescription = trim(substr($strproductdescription,0,81)."...");$strProductName = $_product->getName(); ?> 22){$strProductName =  substr($strProductName,0,21)."...";}?>
<a href="getProductUrl() ?>" title="stripTags($_product->getName(), null, true) ?>">

<a href="getUrl('popular-products');?>">__('More...');?>

How to display add to cart url on any page on magento?


<?php if(isSaleable()): ?>
 <button type="button" title="__(‘Add to Cart’) ?>” class=”button btn-cart” onclick=”setLocation(‘getLayout()->createBlock(‘catalog/product_list’)->getAddToCartUrl($objProduct) ?>’)”>__(‘Add to Cart’) ?>
__(‘Out of stock’) ?>

How to display total reviews of product in magento?

$intTotalReviewPerProduct = $objCategoryBanners->fnGetTotalProductReview($_product);

How to display image of current product on magento?

<a href="getProductUrl();?>">
<img src="helper('catalog/image')->init($objProduct, 'small_image')->resize(60,110); ?>" alt="getName();?>">

How to display total reviews of product in magento?

$intTotalReviewPerProduct = $objCategoryBanners->fnGetTotalProductReview($_product);

How to display average ratings of product in magento?


public function fnGetTotalProductReview($objCurrentProduct)
{
$objReview = Mage::getModel('review/review');
return $objReview ->getTotalReviews($objCurrentProduct->getId(),true);
}
$intTotalReviewPerProduct = fnGetTotalProductReview($_product);
if($intTotalReviewPerProduct > 0){echo $this ->getLayout() ->createBlock('catalog/product_list') ->getReviewsSummaryHtml($_product);
}

How to show all the manufactures or brand list in magento?


$product = Mage::getModel('catalog/product');
$attributes = Mage::getResourceModel('eav/entity_attribute_collection')
->setEntityTypeFilter($product->getResource()->getTypeId())
->addFieldToFilter('attribute_code', 'manufacturer');
$attribute = $attributes->getFirstItem()->setEntity($product->getResource());
$manufacturers = $attribute->getSource()->getAllOptions(false);
foreach ($manufacturers as $manufacturer)
{
echo Mage::getBaseUrl(); ?>catalogsearch/advanced/result/?manufacturer[]=$manufacturer['value']
echo Mage::getBaseUrl(); ?>catalogsearch/advanced/result/?manufacturer[]=$manufacturer['label']
}

How to get the customer login, logout, register and checkout url?

Mage::getUrl('customer/account/login'); //login url
Mage::getUrl('customer/account/logout'); //logout url
Mage::getUrl('customer/account'); //My Account url
Mage::getUrl('customer/account/create'); // Register url
Mage::getUrl('checkout/cart'); //Checkout url

How to show all the manufactures or brand list in magento?


$product = Mage::getModel('catalog/product');
$attributes = Mage::getResourceModel('eav/entity_attribute_collection')
->setEntityTypeFilter($product->getResource()->getTypeId())
->addFieldToFilter('attribute_code', 'manufacturer');
$attribute = $attributes->getFirstItem()->setEntity($product->getResource());
$manufacturers = $attribute->getSource()->getAllOptions(false);
foreach ($manufacturers as $manufacturer)
{
echo Mage::getBaseUrl(); ?>catalogsearch/advanced/result/?manufacturer[]=$manufacturer['value']
echo Mage::getBaseUrl(); ?>catalogsearch/advanced/result/?manufacturer[]=$manufacturer['label']
}

How to get the customer login, logout, register and checkout url?

Mage::getUrl('customer/account/login'); //login url
Mage::getUrl('customer/account/logout'); //logout url
Mage::getUrl('customer/account'); //My Account url
Mage::getUrl('customer/account/create'); // Register url
Mage::getUrl('checkout/cart'); //Checkout url

set or get magento session


//Setting session
Mage::getSingleton('core/session')->setMySessionVariable('value');
//Getting session
Mage::getSingleton('core/session')->getMyDesignProductVariable()
//Unset session
Mage::getSingleton('core/session')->setTestingMagento();
//(Use customer or core session in frontend. Use adminhtml session in the backend.)
Core Session:- Mage::getSingleton(‘core/session’)
Customer Session:- Mage::getSingleton(‘customer/session’)
Admin Session:- Mage::getSingleton(‘adminhtml/session’)

How to get cms content from cms id in magento?

$objCmsPage = Mage::getModel('cms/page')->getCollection()->addFieldToFilter('identifier','next-day');
foreach($objCmsPage as $objCmsPageContent)
{
break;
}
$objCmsHelper = Mage::helper('cms');
$objProcessor = $objCmsHelper->getPageTemplateProcessor();
echo $objProcessor->filter($objCmsPageContent->getContent());

How to get cms content from cms id in magento?

$objCmsPage = Mage::getModel('cms/page')->getCollection()->addFieldToFilter('identifier','next-day');
foreach($objCmsPage as $objCmsPageContent)
{
break;
}
$objCmsHelper = Mage::helper('cms');
$objProcessor = $objCmsHelper->getPageTemplateProcessor();
echo $objProcessor->filter($objCmsPageContent->getContent());

How To fetch all categories and subcategories in magento?

$_helper = Mage::helper(‘catalog/category’)
$_categories = $_helper->getStoreCategories()
$currentCategory = Mage::registry(‘current_category’)
if (count($_categories) > 0)
{
foreach($_categories as $_category)
{
echo $_category->getName()
$_category = Mage::getModel(‘catalog/category’)->load($_category->getId())
$_subcategories = $_category->getChildrenCategories()
if (count($_subcategories) > 0)
{
foreach($_subcategories as $_subcategory)
{
echo $_subcategory->getName()
}
}
}
}

How to define custom layout in magento like 1column,2-column right,3-columns


template/page/2columns-aboutus.phtml
-----------------------------------------------------------------------
layout/page.xml
-----------------------------------------------------------------------
find All Two-Column Layout Pages (Left Column) and place
-----------------------------------------------------------------------
<page_two_columns_aboutus translate="label">
<label>All Two-Column Layout Pages (About us Column)</label>
<reference name="root">
<action method="setTemplate"><template>page/2columns-aboutus.phtml</template></action>
<!-- Mark root page block that template is applied -->
<action method="setIsHandle"><applied>1</applied></action>
</reference>
</page_two_columns_aboutus>
-----------------------------------------------------------------------
now define global object in xml
app/code/local/companyname/modulename/etc/config.xml
<two_columns_aboutus module="page" translate="label">
<label>2 columns with About Us</label>
<template>page/2columns-aboutus.phtml</template>
<layout_handle>page_two_columns_aboutus</layout_handle>
</two_columns_aboutus>
Now go to admin login pages/ -----> 2 columns with About Us

How to define store path on backend side while create static block

{{store url='company-history'}}

How to get request on magento?

echo $this->getRequest()->getParams())