Friday, 4 March 2016

Magneto 2 installation

1. Download Magento 2.02 from https://www.magentocommerce.com/download


2. Put your downloaded folder in www/html
suppose my folder name is m2

go to
cd /var/www/html/m2

3. Make webdata in you user list
chown -R  :www-data .

4. Set file permission:

  sudo find . -type d -exec chmod 770 {} \; && sudo find . -type f -exec chmod 660 {} \; && sudo chmod u+x bin/magento

5. Create virtual host
suppose we created http://local.m2/

6. Start installation

sudo php bin/magento setup:install --base-url=http://local.m2/ \
--db-host=localhost --db-name=magento --db-user=magento --db-password=magento \
--admin-firstname=Magento --admin-lastname=User --admin-email=user@example.com \
--admin-user=admin --admin-password=admin123 --language=en_US \
--currency=USD --timezone=America/Chicago --use-rewrites=1


Installation will complete after a while and it will give you admin url

7. Give full permission to some public folder
sudo chmod -R var/
cd pub/
sudo chmod -R media/ static/


Thats all
go to your url
http://local.m2/
and

http://local.m2/admin_xxxx











Monday, 18 January 2016

adding conditional css for firefox


var j = jQuery.noConflict();
if ( j.browser.mozilla == true ) {
      document.write('<link type="text/css" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">');
 } else {
document.write('<link type="text/css" rel="stylesheet" href="../css/font-awesome.min.css">');
 }

Wednesday, 30 December 2015

Creating a jquery function to make all class with same height

 //Creating a jquery function to make all class with same height

function equaliseDivOnClass(class1){
                    var j = jQuery.noConflict();
     var divheights = 0;
j("."+class1).each(function( i ) {
  if(j(this).height() > divheights){
divheights = j(this).height();
  }
    });
j("."+class1).height(divheights);
   }


Usage: equaliseDivOnClass("f-desc");



------------------------------
//Creating a jquery function to make 2 div with different id same height

function equaliseDiv(div1, div2){
               var j = jQuery.noConflict();
x = j(div1).height();
y = j(div2).height();
if (x > y) {
j(div2).height(x); }
else {
j(div1).height(y);
}

   }

Usage: equaliseDiv("#s1", "#s2");

Thursday, 26 February 2015

Logging all the sql in Magento for debug

In Magento development you need some time to check the sql query running in the background

For this you can insert a code into the lib/Varian/Db/Adaptor/Pdo/Mysql.php


$code = 'SQL: ' . $sql . "\r\n";
if ($bind) {
       $code .= 'BIND: ' . print_r($bind, true) . "\r\n";
}
$this->_debugWriteToFile("[".date('Y-m-d H:i:s')."] ".$code);


in your query method of the page.
now your query method look like

    public function query($sql, $bind = array())
    {
        $this->_debugTimer();
        try {
            $this->_checkDdlTransaction($sql);
            $this->_prepareQuery($sql, $bind);
         
/* Inserted code Starts */
           $code = 'SQL: ' . $sql . "\r\n";
           if ($bind) {
                $code .= 'BIND: ' . print_r($bind, true) . "\r\n";
          }
          $this->_debugWriteToFile("[".date('Y-m-d H:i:s')."] ".$code);
/* Inserted code Starts */

            $result = parent::query($sql, $bind);
        } catch (Exception $e) {
            $this->_debugStat(self::DEBUG_QUERY, $sql, $bind);
            $this->_debugException($e);
        }
        $this->_debugStat(self::DEBUG_QUERY, $sql, $bind, $result);
        return $result;
    }


You can find the log at /var/debug/pdo_mysql.log


Mage::log("MyArray:".print_r($arr,true), null, 'logfile.log');

Friday, 12 December 2014

getting top category on the product listing or product details page

create a method in your helper:

<?php
class Rajiv_Catalog_Helper_Data extends Mage_Core_Helper_Abstract {
public function getTopCat(){
$category = Mage::registry('current_category');
$it = 10; //Amount of iterations before script gives up

if ($category) {
while($category->getLevel() != 2 && $it > 0) {
$category = $category->getParentCategory();

if (!$category) {
break;
}
}

if ($category) {
return $category->getName();
}
return;
}
}
}


----

Call the method anywhere as

echo Mage::helper('rajiv_catalog')->getTopCat();

Monday, 24 November 2014

How to get Magento 1.9.0.1 If official download link is breaking


From some time I found that official download link of magento CE at the magento site is breaking.
So you can use the alternative way for this to get it from github


Here is the magento mirror for Magento CE version 1.9.0.1

https://github.com/OpenMage/magento-mirror



You can also get sample data for CE 1.9.0.1 at following location of github

https://github.com/Vinai/compressed-magento-sample-data

I greatly appreciate the concerned contributor/author to github  who have contributed this github for the public use.


This blog is only the benefit of public who facing issue with download link on the official site. However I recommend that you always try to take a copy for the official magento site(which will be more reliable).

NOTE: This article is also not a way to say any complaint to official site in any way. 

Tuesday, 23 September 2014

Calculating execution time and memory usages in your php script

Here is the script snippet, by using this you can get the execution time of that script and memory usages:
Beginning of the script:

//place this before any script you want to calculate time
$time_start = microtime(true);


End of the script:

//Put it at the end of php script
$time_end = microtime(true);
$execution_time = round(($time_end - $time_start),5);
echo '<br><b>Total Execution Time:</b> '.$execution_time.' Sec';
echo '<br><b>Total Memory Usages:</b> '.round(memory_get_usage(true)/1024,2)." Kb";