Remove .std div (wrapper) from Magento CMS Pages through xml

Add below xml code to local.xml of your current theme or cms.xml file.

1. Remove from all cms pages.

    <reference name="content">
        <remove name="cms.wrapper"/>

2. Remove from CMS Home page only

    <reference name="content">
        <remove name="cms.wrapper"/>

Display Magento cart total Block in custom pages or XML

There is a two way to display checkout cart total block to any page.

1. Through .phtml

    // Method 1: 
              echo $this->getLayout()->createBlock('checkout/cart_totals')

    // Method 2: 
               $layout = $this->getLayout();
               $total_html = $layout->getBlock('checkout.cart.totals')->toHtml();
               echo $total_html;

2. Through xml

<reference name="content">
    <block type="checkout/cart_totals" name="" template="checkout/cart/totals.phtml" />

Split single table field to two separate fields in Magento collection

Here is the example of split order street address in to 2 separate fields separated by ‘n’ newline.

$collection = Mage::getModel('sales/order_address')->getCollection()
                    'IF(LOCATE("n", {{full_street}}) > 0,
                        SUBSTRING({{full_street}}, 1, LOCATE("n", {{full_street}}) - 1),
                        {{full_street}} )',
                array('full_street' => 'street'))

                    'IF(LOCATE("n", {{full_street}}) > 0,
                        SUBSTRING({{full_street}}, LOCATE("n", {{full_street}}) + 1),
                        NULL )',
                array('full_street' => 'street'));            

On print_r($collection->getData()); you can see the 2 new field added to result ‘street_line1′ and ‘street_line2′.

Note : Use ‘addExpressionAttributeToSelect’ if not works ‘addExpressionFieldToSelect’.

Merge two table fields to single in Magento collection

Here is the example of merging Product name and SKU from Order Item collection by ‘ ‘ Space.

$collection = Mage::getResourceModel('sales/order_item_collection')
                'CONCAT({{itemsku}}, ' ', {{itemname}})',
                array('itemsku' => 'sku', 'itemname' => 'name'));


On print_r($collection->getData()); you can see the one new field added to result ‘skuname’ having sku and name merged by ‘ ‘ space.
Note : Use ‘addExpressionAttributeToSelect’ if not works ‘addExpressionFieldToSelect’.

create tar in php

PharData is PHP Class that can be used to create tar and tar.gz compressed files.
It works for php 5.3+ onwards. Lets have a look.


$file = new PharData('compress.tar');    

// Adding single files

// Adding Directory 

// Compress tar


Magento custom search engine supported (SEO) URL.

1. Create Helper file and function in your module to use throughout of your project.

class <Namespace>_<Module>_Helper_Data extends Mage_Core_Helper_Abstract
    public function geturlRewrite($id_path, $request_path, $target_path, $store_id ="0", $is_system=false)
        $isrewrite = Mage::getModel('core/url_rewrite')->load($id_path,id_path);

        if($isrewrite->url_rewrite_id !=""){
            $rewrite = Mage::getModel('core/url_rewrite')->load($isrewrite->url_rewrite_id);
           //throw new Exception("Your Id path must be unique, given id path already in use !");
            $rewrite = Mage::getModel('core/url_rewrite');

        return true;

    // Generate seo url from author name (any string)
    public function formatAuthorUrl($str)
        $urlKey = preg_replace('#[^0-9a-z]+#i', '-', Mage::helper('catalog/product_url')->format($str));
        $urlKey = strtolower($urlKey);
        $urlKey = trim($urlKey, '-');
        return $urlKey;

2. Call the helper function on save Action of any controller based on your requirement OR
You may also use helper function any where in project where required.

public function saveAction()
// .... faq saving process
$aincr = $model->save()->getId();

// Generate URL key
        $id_path = "author/".$aincr;  // Id path must be unique
        $request_path = "author/".Mage::helper('<Namespace>_<Module>')->formatAuthorUrl($authorName);
        $target_path  = "author/index/index/id/".$aincr.";                 
        Mage::helper('<Namespace>_<Module>')->geturlRewrite($id_path, $request_path, $target_path);    
        $slug['author_slug'] = $request_path;
    catch (Exception $e) {                 

Add Custom Tab in Product view page.

1. Add below xml code at appdesignfrontendyour packageyour themelayoutlocal.xml

     <reference name="">
           <block type="catalog/product_view" name="" after="product.description" as="authorbio" template="catalog/product/view/author-bio.phtml">
                   <action method="addToParentGroup"><group>detailed_info</group></action>
                    <action method="setTitle" translate="value"><value>Author Bio</value></action>
<!-- Here we have added Author Bio as extra tab -->

2. Create new file for content to show – appdesignfrontendyour packageyour themetemplatecatalogproductviewauthor-bio.phtml

Here example of Product attribute ‘Author bio’ content or you may write your own content here

$_authorid = $this->getProduct()->getAuthor(); // Get Product Attribute
$author = Mage::getModel('krish_author/author')->getCollection()
          ->addFieldToFilter('author', $_authorid)->getFirstItem();

if ($author->getId()): 
    <h2><?php echo $this->__('About '.$this->getProduct()->getAttributeText('author')) ?></h2>
    <div class="std">   	
        <?php if($author->getAuthorImage() != '') echo '<img src="'.$author->getAuthorImage().'" class="author_image"/>'; ?>    
        <?php if($author->getAuthorInfo() != '') echo '<b>About '.$this->getProduct()->getAttributeText('author').' :</b> '.$author->getAuthorInfo(); ?>
        <?php if($author->getAuthorLinks() != '') echo '<b>Realted Links: </b>'.$author->getAuthorLinks(); ?>
<?php endif; ?>


Display Multiselect product attribute Values

    // Here 'author' is multiselect product attribute.
    $authors = $_product->getAttributeText('author'); 
    $author_names = (is_array($authors)) ? implode( ', ', $authors) : $authors; 
    // Comma separated values, You can change your convenient.
    if($author_names!= ''):
        echo $author_names;