Tuesday 31 December 2013

update product quantity on check out page magento


you can do it by editing item.phtml (template/checkout/onepage/review/item.phtml) and these lines after line no #47

    <td class="a-center"><?php echo $_item->getQty() ?></td> 
        <td class="a-center">
            <input name="cart[<?php echo $_item->getId() ?>][qty]" value="<?php echo $this->getQty() ?>" size="4" name="update_cart_action" id="cup_<?php echo $_item->getId() ?>"  class="input-text qty" maxlength="12" />
        </td>
       <td> <button type="submit" name="update_cart_action" value="update_qty" title="<?php echo $this->__('shopping-cart-table'); ?>" id="up_<?php echo $_item->getId() ?>" class="button btn-update"><span><span><?php echo $this->__('Update'); ?></span></span></button><td>

and put Jquery code at the end

    <script type="text/javascript">
    jQuery(document).ready(function(){
        jQuery(".btn-update").click(function(){

            var id = "#c"+this.id;
            var quan = jQuery(id).val();
            var lastChar = id.substr(id.length - 1);

            jQuery.ajax({
                url: "<?php echo Mage::getBaseUrl(); ?>checkout/cart/updatePosts/",
                data: "cart["+lastChar+"][qty]="+quan,
                async: false,
                    success: function(html){

                        location.reload();

                    }
            })
        })
    })
    </script>now override cartcontroller.php and place all the functions of the original cartcontroller.php and rename function updatePostAction by function updatePostsAction.
and change the redirect path to $this->_redirect('checkout/onepage');

Put magento on maintenance mode and it open only on your ip








Today I am going to explain you how to put magento on maintenance mode. That maintenance mode will show to all other user user beside you. So can can work on a live environment if there is any issue.
Some time we all face a problem that something is not working on live environment while it is working on staging. So we have to test it on live environment but it is more difficult to put echo/ die on live site.
you can you do your work by using these steps so only you are able to open site while other see site is under maintenance mode.
Step 1 : put a file on your root with the name “maintenance.flag”
Step 2 : open you index file and find the code
if (file_exists($maintenanceFile) ) {
include_once dirname(__FILE__) . ‘/errors/503.php’;
exit;
}
Now update the code with that code
$ip = $_SERVER['REMOTE_ADDR']; // you can check your ip by http://who.is/
if (file_exists($maintenanceFile) && $ip != “your ip address” ) {
include_once dirname(__FILE__) . ‘/errors/503.php’;
exit;
}

unzip folder and files using php code

<!--?php
$zip = new ZipArchive;
if ($zip->open('test.zip') === TRUE) {
// using $_SERVER['DOCUMENT_ROOT'] if you don't know the where you are
    $zip->extractTo('/my/destination/dir/');
    $zip->close();
    echo 'ok';
} else {
    echo 'failed';
}
?>

set permission for magento (magento-cleaning)

If you are facing issue of permissions or internal server error then try to set permission to magento folder that might help you.
set 777 for media , var and app/etc folder
and for rest of file and folders create a file with name “magento-cleaning.php” and paste the blow code in that file and put this on root folder and hit this in url.
example: http://www.yourdomain.com/magento-cleaning.php

<?php
## Function to set file permissions to 0644 and folder permissions to 0755
function AllDirChmod( $dir = “./”, $dirModes = 0755, $fileModes = 0644 ){
   $d = new RecursiveDirectoryIterator( $dir );
   foreach( new RecursiveIteratorIterator( $d, 1 ) as $path ){
      if( $path->isDir() ) chmod( $path, $dirModes );
      else if( is_file( $path ) ) chmod( $path, $fileModes );
  }
}
## Function to clean out the contents of specified directory
function cleandir($dir) {
    if ($handle = opendir($dir)) {
        while (false !== ($file = readdir($handle))) {
            if ($file != ‘.’ && $file != ‘..’ && is_file($dir.’/’.$file)) {
                if (unlink($dir.’/’.$file)) { }
                else { echo $dir . ‘/’ . $file . ‘ (file) NOT deleted!<br />’; }
            }
            else if ($file != ‘.’ && $file != ‘..’ && is_dir($dir.’/’.$file)) {
                cleandir($dir.’/’.$file);
                if (rmdir($dir.’/’.$file)) { }
                else { echo $dir . ‘/’ . $file . ‘ (directory) NOT deleted!<br />’; }
            }
        }
        closedir($handle);
    }
}
function isDirEmpty($dir){
     return (($files = @scandir($dir)) && count($files) <= 2);
}
echo “———————– CLEANUP START ————————-<br/>”;
$start = (float) array_sum(explode(‘ ‘,microtime()));
echo “
*************** SETTING PERMISSIONS ***************
“;
echo “Setting all folder permissions to 755<br/>”;
echo “Setting all file permissions to 644<br/>”;
AllDirChmod( “.” );
echo “Setting pear permissions to 550<br/>”;
chmod(“pear”, 550);
echo “<br/>****************** CLEARING CACHE ******************<br/>”;
if (file_exists(“var/cache”)) {
    echo “Clearing var/cache<br/>”;
    cleandir(“var/cache”);
}
if (file_exists(“var/session”)) {
    echo “Clearing var/session<br/>”;
    cleandir(“var/session”);
}
if (file_exists(“var/minifycache”)) {
    echo “Clearing var/minifycache<br/>”;
    cleandir(“var/minifycache”);
}
if (file_exists(“downloader/pearlib/cache”)) {
    echo “Clearing downloader/pearlib/cache
“;
    cleandir(“downloader/pearlib/cache”);
}
if (file_exists(“downloader/pearlib/download”)) {
    echo “Clearing downloader/pearlib/download
“;
    cleandir(“downloader/pearlib/download”);
}
if (file_exists(“downloader/pearlib/pear.ini”)) {
    echo “Removing downloader/pearlib/pear.ini
“;
    unlink (“downloader/pearlib/pear.ini”);
}
echo “<br/>************** CHECKING FOR EXTENSIONS ***********<br/>”;
If (!isDirEmpty(“app/code/local/”)) {
    echo “-= WARNING =- Overrides or extensions exist in the app/code/local folder<br/>”;
}
If (!isDirEmpty(“app/code/community/”)) {
    echo “-= WARNING =- Overrides or extensions exist in the app/code/community folder<br/>”;
}
$end = (float) array_sum(explode(‘ ‘,microtime()));
echo “
——————- CLEANUP COMPLETED in:”. sprintf(“%.4f”, ($end-$start)).” seconds ——————
“;
?>

Wednesday 24 April 2013

copy a file into another folder in asp .net

string targetFolder = Server.MapPath(“~/PDF”);
System.IO.FileInfo fi = new System.IO.FileInfo(Server.MapPath(“~/Bookmark.pdf”));
fi.CopyTo(System.IO.Path.Combine(targetFolder, fi.Name), true);

get product thumb images on view.phtml

<!–?<?php $_images = Mage::getModel(‘catalog/product’)->load($_product->getId())->getMediaGalleryImages(); ?>
<?php if($_images){?>
<?php $i=0; foreach($_images as $_image){ $i++; ?>
<a href=”#” onclick=”ig_lightbox_show(-1)”>

<img src=”<?php echo $this->helper(‘catalog/image’)->init($_product, ‘thumbnail’, $_image->getFile())->resize(108,90); ?>” alt=”<?php echo $this->htmlEscape($_image->getLabel());?>” title=”<?php $this->htmlEscape($_image->getLabel());?>” />
</a><?php } ?> <?php } ?>

how to check canvas is empty or not

<canvas id="canvas11″ height=”200px” width=”200px”>
<asp:Button runat=”server” ID=”btn1″ Text=”Save”  OnClientClick=”checkcanvas();” />
<script type=”text/javascript”>
function checkcanvas() {
var i = isCanvasTransparent();
//i =true    if canvas empty
//i =false       if canvas has image
}
function isCanvasTransparent() {
var canvas1 = document.getElementById(‘canvas11′);
// true if all pixels Alpha equals to zero
var ctx = canvas1.getContext(“2d”);
var result;
var imageData = ctx.getImageData(0, 0, canvas1.offsetWidth, canvas1.offsetHeight);
for (var i = 0; i < imageData.data.length; i += 4)
if (imageData.data[i + 3] !== 0) return false;
return true;
}
</script>

countdown timer in php,

$dateFormat = “d F Y — g:i a”;
$targetDate = $futureDate;//Change the 25 to however many minutes you want to countdown change date in strtotime
$actualDate = $date1;
$secondsDiff = $targetDate – $actualDate;
$remainingDay     = floor($secondsDiff/60/60/24);
$remainingHour    = floor(($secondsDiff-($remainingDay*60*60*24))/60/60);
$remainingMinutes = floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))/60);
$remainingSeconds = floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))-($remainingMinutes*60));
$actualDateDisplay = date($dateFormat,$actualDate);
$targetDateDisplay = date($dateFormat,$targetDate);
<script type=”text/javascript”>
var days = <?php echo $remainingDay; ?>
var hours = <?php echo $remainingHour; ?>
var minutes = <?php echo $remainingMinutes; ?>
var seconds = <?php echo $remainingSeconds; ?>
function setCountDown(statusfun)
{//alert(seconds);
var SD;
if(days >= 0 && minutes >= 0){
var dataReturn =  jQuery.ajax({
type: “GET”,
url: “<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB).’index.php/countdowncont/’; ?>”,
async: true,
success: function(data){
var data = data.split(“/”);
day =  data[0];
hours =  data[1];
minutes =  data[2];
seconds =  data[3];
}
});
seconds–;
if (seconds < 0){
minutes–;
seconds = 59
}
if (minutes < 0){
hours–;
minutes = 59
}
if (hours < 0){
days–;
hours = 23
}
document.getElementById(“remain”).style.display = “block”;
document.getElementById(“remain”).innerHTML = ” Your Product Reverse For “+minutes+” minutes, “+seconds+” seconds”;
SD=window.setTimeout( “setCountDown()”, 1000 );
}else{
document.getElementById(“remain”).innerHTML = “”;
seconds = “00″; window.clearTimeout(SD);
jQuery.ajax({
type: “GET”,
url: “<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB).’index.php/countdown/’; ?>”,
async: false,
success: function(html){
}
});
document.getElementById(“remain”).innerHTML = “”;
window.location = document.URL; // Add your redirect url
}
}
</script>
<?php
if($date1 < $futureDate &&  ($qtyCart > 0)){ ?>
<script type=”text/javascript”>
setCountDown();
</script>
<?php }else{ ?>
<style>
#remain{display:none;}
</style>
<?php }}?>
<div id=”remain”></div>

some mysql queries

1. Add column age and desg in emp_prof table.
Mysql> use profile;
Mysql>alter table emp_prof add column age int;
Mysql> alter table emp_prof add column desg char(10);

2. Update all records of emp_prof.(desg= actn,officer)
Mysql> use profile;
Mysql>update emp_prof set age=24,desg=’officer’ where emp_id=101;
Mysql>update emp_prof set age=21,desg=’actn’ where emp_id=102;
(follow above queries for other records)

3. Display all records from emp_prof where age is 24 and designation is actn.
Mysql> use profile;
Mysql>select * from emp_prof where age=24 and desg=’actn’;

4. Display all records from emp_prof where age is 24 or designation is actn.
Mysql> use profile;
Mysql>select * from emp_prof where age=24 or desg=’actn’;

5.Display emp_name and age where age is not below 25
Mysql> use profile;
Mysql>select emp_name from emp_prof where not age<25;

6.Display emp_name and age where age between 21 and 25
Mysql> use profile;
Mysql> select emp_name from emp_prof where age between 21 and 25;

7.Display name and age where age is not between 23 and 26.
Mysql> use profile;
Mysql>select emp_name from emp_prof where not age between 23 and 26;

8.Display emp_name and country where reperesenting country (‘india’,’australia’)
Mysql> use profile;
Mysql>select emp_name,country from emp_prof where country in (‘india’,’australia’);

9. Display emp_name from emp_prof where emp_name starting with alphabet s.
Mysql> use profile;
Mysql>select emp_name from emp_prof where emp_name like ‘s%’;

10. Display all records from table cust_prof where fname is ending with alphabet s.
Mysql> use profile;
Mysql>select fname from cust_prof where fname like ‘%s’;

11. Display all records from table cust_prof where fname contains alphabet z.
Mysql> use profile;
Mysql>select * from cust_prof where fname like ‘%z%’;

12. Display all records from table cust_prof where lname contains alphabet ‘is’.
Mysql> use profile;
Mysql>select * from cust_prof where lname like ‘%is%’;

13. Display all records from table cust_prof where uppercase ‘A’ is present in fname.
Mysql> use profile;
Mysql>select * from cust_prof where fname like binary ‘%A%’;

  1. Display fname and lname from cust_prof where lowercase ‘t’ is present in fname.
Mysql> use profile;
Mysql>select fname,lname from cust_prof where fname like binary ‘%t%’;

15. Display fname and lname from cust_prof table where 2nd character of fname is ‘a’.(like ‘_a%’)
Mysql> use profile;
Mysql>select fname,lname from cust_prof where fname like  ‘_a%’;

16. Display emp_names from emp_prof  where 2nd last character of the name is ‘e’. (like ‘%e_’)
Mysql> use profile;
Mysql>select emp_name from emp_prof where emp_name like ‘%e_’;


17. Display emp_name from emp_prof where emp_name has exact 5 charecters. ( like ‘_ _ _ _ _ ‘)
Mysql> use profile;
Mysql>select emp_name from emp_prof where emp_name  like ‘_ _ _ _ _’;

18. Display emp_name from emp_prof where name contains ‘s’ first and then ‘i’ somewhere thereafter.
Mysql> use profile;
Mysql>select emp_name from emp_prof where emp_name like ‘s%i%’;

19. Display emp_name from emp_prof where emp_name second character of name is ‘a’ and contains ‘p’ somewhere after thereafter.(like ‘_a%p%’)
Mysql> use profile;
Mysql>select emp_name from emp_prof where emp_name like ‘_a%p%’;

20. Display emp_names from emp_prof where emp_name second character of emp_name is ‘a’ and last character of name is ‘s’. (like ‘_a%s’)
Mysql> use profile;
Mysql>select emp_name from emp_prof where emp_name like ‘_a%s’;

recursive function for getting parent and child

function categoryChild($id) {
$s = “SELECT ID FROM PLD_CATEGORY WHERE PARENT_ID = $id”;
$r = mysql_query($s);
$children = array();
if(mysql_num_rows($r) > 0) {
# It has children, let’s get them.
while($row = mysql_fetch_array($r)) {
# Add the child to the list of children, and get its subchildren
$children[$row['ID']] = categoryChild($row['ID']);
}
}
return $children;
}

quick seo (A SEO guide )

In this guide  you can learn how increase traffic on your site…
Download