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’.

Sort Magento1 and Magetno2 Products using Drag & Drop

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;