Friday, September 13, 2013

How to overwrite magento controller in local directory

For Example you have to overwrite Mage/Contacts/controller/IndexController.php
Step 1: First you have to make a xml in app/etc/modules/ with name CompanyName_NameSpace.xml true local 0.1.0

Step2: You have to create the folders if not exist in local/CompanyName/NameSpace/etc/ local/CompanyName/NameSpace/controllers/ In etc folder you have to create a config.xml file Shweta_Newscontacts In controllers folder copy the Mage/Contacts/controller/IndexController.php file and include the lines: include_once('Mage/Contacts/controllers/IndexController.php'); and change the class name as: class CompanyName_NameSpace_IndexController extends Mage_Core_Controller_Front_Action Now apply changes in the file you wanted. Now also, Magento take local pool file instead of core pool.

customize of label "choose an option" of configurable product in magento

Step 1: Change in catalog/product/view/type/options/configurable.phml getProduct(); $_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes()); ?> isSaleable() && count($_attributes)):?>
getAttributeId(); $_attributeInfo = Mage::getModel('eav/entity_attribute')->load($_attributeId); $_attributeLabel = str_replace(' ','-',strtolower($_attributeInfo->getFrontendLabel())); ?>
decoratedIsLast){?> class="last">
Step 2: js/varien/configurable.js replace line 171 = element.options[0] = new Option(element.config.label, '');

 Step 3: app/design/frontend/default/grayscale/template/catalog/product/view/type/options/configurable.php change this line: 'label' => 'choose a '.$attribute->getLabel(),

Monday, August 26, 2013

magento remove Product Type virtual product,bundle product and downloadable product.

app/code/core/mage/catalog/model/product/type.php

static public function getOptionArray()
    {
        $options = array();
        foreach(self::getTypes() as $typeId=>$type)
        {
            if($type['label'] != "Virtual Product" && $type["label"] != "Grouped Product" && $type["label"] != "Downloadable Product" && $type["label"] != "Bundle Product")
            {
                $options[$typeId] = Mage::helper('catalog')->__($type['label']);
            }
        }

        return $options;
    }

Wednesday, August 7, 2013

Magento display all categories from product id (product listing page and search product listing page).

$product_model = Mage::getModel('catalog/product');
$product_model->reset();
$_product = $product_model->load($_product->getId());
$all_cats = $product_model->getCategoryIds($_product);
foreach($all_cats as $key => $_categoryId)
{
$category = Mage::getModel('catalog/category')->load($_categoryId);
echo "<br />".$category->getName();
}

Monday, August 5, 2013

PHP Script to calculate time from specific date(Like Facebook)

function time_passed($timestamp)

    $timestamp      = (int) $timestamp;
    $current_time   = time();
    $diff           = $current_time - $timestamp;
  
    $intervals      = array ('year' => 31556926, 'month' => 2629744, 'week' => 604800, 'day' => 86400, 'hour' => 3600, 'minute'=> 60);
  
    if ($diff == 0)
    {
        return 'just now';
    }  

    if ($diff < 60)
    {
        return $diff == 1 ? $diff . ' second ago' : $diff . ' seconds ago';
    }      

    if ($diff >= 60 && $diff < $intervals['hour'])
    {
        $diff = floor($diff/$intervals['minute']);
        return $diff == 1 ? $diff . ' minute ago' : $diff . ' minutes ago';
    }      

    if ($diff >= $intervals['hour'] && $diff < $intervals['day'])
    {
        $diff = floor($diff/$intervals['hour']);
        return $diff == 1 ? $diff . ' hour ago' : $diff . ' hours ago';
    }  

    if ($diff >= $intervals['day'] && $diff < $intervals['week'])
    {
        $diff = floor($diff/$intervals['day']);
        return $diff == 1 ? $diff . ' day ago' : $diff . ' days ago';
    }  

    if ($diff >= $intervals['week'] && $diff < $intervals['month'])
    {
        $diff = floor($diff/$intervals['week']);
        return $diff == 1 ? $diff . ' week ago' : $diff . ' weeks ago';
    }  

    if ($diff >= $intervals['month'] && $diff < $intervals['year'])
    {
        $diff = floor($diff/$intervals['month']);
        return $diff == 1 ? $diff . ' month ago' : $diff . ' months ago';
    }  

    if ($diff >= $intervals['year'])
    {
        $diff = floor($diff/$intervals['year']);
        return $diff == 1 ? $diff . ' year ago' : $diff . ' years ago';
    }
}
echo time_passed(strtotime('2012-08-05')) . '<br />';