Posts

Showing posts from 2012

Open color box on Page load

This code working with all frameworks.             Required Latest versions of :-                     1-colorbox.js                     2-jquery.min.js                     2- Download                 < script type = "text/javascript" > var j = jQuery.noConflict(); j( document ).ready( function (){ j.fn.colorbox({width : "685px;" ,overlayClose : false , escKey : false , inline : true , href : "#inline_content" }); j( "#cboxClose" ).remove(); }); < /script>

Safe name of a file by php

 function filename_safe($filename) {     $temp = $filename;      // Lower case     $temp = strtolower($temp);         // Replace spaces with a "_"     $temp = str_replace(" ", "_", $temp);         // Loop through string     $result = "";     for ($i=0; $i<strlen($temp); $i++) {     if (preg_match("([0-9]|[a-z]|_)", $temp[$i])) {     $result = $result . $temp[$i];     }     }     // Return filename     return $result;     }         function safe_filename ($filename) {     $search = array(     // Definition of German Umlauts START     "/ß/",     "/ä/","/Ä/",     "/ö/","/Ö/",     "/ü/","/Ãœ/",     // Definition of German Umlauts ENDE     "([^[:alnum:]_])" // Disallow: Not alphanumeric, dot or underscore     );     $replace = array(     "ss",     "ae","Ae",     "oe","Oe",    

Get related product on with same category,brand,gender

include('app/Mage.php'); Mage::app(); $product = Mage::getModel('catalog/product')->load(2122); $ids = $product->getCategoryIds(); //echo '<pre>'; //print_r($ids); $latest_cat_id = $ids[count($ids)-1]; $_category = Mage::getModel('catalog/category')->load($latest_cat_id); $_gender=Mage::getResourceModel('catalog/product')->getAttributeRawValue(2122, 'gender'); $_brand_name=Mage::getResourceModel('catalog/product')->getAttributeRawValue(2122, 'brand_name'); $catagory_model = Mage::getModel('catalog/category')->load($latest_cat_id);     $collection = Mage::getResourceModel('catalog/product_collection'); $collection->addCategoryFilter($catagory_model); $collection->addFieldToFilter('brand_name',$_brand_name ); $collection->addFieldToFilter('gender',$_gender );     $collection->addAttributeToFilter('status',1); $collection->ad

Randomize Collection In magento

Randomize Collection In magento <?php $_model = Mage :: getModel ( 'catalog/category' ); // Using the "catalog/navigation" Block Classes, we can invoke the getStoreCategories() method to get all Store Cats. $storeId = Mage :: app () -> getStore () -> getId (); $_categories = Mage :: getModel ( 'catalog/category' ) -> getCollection () -> addAttributeToSelect ( '*' ) -> addIsActiveFilter () -> addLevelFilter ( 2 ) -> setStoreId ( $storeId ); $_categories -> getSelect () -> order ( new Zend_Db_Expr( 'RAND()' )); $new = "" ; $new2 = "" ; // We'll loop through the returned Category Object foreach ( $_categories as $_category ) { //this gives random order of products }
 Programming Mistakes Improper Input Validation Ensure that your input is valid. If you're expecting a number, it shouldn't contain letters. Nor should the price of a new car be allowed to be a dollar. Incorrect input validation can lead to vulnerabilities when attackers can modify their inputs in unexpected ways. Many of today's most common vulnerabilities can be eliminated, or at least reduced, with strict input validation. Improper Encoding or Escaping of Output Insufficient output encoding is at the root of most injection-based attacks. An attacker can modify the commands that you intend to send to other components, possibly leading to a complete compromise of your application - not to mention exposing the other components to exploits that the attacker would not be able to launch directly. When your program generates outputs to other components in the form of structured messages such as queries or requests, be sure to separate control information a

Add template exceptions on the basis of parameter magento

copy  this file in magento local Mage before edit. /public_html/app/code/core/Mage/Core/Model/Design/package.php <?php /**  * Magento  *  * NOTICE OF LICENSE  *  * This source file is subject to the Open Software License (OSL 3.0)  * that is bundled with this package in the file LICENSE.txt.  * It is also available through the world-wide-web at this URL:  * http://opensource.org/licenses/osl-3.0.php  * If you did not receive a copy of the license and are unable to  * obtain it through the world-wide-web, please send an email  * to license@magentocommerce.com so we can send you a copy immediately.  *  * DISCLAIMER  *  * Do not edit or add to this file if you wish to upgrade Magento to newer  * versions in the future. If you wish to customize Magento for your  * needs please refer to http://www.magentocommerce.com for more information.  *  * @category    Mage  * @package     Mage_Core  * @copyright   Copyright (c) 2011 Magento Inc. (http://www.magentoc

Get best seller,newarrivals ,most viewed product collection

//Get most sold product collection <?php $visibility = array ( Mage_Catalog_Model_Product_Visibility :: VISIBILITY_BOTH , Mage_Catalog_Model_Product_Visibility :: VISIBILITY_IN_CATALOG ); $_productCollection2 = Mage :: getResourceModel ( 'reports/product_collection' ) -> addAttributeToSelect ( '*' ) -> addOrderedQty () -> addAttributeToFilter ( 'visibility' , $visibility ) -> setOrder ( 'ordered_qty' , 'desc' ); //Get most viewed product collection $_productCollection1 = Mage :: getResourceModel ( 'reports/product_collection' ) -> addAttributeToSelect ( '*' ) -> setStoreId ( $storeId ) -> addStoreFilter ( $storeId ) -> addViewsCount (); //->setPageSize($productCount); Mage :: getSingleton ( 'catalog/product_status' ) -> addVisibleFilterToCollection ( $_productCollection1 ); Mage :: getSingleton ( 'catalog/product_visib

Show top level categories in magento.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 <?php $obj = new Mage_Catalog_Block_Navigation(); $store_cats = $obj -> getStoreCategories (); $current_cat = $obj -> getCurrentCategory (); $current_cat = ( is_object ( $current_cat ) ? $current_cat -> getName () : '' ); foreach ( $store_cats as $cat ) { if ( $cat -> getName () == $current_cat ) { echo '<li><a href="' . $this -> getCategoryUrl ( $cat ) . '">' . $cat -> getName () . "</a> \n <ul> \n " ; foreach ( $obj -> getCurrentChildCategories () as $subcat ) { echo '<li><a href="' . $this -> getCategoryUrl ( $subcat ) . '">' . $subcat -> getName () . "</a></li> \n " ; } echo "</ul> \n </li> \n " ; } else { echo '<li><a href="' . $this -> getCategoryUrl ( $cat ) . '">' . $

How to configure Magento to work with a new domain

Select your Magento database from the  left menu, find the table called  core_config_data and click on it.  Click the Browse tab and edit the first two fields: web/unsecure/base_url web/secure/base_url by clicking the pen icon in front of each of them. Replace your old domain name with your new one and click the Go button to save the change. Clear the Magento cache. The Magento cache folder is located in your Magento installation directory > /var/cache. To clear the cache, simply delete the folder.  Many Magento issues can be fixed just by deleting the cache.

Improve Your YSlow Grade Using .htaccess

Put these lines in you .htaccess and see magic :)                                                                                      @Saurabh Mishra < FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)(\.gz)?$" > Header set Expires "Thu, 15 Apr 2012 20:00:00 GMT" < / FilesMatch > <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)(\.gz)?$"> Header unset ETag FileETag None </FilesMatch> <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)(\.gz)?$"> Header set Expires "Thu, 15 Apr 2012 20:00:00 GMT" Header unset ETag FileETag None </FilesMatch>

Get width height of image using Varien-image class in Magento

You can get width height of image using Varien_Image (lib/Varien/Image.php) class object. In this example, I assume that your image is present inside media directory of your magento installation. $imagePath = YOUR_IMAGE_PATH_LINK; // like http://example.com/media/myfolder/myimage.jpg // changing url link of image into directory link $dirImg = Mage::getBaseDir().str_replace("/",DS,strstr($imagePath,'/media')); // getting image width and height if (file_exists($dirImg)) { $imageObj = new Varien_Image($dirImg); $width = $imageObj->getOriginalWidth(); $height = $imageObj->getOriginalHeight(); echo $width." x ".$height; } else { echo "File doesn't exist."; } Resize Image <?php echo $this ->helper( 'catalog/image' )->init( $_product , 'image' ) ->constrainOnly(TRUE) ->keepAspectRatio(TRUE) ->keepFrame(FALSE) ->resize(600,null) ?> Fixed h