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 ——————
“;
?>