PHP SOLUTIONS

This is the blog for getting Idea regarding PHP, Magento, jQuery and JavaScript for Customization.

Wednesday 31 October 2012

Magento : get CMS static block using XML file


A) Create one Static Block in CMS > Static block Admin

       1.  Block Title =  heders_links
       2.  Identifier    =  heders_links
       3.  Status        =  Enable
       4.  Content     =  "Give your Custom Design Layout"
             ex.
            <ul class="header-menu">
                     <li><a href="{{store direct_url=''}}">Home</a></li>
                     <li><a href="{{store direct_url='about-magento-demo-store'}}">About Us</a></li>
                     <li><a href="{{store direct_url='catalogsearch/advanced/'}}">Advanced Search</a></li>
                     <li><a href="{{store direct_url='contacts/'}}">Contact Us</a></li>
            </ul>


B)  Copy code inside page.xml file


     <block type="cms/block" name="header_links">
                    <!--
                        The content of this block is taken from the database by its block_id.
                        You can manage it in admin CMS -> Static Blocks
                     -->
                    <action method="setBlockId"><block_id>header_links</block_id></action>
            </block>

Tuesday 30 October 2012

Magento : get category list on Home page


Actually There are various types to get category List but I suggest two way for this,

1) First One

Simply follow bellow steps to get Category List on Home page,

A) Create a one Phtml file inside

     app/design/frontend/base/default/template/catalog/navigation/

     use file name left_navcategory.phtml

B) Now, Copy below code and paste in left_navcategory.phtml

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

<?php
$obj = new Mage_Catalog_Block_Navigation();
$store_cats    = $obj->getStoreCategories();
$current_cat     = $obj->getCurrentCategory();
$current_cat    = (is_object($current_cat) ? $current_cat->getName() : '');

foreach ($store_cats as $cat) {
    if ($cat->getName() == $current_cat) {
        echo '<li class="current"><a href="'.$this->getCategoryUrl($cat).'">'.$cat->getName()."</a>\n<ul  id='nav_category' class='nav_category'>\n";
        foreach ($obj->getCurrentChildCategories() as $subcat) {
            echo '<li><a href="'.$this->getCategoryUrl($subcat).'">'.$subcat->getName()."</a></li>\n";
        }
        echo "</ul>\n</li>\n";
    } else {
        echo '<li><a href="'.$this->getCategoryUrl($cat).'">'.$cat->getName()."</a></li>\n";
    }
}
endif ?>


C) Create one Block for that in Catalog.xml under

<reference name="left">
   <block type="catalog/navigation" name="catalog.left_navcategory" template="catalog/navigation/left_navcategory.phtml" />
</reference>



Magento : Create featured product


There is easy few steps to create Featured Product,

A) First Create a One Attribute :

    Set this under "Property Teb" of Right side, 

         1.  Attribute Code *                                        =      featured
         2. Scope                                                         =      Store View
         3. Catalog Input Type for Store Owner            =      Yes/No

  Set this under "Manage Label/Options Teb" of Right side, 

        1.  Admin                        =    Featured Product
        2.   Default Store View    =    Featured Product 


B) Now goto Catalog > Attribute > Manage Attribute Set

    1. Click on Default Attribute set,
    2. Here, see your  fetured attribute under Unassigned Attributes,  Drag that attribute inside Groups  general  directory
    3. Save



Monday 29 October 2012

Magento : Get logged customers details

There are two type

A) To get Specific Details of customer


<?php

          if(Mage::getSingleton('customer/session')->isLoggedIn())
          {
                   /* If Customer Log In to System */

                   echo $this->_data['welcome'] = $this->__('Welcome, %s!', Mage::getSingleton('customer/session')->getCustomer()->getId());

                  echo $this->_data['welcome'] = $this->__('Welcome, %s!', Mage::getSingleton('customer/session')->getCustomer()->getName());

          } 
          else
         {
                   /* If Customer not Log In to System */
                   echo "Not Log In";
         }

 ?>

B) To get all Session Details of customer


<?php

          if(Mage::getSingleton('customer/session')->isLoggedIn())
          {
                   /* If Customer Log In to System */

                   $customer = Mage::getSingleton('customer/session')->getCustomer();
   print_r($customer);
   echo $taxVat = $customer->getData('taxvat');
          } 
          else
         {
                   /* If Customer not Log In to System */

                   echo "Not Log In";
         }

 ?>

Friday 26 October 2012

Magento : Get value of CMS Static Block using XML file



This is a XML block, Simply use this in your XML file of layout directory,


<block type="cms/block" name="Here Id of your Static block">
<!--
The content of this block is taken from the database by its block_id.
You can manage it in admin CMS -> Static Blocks
-->
<action method="setBlockId"><block_id>"Here Id of your Static block"</block_id>                                 </action>
</block>


For Example,


<block type="cms/block" name="header_block">
<action method="setBlockId"><block_id>"header_block"</block_id>                                 </action>
</block>

As per example, Here "header_block" is a static block in CMS->Static Block .

Monday 15 October 2012

Magento : Set Google Translator


<!-- Put this code in Header File -->
<!-- File Path ::=> app/design/frontend/base/default/template/page/html/header.phtml-->


 <div id="google_translate_element"></div>
<script>
         function googleTranslateElementInit()
        {
new google.translate.TranslateElement({
      pageLanguage: 'en'
}, 'google_translate_element');
}
</script>
<script src="http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>