Wednesday 30 December 2015

order email confirmation not received in Magento 1.9.1

Just make a small change in order.php

/app/code/core/Mage/Sales/Model/Order.php

First, create one directory structure on the path below, then copy and paste the file to the path below.

/app/code/local/Mage/Sales/Model/Order.php

Now, change from

$mailer->setQueue($emailQueue)->send();

to

$mailer->send();

Tuesday 29 December 2015

magento 2 - how to enable developer mode

Open run cmd and go to magento root directory and run below command :-

php bin/magento deploy:mode:set developer

How to include css,js file on head in magento 2

First you paste your css file here :-  pub/static/frontend/{Package}/{theme}/en_US/css/ 
  your js file here :-  pub/static/frontend/{Package}/{theme}/en_US/js/

And open below directory file :-

app/code/Magento/Theme/view/frontend/layout/default_head_blocks.xml

And add your css or js file name in <head> tag :- 
<css src="css/custom.css"/>
<script src="js/custom.js"/>

Magento 2 - How to call a custom phtml file in another phtml file, xml layout, static block and cms page

custom file path

app/code/Magento/Theme/view/frontend/templates/html/test.phtml

calling in xml layout file

<block class="Magento\Framework\View\Element\Template" name="test_file" template="Magento_Theme::html/test.phtml"/>

calling in blocks and cms pages
 
{{block class="Magento\Framework\View\Element\Template" name="test_file" template="Magento_Theme::html/test.phtml"}}

calling in any phtml file
 
<?php include ($block->getTemplateFile('Magento_Theme::html/test.phtml')) ?>

or as before
 
<?php echo $this->getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate("Magento_Theme::html/test.phtml")->toHtml();?>

Thursday 17 December 2015

Magento 2 Installation: css/js/images not loading.(Solution).


First open the cmd command and goto magento installed directory
and run following command :-
php bin/magento setup:static-content:deploy

Note :- Please exceed memory_limit (If you an error of memory limit during running command).

How to install magento 2

Installing  Magento2 on XAMPP could be pretty painful for the developers, as Magento2 requires a lot of server configurations.
Before you start installing you need the following:
1. XAMPP server installed in your computer
2. Magento 2 can be downloaded from this link Magento2.
Apache Version :-  2.2 or 2.4
PHP            :-  5.5.x or 5.6.x
MySQL          :-  5.6.x

Installation :-
1.) Enter your Magento 2 url in browser and hit Enter.
 
2.) Click on “Agree and Setup Magento”.









3.) Now Magento 2 will check your environment for readiness for the setup. Click on “Start readiness check”.
 











4.) Now enter Empty database that you created previously, where you want to install Magento2.










5.) Click Next, now you will be asked for web configurations like store url, admin url, Apache rewrites, https options.
6.) Click Next, now you can select Timezone, Currency and language in “Customize Your Store” section.










7.)Click Next, Enter Admin username, email and password to setup Admin credentials.










8.)Click Next, Voila J, Now Magento 2 is ready to be installed on localhost. Click on “Install Now”. Don’t close your browser until setup is done.












9.)After the installer has completed the setup, it will show Success page.













10.) Now You can open Magento Admin panel and front page.

How to get instagram user id and access token

Get user id by user name through below Steps :-
Login with instagram account

https://www.instagram.com/developer/

create client_id and secret_key and  request_url

After that you should pass client_id and request_url in this url

https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=token

we get access_token like this

http://your-redirect-uri#access_token=ACCESS-TOKEN

now you should pass token for find user information like this

https://api.instagram.com/v1/users/self?access_token=access_token

{"data": {"id": "XXXXX", "username": "XXXX", "profile_picture": "XXXX", "full_name": "Naresh Chaudhary", "bio": "", "website": "", "is_business": false, "counts": {"media": 4, "follows": 6, "followed_by": 52}}, "meta": {"code": 200}}  

Monday 23 November 2015

smileys for chat script using php

<?php function parseString($message ) {
    $my_smilies = array(
        ':)' => '<img src="images/smiley.gif" alt="" />',
    ':(' => '<img src="images/sad.gif" alt="" />',
   
    );

    return str_replace( array_keys($my_smilies), array_values($my_smilies), $message);
}

echo parseString($message);
?>

Thursday 8 October 2015

How to make an autocomplete address field with google map api

<script src="http://maps.googleapis.com/maps/api/js?sensor=false&amp;libraries=places" type="text/javascript"></script>
        <script type="text/javascript">
               function initialize() {
                       var input = document.getElementById('searchTextField');
                       var autocomplete = new google.maps.places.Autocomplete(input);
               }
               google.maps.event.addDomListener(window, 'load', initialize);
       </script>
 <body>
               <div>
                       <input id="searchTextField" type="text" size="50" placeholder="Enter a location" autocomplete="on">
               </div>
           </body>

Wednesday 30 September 2015

get distance between two address through google api in php

<?php
function get_distance($address1,$address2)
{
$address1_encode = urlencode($address1);
$address2_encode = urlencode($address2);
$addresses_string = "?origins=".$address1_encode."&destinations=".$address2_encode."&key=AIzaSyBf6kfop46PNbRUAG-VwHVrGlyvNunpw9o";
    $url = "https://maps.googleapis.com/maps/api/distancematrix/json".$addresses_string;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    $response = curl_exec($ch);
    curl_close($ch);
   
  return $response;
    //$status = $response_a->status;
}
if(isset($_POST['get_dis'])){
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$results = get_distance($address1,$address2);
$response_a = json_decode($results);

echo "status :- ";
echo $result_status = $response_a->status;
echo "<br/>";
echo "distance :- ";
echo  $distance = $response_a->rows[0]->elements[0]->distance->value;
echo " M";
}
 ?>
 <form action="" method="post">
 <input type="text" name="address1">&nbsp;&nbsp;&nbsp;
 <input type="text" name="address2">&nbsp;&nbsp;&nbsp;
 <input type="submit" name="get_dis" value="Get Distance">

 </form>

Monday 28 September 2015

javascript add class step by step in loop.

<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script>
$(function () {
  var $anchors = $('.anchor');

  (function _loop(idx) {
    $anchors.removeClass('highlight').eq(idx).addClass('highlight');
    setTimeout(function () {
      _loop((idx + 1) % $anchors.length);
    }, 2000);
  }(0));
});
</script>
<style>
.highlight{
color:#FF0000;
font-size:24px;
}
</style>
<a class="anchor">A</a>
<a class="anchor">B</a>
<a class="anchor">C</a>
<a class="anchor">D</a>
<a class="anchor">E</a>
<a class="anchor">F</a>
<a class="anchor">G</a>

Wednesday 5 August 2015

how to import sql file in database in php

function  import_db($mysql_username,$mysql_password,$mysql_host,$mysql_database)
{
    // Name of the file
    $filename = $file_path.'/sql/database.sql';
   

    // Connect to MySQL server
    $db_conn = mysqli_connect($mysql_host, $mysql_username, $mysql_password,$mysql_database) or die('Error connecting to MySQL server: ' . mysql_error());
    // Select database
    //mysql_select_db($mysql_database) or die('Error selecting MySQL database: ' . mysql_error());

    // Temporary variable, used to store current query
    $templine = '';
    // Read in entire file
    $lines = file($filename);
    // Loop through each line
    foreach ($lines as $line)
    {
    // Skip it if it's a comment
    if (substr($line, 0, 2) == '--' || $line == '')
        continue;

    // Add this line to the current segment
    $templine .= $line;
    // If it has a semicolon at the end, it's the end of the query
    if (substr(trim($line), -1, 1) == ';')
    {
        // Perform the query
        mysqli_query($db_conn,$templine) or print('Error performing query \'<strong>' . $templine . '\': ' . mysql_error() . '<br /><br />');
        // Reset temp variable to empty
        $templine = '';
    }
    }
    //echo "Tables imported successfully";

}

Thursday 18 June 2015

html value set in php variable

<?php
$my_var = <<<EOD
<div onclick="pa('1','sdsa','12');">SOME HTML</div>
EOD;

echo $my_var;
?>

Saturday 13 June 2015

redirect www to non www htaccess

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

Friday 12 June 2015

date difference in php

$d1 = new DateTime("2009-07-01");
$d2 = new DateTime("2010-05-31");
var_dump($d1->diff($d2)->m + ($d1->diff($d2)->y*12));

Tuesday 9 June 2015

jquery get month and year value on change in datepicker

<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery UI Datepicker - Display inline</title>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
  <script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script>
  $(function() {
  $( "#datepicker" ).datepicker({
  onChangeMonthYear :function(da,mon,ob){alert("Year-"+ da +" Month- " + mon);}
});
});
  </script>
</head>
<style>
.ui-datepicker table{display:none;}
</style>
<body>

Date: <div id="datepicker"></div>


</body>
</html>

Saturday 9 May 2015

Send email with attachment file in php

<form action="" enctype="multipart/form-data" method="post">
<input type="file" name="attc">
<input type="submit" name="sub" value="send" />
</form>
<?php
function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) {
    $file = $path.$filename;
    $file_size = filesize($file);
    $handle = fopen($file, "r");
    $content = fread($handle, $file_size);
    fclose($handle);
    $content = chunk_split(base64_encode($content));
    $uid = md5(uniqid(time()));
    $name = basename($file);
    $header = "From: ".$from_name." <".$from_mail.">\r\n";
    $header .= "Reply-To: ".$replyto."\r\n";
    $header .= "MIME-Version: 1.0\r\n";
    $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
    $header .= "This is a multi-part message in MIME format.\r\n";
    $header .= "--".$uid."\r\n";
    $header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
    $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
    $header .= $message."\r\n\r\n";
    $header .= "--".$uid."\r\n";
    $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n";
    $header .= "Content-Transfer-Encoding: base64\r\n";
    $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
    $header .= $content."\r\n\r\n";
    $header .= "--".$uid."--";
    if (mail($mailto, $subject, "", $header)) {
        echo "mail send ... Successfully";
    } else {
        echo "ERROR!";
    }
}
if(isset($_POST['sub']))
{

$filename = $_FILES['attc']['name'];
move_uploaded_file($_FILES['attc']['tmp_name'],"file_attached/".$filename);
$path = "file_attached/";
$mailto = "your-email@gmail.com";
$from_mail = "from@gmail.com";
$from_name = "from_name";
$replyto = "reply@gmail.com";
$subject = "new testing";
$message = "Please find attached file";
echo mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message);
}
?>

Wednesday 6 May 2015

All child checkbox checked on checked in jquery

<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script>
var nocon = jQuery.noConflict();
nocon(document).ready(function(){

  nocon(".chk").click(function(ev) {
 
    nocon(this).siblings('ul').find("input[type='checkbox']").prop('checked', this.checked);
        ev.stopImmediatePropagation();
  });
});
</script>

<ul><li><input type="checkbox" class="chk"><a href="">1</a>
   <ul>
   <li>
   <input type="checkbox"class="chk"><a href="">2_1</a>
                       <ul>
                       <li><input type="checkbox" class="chk"><a href="">3_1</a></li>
                       <li><input type="checkbox" class="chk"><a href="">3_2</a></li>
                       </ul>
                    
                      </li>
                    <li>
                      <input type="checkbox"class="chk"><a href="">2_2</a>
                       <ul>
                       <li><input type="checkbox" class="chk"><a href="">3_3</a></li>
                       <li><input type="checkbox" class="chk"><a href="">3_4</a></li>
                       </ul>
                    
                      </li>
                      </ul>
                      </li>
        <li><input type="checkbox" class="chk"><a href="">1</a>
   <ul>
   <li>
   <input type="checkbox"class="chk"><a href="">2_1</a>
                       <ul>
                       <li><input type="checkbox" class="chk"><a href="">3_1</a></li>
                       <li><input type="checkbox" class="chk"><a href="">3_2</a></li>
                       </ul>
                    
                      </li>
                    <li>
                      <input type="checkbox"class="chk"><a href="">2_2</a>
                       <ul>
                       <li><input type="checkbox" class="chk"><a href="">3_3</a></li>
                       <li><input type="checkbox" class="chk"><a href="">3_4</a></li>
                       </ul>
                    
                      </li>
                      </ul>
                      </li>            
                    
                      </ul>

Saturday 18 April 2015

random string genrate in php

<?php
function Password_genrator($length = 10) {
    $characters = '0123456789!@#$%^&*abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $charactersLength = strlen($characters);
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, $charactersLength - 1)];
    }
    return $randomString;
}

echo Password_genrator();

?>

Wednesday 11 March 2015

inactive user session expire in php

 <?php

$expireAfter = 5; //expire session after 5 mints.
if(isset($_SESSION['last_action'])){

    $secondsInactive = time() - $_SESSION['last_action'];
  
  
    $expireAfterSeconds = $expireAfter * 60;
  
  
    if($secondsInactive >= $expireAfterSeconds){
        unset($_SESSION['vendor']);
    }
  
}

$_SESSION['last_action'] = time();

?>

simple pop up through css

<style type="text/css">
.blankdiv{background-color:#000;
position:fixed;
z-index: 9001;
top:0px; height:100%;
left:0px;
width:100%; opacity: 0.65;
filter:alpha(opacity=65);}


#popupform{height: 100%;
    left: 0;
    padding: 15px;
    position: fixed;
    top: 0;
    width:97%;
    z-index: 10001;
    }
  
#popupform .applyform{position:relative; overflow:auto;
background-color:#fff;
width:670px;
height:500px;  margin:5% auto auto auto;
z-index: 9002; padding:10px; border:10px solid #7F3814; }


#pclose{
    background-position: left top;
    background-repeat: no-repeat;
    cursor: pointer;
    height: 25px;
    margin: 5% auto -6%;
    position: relative;
    right: -324px;
    top: 24px;
    width: 25px;
    z-index: 9999;}
</style>

  <a href="javascript:void(0)" id="apply" onclick="javascript:document.getElementById('popupform').style.display='block';return false;">Click Me</a>
 <div id="popupform" style="display:none">
  <div class="blankdiv"></div>
  <div id="pclose" onclick="javascript:document.getElementById('popupform').style.display='none';">close</div>
    <div class="applyform">
        <p id="contactArea">
        purushotam
        </p>
    </div>
 </div>

Friday 27 February 2015

how to remove no selected file in javascript

<div><input type='file' title="Choose a video please" id="aa" onchange="pressed()"><label id="fileLabel">Select New file</label></div>

<style>
input[type=file]{
    width:80px;
    color:transparent;
}

</style>


<script>
window.pressed = function(){
    var a = document.getElementById('aa');
    if(a.value == "")
    {
        fileLabel.innerHTML = "Select New file";
    }
    else
    {
        var theSplit = a.value.split('\\');
        fileLabel.innerHTML = theSplit[theSplit.length-1];
    }
};
</script>

Thursday 26 February 2015

get last 30 days data in php

select * from `tablename` where `yourdatefield` >= 
 DATE_SUB(CURDATE(), INTERVAL 30 DAY)

Monday 16 February 2015

set timezone and get timezone in php

 1.) Set timezone :-
<?php echo date_default_timezone_set("Asia/Kolkata"); ?>

 2.) Get timezone :-
<?php echo date_default_timezone_get(); ?>

export sql table to csv format in php

<?php 
//First create db connection.
$output = "";
$sql = mysql_query("select col1,col2,col3 from table_name where 1");
$columns_total = mysql_num_fields($sql);
for ($i = 0; $i < $columns_total; $i++) {
$heading = mysql_field_name($sql, $i);
$output .= '"'.$heading.'",';
}
$output .="\r\n";
while ($row = mysql_fetch_array($sql)) {
for ($i = 0; $i < $columns_total; $i++) {
$output .='"'.$row["$i"].'",';
}
$output .="\n";
}
$filename = "Vendor-data-export.csv";
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename='.$filename);

echo $output;
?>

Saturday 14 February 2015

Create custom home page layout in magento

1.)  First go to app/design/frontend/rwd/default/layout/page.xml and following  code after one_page colamn structure

<page_home translate="label">
        <label>All home Layout Pages</label>
        <reference name="root">
            <action method="setTemplate"><template>page/home.phtml</template></action>
            <!-- Mark root page block that template is applied -->
            <action method="setIsHandle"><applied>1</applied></action>
            <action method="setLayoutCode"><name>home</name></action>
        </reference>
    </page_home>

2.) second open app/code/core/Mage/Page/etc/config.xml file and set following code after one_page colamn

<home module="page" translate="label">
                    <label>Home page</label>
                    <template>page/home.phtml</template>
                    <layout_handle>page_home</layout_handle>
                    <is_default>1</is_default>
                </home>

3.) And last go to admin->cms->pages in content tab select your home page.

Tuesday 20 January 2015

get image height and width in php

<?php list($width, $height) = getimagesize('path_to_image');
echo $width."<br/>";
echo $height; 
?>
 
 
 
Powered by Crawlers group

how to count array value in jquery

<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script>
function chksame(cl) {
var newArray = new Array();

var classnm = $(cl).attr("class");
 
var array = $("input[class^= '" + classnm + "']"); //get value by class name

$.each(array, function(key, value) {
card_value = array.eq(key).val();
   newArray.push(card_value);//push value in array.
  
});

counts = {};
jQuery.each(newArray, function(key,value) {
  if (!counts.hasOwnProperty(value)) {
    counts[value] = 1; //set count value
  } else {
    counts[value]++;
  }
 
  if(counts[value]>1 && value!="") //check if value greater than then alert massege.
  {
  alert("This order already exist");
  $(cl).val("");
  }
});
return false;
}
</script>

Powered by Crawlers group

Thursday 8 January 2015

download file in php

function Download($path, $speed = null)
{
if (is_file($path) === true)
    {
set_time_limit(0);
while (ob_get_level() > 0)
        {
            ob_end_clean();
        }
$size = sprintf('%u', filesize($path));
        $speed = (is_null($speed) === true) ? $size : intval($speed) * 1024;
        header('Expires: 0');
        header('Pragma: public');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Content-Type: application/octet-stream');
        header('Content-Length: ' . $size);
        header('Content-Disposition: attachment; filename="' . basename($path) . '"');
        header('Content-Transfer-Encoding: binary');

        for ($i = 0; $i <= $size; $i = $i + $speed)
        {
            echo file_get_contents($path, false, null, $i, $speed);

            while (ob_get_level() > 0)
            {
                ob_end_clean();
            }

            flush();
            sleep(1);
        }

        exit();
    }

    return false;
}
echo Download($file_path,500);