Posts

Showing posts from 2015

Happy New Year 2016

Image
Wishing you a year that is filled with all the fragrance of roses, illuminated with all the lights of the world and be blessed with all the smiles on the planet. Hope this year will be the year when all your dreams come true. Happy New Year 2016 .

Script to delete all subdirectories and contents with php

<?php //If you want to remove the complete directories, sub directories and files inside it, you can use the following function.  function delete_directories_recursively($dirname) {     // recursive function to delete     // all subdirectories and contents:     if(is_dir($dirname))$dir_handle=opendir($dirname);     while($file=readdir($dir_handle)){         if($file!="." && $file!="..") {             if(!is_dir($dirname."/".$file)){                 unlink ($dirname."/".$file);             } else {                 delete_directories_recursively($dirname."/".$file);          ...

Recursively walk in a directory and delete all matched files with php script

<?php //Recursively walk in a directory and delete all matched files with php  function delete_recursively_($path){    static $deleted = 0,    $dsize = 0;    $dirs = glob($path."*");    $match = '*.encrypted';    $files = glob($path.$match);    foreach($files as $file){       if(is_file($file)){          $deleted_size=0;          $deleted_size += filesize($file);          unlink($file);          $deleted++;       }    }    foreach($dirs as $dir){       if(is_dir($dir)){          $dir = basename($dir) . "/";          delete_recursively_($path.$dir,$match);    ...

Magento - Call Static Block in External file

<?php     require_once('app/Mage.php');     umask(0);     Mage::app();     $block = Mage::getModel('cms/block')->setStoreId(Mage::app()->getStore()->getId())->load('top_slider');     echo $block->getContent(); ?>

Magento - Remove other shipping methods if free shipping is Available

The file you need to adjust is:   app/design/frontend/default/YOURTEMPLATE/template/checkout/onepage/shipping_method/available.phtml Place the following code right before the tag that displays the different options.   <?php if ( array_key_exists('freeshipping', $_shippingRateGroups )) { unset($_shippingRateGroups["flatrate"]); unset($_shippingRateGroups["tablerate"]); } ?>

Add CSS Property in iFrame

To add the css property in iframe var frameListener; jQuery('iframe').ready(function () {     frameListener = setInterval("frameLoaded()", 50); }); function frameLoaded() {     var frame = jQuery('iframe').get(0);     if (frame != null) {         var frmHead = jQuery(frame).contents().find('head');         if (frmHead != null) {             clearInterval(frameListener); // stop the listener             //frmHead.append($('style, link[rel=stylesheet]').clone()); // clone existing css link             //frmHead.append(jQuery("<link/>", { rel: "stylesheet", href: "/styles/styleasa.css", type: "text/css" })); // or create css link yourself          ...

Magento Image Resize

$imageName = substr(strrchr($slide->getFilename(),"/"),1); $imageResized = Mage::getBaseDir('media').DS."custom".DS."imagegallery".DS."resize/".$imageName; $dirImg = Mage::getBaseDir('media').DS.$slide->getFilename(); if (!file_exists($imageResized)&&file_exists($dirImg)) { $imageObj = new Varien_Image($dirImg); $imageObj->constrainOnly(TRUE); $imageObj->keepAspectRatio(TRUE); $imageObj->keepFrame(FALSE); $imageObj->resize(200, 200); $imageObj->save($imageResized); } Note: Mine image path was like this custom/imagegallery/File-1420814603.jpg it will create a folder name custom/imagegallery/resize and will add the resize images on it

Magento: Get category layer filter attributes Programatically

 Get Category layer filter attribute $layer = Mage::getModel("catalog/layer"); // 32 cat id     $category = Mage::getModel("catalog/category")->load(32);     $layer->setCurrentCategory($category);     $attributes = $layer->getFilterableAttributes();     foreach ($attributes as $attribute) {         if ($attribute->getAttributeCode() == 'price') {             $filterBlockName = 'catalog/layer_filter_price';         } elseif ($attribute->getBackendType() == 'decimal') {             $filterBlockName = 'catalog/layer_filter_decimal';         } else {             $filterBlockName = 'catalog/layer_filter_attribute';     ...

Add Custom Fields in Magento Admin Panel

Image
 Source code system.xml file content (inside etc/ folder of your extension): <?xml version="1.0"?> <config>     <tabs>         <myconf translate="label">             <label>My Configuration</label>             <sort_order>150</sort_order>         </myconf>     </tabs>     <sections>         <tab1 translate="label" module="adminhtml">             <label>Tab #1</label>             <tab>myconf</tab>             <sort_order>10</sort_order>   ...

Add a Dropdown Field In Admin Section

Image
Create the configuration field Without much effort, you can create your own fields. All you need is:     >>your own module     >>a system.xml file inside this module I assume that you are familiar with creating your own module and new (text) fields in the system.xml. It will look like this when it’s finished: In Your Custom module system.xml file Add this line     <shipping_costs translate="label">         <label>Zipcode Range,Weight with Price</label>         <frontend_model>dao_customshippingmethod_block_linkedAttributes</frontend_model>         <backend_model>adminhtml/system_config_backend_serialized_array</backend_model>         <sort_order>22</sort_order>         <show_in_default>1...

Magento Language Translation for Custom Module

This article shows how you can create and use custom language translation csv file for your custom module. Suppose, I have created a new module and I want language translation file particularly for my newly made module. Here is how we do it:- In this example,     Namespace: Rahul     Module Name: News 1) In config.xml file of your module, you have to write the following code specifying the language translation csv file. Note that the same code is written inside the frontend and adminhtml node. Frontend is for frontend translation and adminhtml is for backend translation. In the example below, same file name (Rahul_News.csv) is specified for both. You may use different file as well. <?xml version="1.0"?>     <config>      .      .      .       <frontend>       .       .    ...

Google map comes partially, grey area comes instead of images from google server

Sometimes google map comes partially with other area getting grayed out. This style solved my problem #map_canvas img { max-width: none !important; } #map_canvas id of the map It forces the browser to allow the map to be as wide as it needs to be.

ultimate module creater configuration

Auto hide footer on scroll using jquery

##--First include jQuery 1.10 version file--## ##--Place these property in CSS File--## footer {     position: fixed;     bottom:0px;     height: 40px;     width: 100%;     margin: 0 auto;     text-align: center;     border-top:2px solid #6ce6d5;     background: white;     z-index: 100; } #underfooter {     position: fixed;     bottom: -44px;     background: blue;     width: 100%;     height: 40px;     z-index: 90; } ##----------------------------------## ##------------Content---------------## <footer> Your Content </footer> <div id="underfooter"></div> ##----------------------------------## ##---------Place the script--------## <script> $(function(){     $('footer').hide();     if($(document).height() ...

How to speed up your magento

Image
One of the drawbacks of Magento is currently its speed if default configuration is used. There are certain ways of making it run faster. The best one is to enable GZip compression by changing .htaccess file a little. You just need to uncomment part of the code. In my case, the speed increase was exactly 235%. Let’s start speeding up Magento! Find the following lines in your Magento .htaccess file and replace them with the following code. ############################################ ## enable apache served files compression ## http://developer.yahoo.com/performance/rules.html#gzip # Insert filter SetOutputFilter DEFLATE # Netscape 4.x has some problems… BrowserMatch ^Mozilla/4 gzip-only-text/html # Netscape 4.06-4.08 have some more problems BrowserMatch ^Mozilla/4\.0[678] no-gzip # MSIE masquerades as Netscape, but it is fine BrowserMatch \bMSIE !no-gzip !gzip-only-text/html # Don’t compress images SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary # Make ...

Read and Write XML Files In Magento

You can use  Varien_Simplexml_Element class  to  read and write xml nodes . In magento the location of class file is lib/Varien/Simplexml/Element.php Below is a sample of an XML file which I will read through Magento code. And after that i will also add an xml node into it. <? xml version = "1.0" ?> <config> <modules> <MyNamespace_MyModule> <version> 0.1.0 </version> </MyNamespace_MyModule> </config> </modules> Here is the Magento/PHP code to read the XML data. I have kept the XML file in the root directory of Magento installation. The XML file is named  test.xml . At first, the XML file is loaded and then it’s node are read with getNode function. Then, I have printed the result. $xmlPath = Mage :: getBaseDir (). DS . 'test.xml' ; $xmlObj = new Varien_Simplexml_Config ( $xmlPath ); $xmlData = $xmlObj -> getNode (); echo "<pre>" ...

How to get product rating and review in magento

/**Getting reviews collection object**/ $productId = $product->getId(); $reviews = Mage::getModel('review/review') ->getResourceCollection() ->addStoreFilter(Mage::app()->getStore()->getId()) ->addEntityFilter('product', $productId) ->addStatusFilter(Mage_Review_Model_Review::STATUS_APPROVED) ->setDateOrder() ->addRateVotes(); /**Getting average of ratings/reviews**/ $avg = 0; $ratings = array(); if (count($reviews) > 0) { foreach ($reviews->getItems() as $review) { foreach( $review->getRatingVotes() as $vote ) { $ratings[] = $vote->getPercent(); } } $avg = array_sum($ratings)/count($ratings); }

To find the URL path in Array

$currentUrl = Mage::helper('core/url')->getCurrentUrl(); $url = Mage::getSingleton('core/url')->parseUrl($currentUrl); $path = $url->getPath(); $blogPaths = array('/checkout/onepage/','/checkout/cart/','/checkout/onepage/index/'); if(in_array($path,$blogPaths)) { }

Move layered navigation block between product list toolbar and product list

Add this code to your layout XML : <?xml version="1.0"?> <layout version="0.1.0"> <catalog_category_layered> <reference name="left"> <action method="unsetChild"><alias>catalog.leftnav</alias></action> </reference> <reference name="product_list"> <action method="insert"><blockName>catalog.leftnav</blockName></action> </reference> </catalog_category_layered> </layout>      In list.phtml File Call this <?php echo $this->getChildHtml('catalog.leftnav'); ?>

Count Up Timer jquery

<div id="bestPrice"></div> <script src="js/countUp.js"></script> <script>         jQuery( document ).ready(function () {             var bestAnim = new countUp("bestPrice", 0, "<?php echo $price_in_format;?>", 2, 1.5);             bestAnim.start();                         });      </script>