Thursday, 29 June 2017

Magento2


Command Magento2 Shell

sudo chmod -R 777 pub/ var/ && bin/magento cache:clean && bin/magento setup:upgrade && bin/magento setup:di:compile


Cache namespace issue

sudo rm -rf var/di/* var/generation/* var/cache/* var/page_cache/* var/view_preprocessed/* var/composer_home/cache/* && sudo chmod 777 var -R && sudo chmod 777 pub -R && sudo php bin/magento setup:static-content:deploy && sudo chmod 777 var -R && sudo chmod 777 pub -R

Correct permission for folders and files

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

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();

Tuesday, 2 December 2014

linux

You have to install the open-terminal package :
sudo apt-get install nautilus-open-terminal
Then:
nautilus -q

in order to reset Nautilus


find . -type f -exec chmod 644 {} \;



Linux command:
-> To check server space
df -h 

-> To check folder space
du -sh foldername/

--> To check version and flavor of linux on server
cat /proc/version

--> Creating a tar.gz file
tar -czvf truconnect_qa_20170601.tar.gz truconnect_qa_20170601.sql

--> To view appended content in real time
tail -f filename

--> to find last 1 day changed files
find /directory_path -mtime -1 -ls