Saturday, February 18, 2012

Magento : Add extra links to top links in header


We always need to add links apart from default top links in magento.
Here are the steps to add extra links to top links without touching the core files.

1)   Find   "<block type="page/template_links" name="top.links" as="topLinks"/>" in
page.xml    and paste just below this

<!--Added for showing extra links below top links start("/Clients/slendersbeauty/index.php" should be removed in below three links when go live)-->
                <block type="page/template_links" name="header_links" as="header_links" template="page/template/header_links.phtml">
                    <action method="addLink" translate="label title" ><label>AANBIEDINGEN</label><url>/aanbiedingen</url><title>AANBIEDINGEN</title><prepare/><urlParams/><position>10</position></action>
                    <action method="addLink" translate="label title" ><label>OVER ONS</label><url>/about-magento-demo-store</url><title>OVER ONS</title><prepare/><urlParams/><position>10</position></action>
                    <action method="addLink" translate="label title" ><label>CONTACT</label><url>/contacts</url><title>CONTACT</title><prepare/><urlParams/><position>10</position></action>
                </block>
            <!--Added for showing extra links below top links end-->


2)  Copy    /app/design/frontend/base/default/template/page/template/links.phtml
to  a file /app/design/frontend/base/default/template/page/template/header_links.phtml

3)  In /app/design/frontend/base/default/template/page/html/header.phtml
paste     <?php echo $this->getChildHtml('header_links') ?>
where you want to appear the above links.

and now you can see the extra links apart from top links in header .

Magento : Special product Page

Magento : Special product Page

For showing special products(products which have special price) in a cms page ,
follow the below steps:

1) Create a file   "/app/code/local/Mage/Catalog/Block/Product/Special.php "
     with following contents:




     <?php
if(version_compare(Mage::getVersion(), '1.4.0.0', '>=') || version_compare(Mage::getVersion(), '1.6.0.0', '<=')){
//Code
class Mage_Catalog_Block_Product_Special extends Mage_Catalog_Block_Product_List
{
   function get_prod_count()
   {
      //unset any saved limits
      Mage::getSingleton('catalog/session')->unsLimitPage();
      return (isset($_REQUEST['limit'])) ? intval($_REQUEST['limit']) : 12;
   }// get_prod_count

   function get_cur_page()
   {
      return (isset($_REQUEST['p'])) ? intval($_REQUEST['p']) : 1;
   }// get_cur_page

   /**
    * Retrieve loaded category collection
    *
    * @return Mage_Eav_Model_Entity_Collection_Abstract
   **/
   protected function _getProductCollection()
   {
      $todayDate = date('m/d/y');
      $tomorrow = mktime(0, 0, 0, date('m'), date('d')+1, date('y'));
      $tomorrowDate = date('m/d/y', $tomorrow);


            
        $collection = Mage::getResourceModel('catalogsearch/advanced_collection')
            ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
            ->addMinimalPrice()
            ->addStoreFilter();
       
        Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
        Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($collection);
       
        $collection->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $todayDate))
            ->addAttributeToFilter('special_to_date', array('or'=> array(
            0 => array('date' => true, 'from' => $tomorrowDate),
            1 => array('is' => new Zend_Db_Expr('null')))
            ), 'left');


      $this->setProductCollection($collection);

      return $collection;
   }// _getProductCollection
}// Mage_Catalog_Block_Product_Special
}


2)  Create a CMS page "SPECIAL" by going to
Magento -> Admin ->CMS -> Pages

3)  In the above CMS page
Go to Design-> Layout Update XML
and
Paste



<reference name="content">
   <block type="catalog/product_special" name="product_new" template="catalog/product/list.phtml">
      <action method="setCategoryId"><category_id>10</category_id></action>
      <action method="setColumnCount"><column_count>6</column_count></action>
      <action method="setProductsCount"><count>0</count></action>
      <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
         <block type="page/html_pager" name="product_list_toolbar_pager" />
         <action method="setDefaultGridPerPage"><limit>12</limit></action>
         <action method="addPagerLimit"><mode>grid</mode><limit>12</limit></action>
         <action method="addPagerLimit"><mode>grid</mode><limit>24</limit></action>
         <action method="addPagerLimit"><mode>grid</mode><limit>36</limit></action>
         <action method="addPagerLimit"><mode>grid</mode><limit>48</limit></action>
         <action method="addPagerLimit" translate="label"><mode>grid</mode><limit>all</limit><label>All</label></action>
      </block>
      <action method="addColumnCountLayoutDepend"><layout>one_column</layout><count>6</count></action>
      <action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
   </block>
</reference>


 


Your CMS Page is created .
You can see your page at
www.yoursite.com/SPECIAL

---------------------------------------------------------------------------------------------------

If you want special product on homepage

Paste
<reference name="content">
<block type="catalog/product_special" name="catalog_product_special" as="product_homepage"  template="catalog/product/lists.phtml"/>
</reference>

in Layout Update XML of "Home Page" CMS

A useful link also is available at:
http://www.dnawebagency.com/displaying-new-products-in-magento-with-pagination