Sunday, 21 October 2012

Add Custom PHTML Templates to Magento CMS Pages


1) Add The New Template File

The first step in this process is to create the new PHTML template file. You don’t need to develop the template yet. Just create an empty placeholder or copy and rename an existing file.
The important thing is to save your new PHTML template file to app > design > frontend > default > modern > template > page, wherein “default” is the name of the package and “modern” is the name of the template. If your package was named “Fred” and your theme was called “Astaire,” the path would be app > design > frontend > Fred > Astaire > template > page.

2) Mirror the Core File Structure in Local

From a development standpoint, one of Magento’s best features is its ability to mirror core files. In this way, you can make changes to what are clearly core functions or files without worrying about future updates erasing those changes or breaking your site.
Navigate to app > code > local. Create a new folder called “Mage.” Inside of the “Mage” folder, create a new folder named “Page.” Open “Page” and create a folder called “etc.” In this way, you will have mimicked the folder structure of one portion of the Magento core.

Get a copy of config.xml


Now open config.xml 
Add the following code under <layout> tag:-
  1. <twelve_columns module="page" translate="label">
                      <label>12 columns</label>
                      <template>page/12columns.phtml</template>
                      <layout_handle>page_12_columns</layout_handle>
                </twelve_columns>


4) Update Mage_All.xml

I need to update MageAll.xml_, which can be found at app > etc > modules.
In this file, I need to locate the “Mage_Page” module. It will look like the following code.
  1.         <Mage_Page>
  2.             <active>true</active>
  3.             <codePool>core</codePool>
  4.             <depends>
  5.                 <Mage_Core/>
  6.             </depends>
  7.         </Mage_Page>
Between the “codePool” tags, I need to change “core” to “local.”
  1.         <Mage_Page>
  2.             <active>true</active>
  3.             <codePool>local</codePool>
  4.             <depends>
  5.                 <Mage_Core/>
  6.             </depends>
  7.         </Mage_Page>

6) Flush Magento Cache

7) Check the new template

Go to CMS > Pages > Home page > Design in the Magento administration panel

Saturday, 20 October 2012

Skip Login/Registration at Checkout


We are going to:
  1. Hide Step 1
  2. Tell Magento that Step 1 was “completed” as Guest
  3. Have Step 2 appear as Step 1

1. Hiding Step 1 – Login/Register
Open /app/design/frontend/<your_company>/<your_company>/template/checkout/onepage.phtml
Find:

<li id="opc-<?php echo $_stepId ?>" {...}


And replace it with:

<li <?php echo $i==1 ? 'style="display:none;"' : '' ?> id="opc-<?php echo $_stepId ?>"  {...}


2. Set Step 1 to equal Guest
Open /app/design/frontend/<your_company>/<your_company>/template/checkout/onepage/login.phtml
Basically, comment everything out and insert:

<input type="hidden" name="checkout_method" id="login:guest" value="guest" checked="checked" />
<script type="text/javascript">
Event.observe(window, 'load', function() {
checkout.setMethod();
});
</script>


3. Make Step 2 look like Step 1
Open /app/design/frontend/<your_company>/<your_company>/template/checkout/onepage.phtml
Find:
$i=0; foreach($this->getSteps() as $_stepId => $_stepInfo):
And replace it with:
$i=-1; foreach($this->getSteps() as $_stepId => $_stepInfo):
Finally, in the same file, change this snippet that we added in step 1:
echo $i==1
to:
echo $i===0

Saturday, 16 June 2012

Send Email in magento



 // Transactional Email Template's ID

            $templateId = 1;

            // Set sender information

            $senderName = Mage::getStoreConfig('trans_email/ident_support/name');          
$senderEmail = Mage::getStoreConfig('trans_email/ident_support/email');
            $sender = array('name' => $senderName,
            'email' => $senderEmail);

            // Set recepient information(Let, $email has recepient information )

            $recepientEmail = $email['emailid'];
            $recepientName = $email['name']." ".$email['surname'];

            // Get Store ID

            $store = Mage::app()->getStore()->getId();

            // Set variables that can be used in email template

            $vars = array('customerName' => $email['name']." ".$email['surname'],
            'customerEmail' => $email['emailid'],'companydetail'=>$email['company_detail']);
            $translate = Mage::getSingleton('core/translate');

            // Send Transactional Email

            Mage::getModel('core/email_template')
            ->sendTransactional($templateId, $sender, $recepientEmail, $recepientName, $vars, $storeId);
            $translate->setTranslateInline(true);






Friday, 15 June 2012

Display sub-categories on category page



First create a new phtml file and save it in your/app/design/frontend/default/yourTheme/template/catalog/category folder.


1-     we have to find the category id for the page we're looking at. (This code will only be called when we're on a category page). We find the id with the following code:

//get the current category
$_cat = new Mage_Catalog_Block_Navigation();
$currentCat = $_cat->getCurrentCategory();

              
2-    This gives us the current category, in the next step we'll use its id to find the sub categories (children) associated with it.

//get the children of the current category
$subCats = Mage::getModel('catalog/category')
              ->load($currentCat->getId())->getChildren();

                              
                              
3-    $subCats now contains a comma separated list of the ids of the sub categories. We need to get rid of the commas:

//get sub category ids
$subCatIds = explode(',',$subCats);
                              
4-    Now the last step is-

<?php if (count($subCatIds) > 1): ?>
 <ul>
  <?php foreach($subCatIds as $subCatId): ?>
   <?php $subCat = Mage::getModel('catalog/category')->load($subCatId); ?>
               <?php if($subCat->getIsActive()): ?>
                <li>
      <?php //display category image
                 if($subCat->getImageUrl()): ?>
                  <img src="<?php echo $subCat->getImageUrl(); ?>" />
                 <?php endif; ?>
                 <a href="<?php echo $subCat->getUrl(); ?>">
                 <?php echo $subCat->getName(); ?>
                 </a>
                </li>
               <?php endif; ?>
   <?php endforeach; ?>
  </ul>
<?php endif; ?>