Monthly Archives: May 2012

Magento Add Custom links to Top menu

Sometime we don’t require to show categry in the top navigation but we require to show our customlinks at the top menu
for example we are taking all footer links to be shown in the top menu where category is showingHow to add footer page links into the header i.e top menuSo first things first login to you admin Backend

1) go to cms and then to Static Blocks >> Add new Block

Title Top Navigation Links

Identifier top_nav_links

Then add this code

<ul id="nav">
<li><a href="{{store url=""}}">Link1</a></li>
<li><a href="{{store url=""}}link1">Link2</a></li>
<li><a href="{{store url=""}}link3">Link3</a></li>
<li><a href="{{store url=""}}link4">Link4</a></li>
<li><a href="{{store url=""}}link5">Link5</a></li>
</ul>

you will also need to create pages to reflect CMS BLOCK links above

go to cms and then to MANAGE PAGES >> ADD NEW PAGE

2)Now go to apps/design/frontend/your_interface/your_theme/layout/page.xml

after   <block type=”core/text_list” name=”top.menu” as=”topMenu”/>

add this line

<block type="page/html_nav" name="nav" as="nav" template="page/html/nav.phtml">
                <block type="cms/block" name="top_nav_links">
                    <action method="setBlockId"><block_id>top_nav_links</block_id></action>
               </block>
      </block>

3) Now go to apps/design/frontend/your_interface/your_theme/template/page/html and create one file called

nav.phtml

<div>
<div>
<?php $this->getChildHtml()?> 
<?php if($this->hasSeoLinks()>0):?>
<ul id="nav">
<!--edit this out as these links not needed-->
   <?php foreach($this->getSeoLink() as $item):?>
<li><a href="<?php $item['url'];?>"><?php $item['title'];?></a></li>
<?php endforeach;?>
<!--edit finish-->
</ul>
<script type="text/javascript">decorateList('footer:seo-links')</script>
</div>
<?php endif;?>     
</div>

4) Now create one file in local apps/code/core/Mage/Page/Block/Html

and name as Nav.php

and add the following code

<?php

class Mage_Page_Block_Html_Nav extends Mage_Core_Block_Template

{

    protected $_seolinks; 
    protected function _prepareLayout()
    {
        parent::_prepareLayout();
        $this->initSeoLink();
    }
    public function setCopyright($copyright)
    {
        $this->_copyright = $copyright;
        return $this;
    }
  public function getCopyright()
    {
        if (!$this->_copyright) {
            $this->_copyright = $this->getDesignConfig('page/nav/copyright');
        }
        return $this->_copyright;
    }
    public function getSeoLink()
    {     
        return $this->_seolinks; 
    }
    public function setSeoLink(array $varName)
    {
        $this->_seolinks=$varName;
    }
    public function addSeoLink(array $varName)
    {
        $this->_seolinks[]=$varName;

    }
    public function hasSeoLinks()
    {
        return count($this->_seolinks);
    } 
    public function initSeoLink()
    {
        if(Mage::getStoreConfig('catalog/seo/site_map')){

            $seolink['title']=$this->__('Site Map');

            $seolink['url']=$this->helper('catalog/map')->getCategoryUrl();

            $this->_seolinks[]=$seolink;           

        }
        if(Mage::getStoreConfig('catalog/seo/search_terms')){

            $seolink['title']=$this->__('Search Terms');

            $seolink['url']=$this->helper('catalogSearch/data')->getSearchTermUrl();
            $this->_seolinks[]=$seolink;           
        }   
    }

}?>

5)Now go to in your template/page/html/header.phtml

just comment the line <?php echo getchildhtml(‘topmenu’)?>

and add the new line <?php echo getchildhtml(‘nav’)?>

6) Now last part i.e css

#nav { padding:0 50px; font-size:1.1em; z-index:999;  margin-left:200px;}

that’s it now your custom links will be shown in top menu whereas categroy will not come as we have commented the top menu

Google API Calendar Service with Magento

Google Calendar allows client applications to view and update calendar events in the form of Google Data API feeds. Your client application can use the Google Calendar Data API to create new events, edit or delete existing events, and query for events that match particular criteria.

As Magento is using Zend library so Easily integrated with Magento with some customization

Just Amazing thing from Google which will help to integrate the calendar service from website to internal Google calendar with Zend Library

Reference Links
1) https://developers.google.com/google-apps/calendar/v1/developers_guide_php
2) http://www.ibm.com/developerworks/library/x-googleclndr/
3) http://maestric.com/doc/php/google_calendar_api

Hope this will be helpful

Magneto Adding New Layout

Custom Module will help to make the New layout if we don’t want to use the Magento default layout

We can add a new page layout in Magento, create a custom layout or create a new theme layout then here are the steps need to follow

create a module. Create file: app/etc/modules/Mage_Page.xml





true
local


Then copy this whole folder: app/code/core/Mage/Page/etc/config.xml  to app/code/local/Mage/etc/config.xml





page_home




page_empty




page_one_column




page_two_columns_left




page_two_columns_right




page_three_columns

Now all you have to do is make a template for this page. Navigate to your theme directory: app/design/frontend/YOUR_THEME/YOUR_THEME/template/page/ and create a new template called home.phtml.
same as u can copy 2column-left.phtml or any
his will enable a custom layout option for CMS pages once you’re finished

Magento Best seller and Top seller

To show bestseller at Top seller at home page.so that best products should come on home page.For that follow the following steps
Create a Bestseller.php file and put it here :

app/code/local/Mage/Catalog/Block/Product/Bestseller.php

 

class Mage_Catalog_Block_Product_Bestseller extends Mage_Catalog_Block_Product_Abstract{
    public function __construct(){
        parent::__construct();
        $storeId = Mage::app()->getStore()->getId();
        $products = Mage::getResourceModel('reports/product_collection')
            ->addOrderedQty()
            ->addAttributeToSelect('id')
            ->addAttributeToSelect(array('name', 'price', 'small_image'))
            ->setStoreId($storeId)
            ->addStoreFilter($storeId)
            ->setOrder('ordered_qty', 'desc'); // most best sellers on top
        Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
        Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
        $products->setPageSize(3)->setCurPage(1);
        $this->setProductCollection($products);
    }
}

 

Create bestseller.phtml file and put it here :

app/design/frontend/yourtheme/template/catalog/product/bestseller.phtml

 

<?php if (($_products = $this->getProductCollection()) && $_products->getSize()): ?>
<div>
<?php $i=0; foreach ($_products->getItems() as $_product): ?>
    <?php if ($i>5): continue; endif; ?>
<div>
        <div>
            <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>">
                 <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(65,65); ?>" alt="<?php echo $this->htmlEscape($_product->getName()) ?>"/>
            </a>
            <?php echo $_product->getDescription(); //also getShortDescription ?>
        </div>
        <div>
            <p><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>)"><?php echo $_product->getName() ?></a></p>
            <?php //echo $this->helper('review/product')->getSummaryHtml($_product, 'short') //product review link ?>
            <?php echo $this->getReviewsSummaryHtml($_product, false, true)?>
            <?php //echo $this->helper('catalog/product')->getPriceHtml($_product) ?>
            <?php echo $this->getPriceHtml($_product) ?>
            <?php echo $_product->getProductId(); ?>
            <?php if($_product->getevent_date()) {echo $_product->getevent_date();} ?>
</div>
</div>
<?php $i++; endforeach; ?>
<?php for($i;$i%5!=0;$i++): ?>
    <?php endfor ?>
</div>
<?php endif; ?>

now put this line where you want to view best selling products..

you can use through block or through XML also

{{block type=”catalog/product_bestseller” template=”catalog/product/bestseller.phtml”}}

 

<block type=”catalog/product_bestseller” name=”bestseller” template=”catalog/product/bestseller.phtml”>

 

Hope this will help you!

Magneto Get Router.Controller,Module,Action Name

Generally we get confused while checking the controller name .so require to known name for the controller,router,module,action.Below are the following methods which will help to get the controllers ,action ..etc as per the need

IN TEMPLATE FILES
$this->getRequest() can be used

get Controller name
$this->getRequest()->getControllerName();

get Action name, i.e. the function inside the controller
$this->getRequest()->getActionName();

get Router name
$this->getRequest()->getRouteName();

get module name
$this->getRequest()->getModuleName();

IN CLASS FILES menas php files
$this might not work.In this case, you need to use Mage::app().

get Controller name
Mage::app()->getRequest()->getControllerName();

get Action name, i.e. the function inside the controller
Mage::app()->getRequest()->getActionName();

get Router name
Mage::app()->getRequest()->getRouteName();

get module name
Mage::app()->getRequest()->getModuleName();

This functions (getControllerName, getActionName, getRouteName, getModuleName)
are present in the class Mage_Core_Model_Url.

Hope this will help You….