Saturday 4 November 2017

How do i reverse parse_url in PHP


$parsed = parse_url($url);

You can reverse back parse url like below

$newUrl = $parsed['scheme']."://".$parsed['host'].$parsed['path'];
$new_query = http_build_query($params);
if($new_query){
    $newUrl .= "?".$new_query;
}

Friday 10 February 2017

How to add css and js file in head section opencart


How to add css and js file in head section opencart

Include Css file code:

$this->document->addStyle('catalog/view/theme/themename/stylesheet/product.css');


Include Js file code:

$this->document->addScript('catalog/view/theme/themename/js/product.js');

Saturday 28 January 2017

How to make counter not reset on page refresh javascript


How to make counter not reset on page refresh javascript

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

<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;
jQuery("#counter").val(getCookie("cnt"));

if(cnt>0){
setTimeout(counter,1000);
}

}

counter();
</script>

Monday 12 December 2016

How to add sku column in sales order grid magento admin


How to add sku column in sales order grid magento admin

Note: For not to override magento core functionality, You can create your own module and use the below code in Grid.php

Open app\code\core\Mage\Adminhtml\Block\Sales\Order\Grid.php

Replace the below function

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->_getCollectionClass());
    $collection->getSelect()->joinLeft(
            'sales_flat_order_item',
            '`sales_flat_order_item`.order_id=`main_table`.entity_id',
            array('skus'  => new Zend_Db_Expr('group_concat(`sales_flat_order_item`.sku SEPARATOR ",")'))
    );
    $collection->getSelect()->group('entity_id');
   
    $this->setCollection($collection);
    return parent::_prepareCollection();
}

Now put the below code in _prepareColumns() function

$this->addColumn('sku', array(
    'header' => Mage::helper('sales')->__('SKU'),
    'index' => 'skus',
    'type' => 'text',
    'width' => '100px',
    'filter'    => false,
));

Friday 9 December 2016

Swap variable values in php


Swap variable values in php

<?php
$a = 40;
$b = 50;

$temp = $a;
$a = $b;
$b = $temp;

echo $a;
echo $b;

OR

Swap values without third variable

$a = 40;
$b = 50;

$a = $a+$b;
$b = $a - $b;
$a = $a - $b;

echo $a;
echo $b;

?>