Thursday, February 20, 2014

Magento Notes - I

Here I discuss some quick tips for Magento 1.8. 

1. How to set "One-column" template to Category Page?

   a. If you use 'base' package's 'default' theme, open app/design/frontend/base/default/layout/catalog.xml 
   
   b. If you have defined your own theme in 'default' package and overridden the above file, then open app/design/frontend/default/YOUR_THEME/layout/catalog.xml 

   Locate the following :: 
   
  <catalog_category_default translate="label">
    <label>Catalog Category (Non-Anchor)</label>

   Add the following ::  

   
  <reference name="root">
<action method="setTemplate">
             <template>page/1column.phtml</template>
         </action>
  </reference>

2. How to Resize Image in Product Listing Page ?
  
   Open app/design/frontend/YOUR_PACKAGE/YOUR_THEME/catalog/product/list.phtml

   Add the following <image> tag where necessary. We are resizing image to 218x317 (width x height). Product object "$_product" is already available to you.

   <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(218,317); ?>" width="218" height="317" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />

3. How to Resize Image in Product Details Page ?

   Open app/design/frontend/YOUR_PACKAGE/YOUR_THEME/template/catalog/product/view/media.phtml

   Add following <image> tag where necessary.

   <img id="image" src="<?php echo $this->helper('catalog/image')->init($_product, 'image')->resize(338,438);?>" alt="<?php echo $this->escapeHtml($this->getImageLabel());?>" title="<?php echo $this->escapeHtml($this->getImageLabel());?>" />

4. How to call a static block from inside the phtml file?

   If we have already defined any static block in Admin Panel, we can call it from within view (.PHTML) files. We just need to have its identifier. Then use the following code where necessary.
  
   <?php 
  echo $this->getLayout()->createBlock('cms/block')->setBlockId('STATIC_BLOCK_IDENTIFIER')->toHtml(); 
 ?>
   
   Make sure you replace the 'STATIC_BLOCK_IDENTIFIER' with the real one.

5. How to fix the error "TypeError: productAddToCartForm is undefined" Magento?
  
   This Javascript error may crop up on your product details page when "Add to Cart" to button is clicked. This happens because of the conflict between existing Prototype JS library and jQuery (which you added later).

   Simple solution is to add "jQuery.noConflict();" statement after you have included your jQuery Library file.
   
6. How to get current product's Category name?

   I assume that you have $_product object at your disposal. Then, use the code below to get Category names. A product can belong to multiple categories. 
   
<php 
  // Get All Category IDs
   $cat = $_product->getCategoryIds(); 

   // Get First Category Name
   $cat_name = Mage::getModel('catalog/category')->load($cat[0])->getName();
?>

For More, check out my next article Magento Notes - II.

No comments: