Saturday, 4 November 2017

How to Rewrite / Override block in magento

How to Rewrite / Override block in magento

Here we are Overriding / Rewriting magento block of Mage_Catalog_Block_Product_View with custom module named Chand_Software.

(1) Create module file in app/etc/modules/Chand_Software.xml

<?xml version="1.0"?>

(2) Create module config file in app/code/local/Chand/Software/etc/config.xml

<?xml version="1.0"?>
            <catalog>  // This is the block identifier which we want rewrite

(3) Now Create block file of our custom module in app/code/local/Chand/Software/Block/Product/View.php

class Chand_Software_Block_Product_View extends Mage_Catalog_Block_Product_View
     * Put your logic here

How to add css in only product type simple in magento

How to add css in only product type simple in magento

First to create local.xml file at this path app/design/frontend/yourpackage/default/layout/local.xml and paste below code in local.xml

<?xml version="1.0"?>

<layout version="0.1.0">

            <reference name="head">
                <action method="addCss"><stylesheet>css/your_simple.css</stylesheet></action>


Handle of different product types :


How to make timer that not reset when page refresh javascript

<form name="counter">
    <input type="text" size="8" name="jimmy" id="counter">

<script type="text/javascript">
function getCookie(cname) {
    var name = cname + "=";
    var decodedCookie = decodeURIComponent(document.cookie);
    var ca = decodedCookie.split(';');
    for(var i = 0; i <ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') {
            c = c.substring(1);
        if (c.indexOf(name) == 0) {
            return c.substring(name.length, c.length);
    return "";

var cnt = 60;
function counter(){
    if(getCookie("cnt") > 0){
  cnt = getCookie("cnt");
 cnt -= 1;
 document.cookie = "cnt="+ cnt;




How to add css and js file in head section opencart

Include Css file code:


Include Js file code:


How to append GET parameters in url PHP

First make one function like below


$param = GET;

function filter_url($url,$param){

    $parsed = parse_url($url);
    $query = str_replace("&amp;","&",$parsed['query']);
    $new_query = http_build_query($params);
    $newUrl = $parsed['scheme']."://".$parsed['host'].$parsed['path'];
        $newUrl .= "?".$new_query;
    return $newUrl;