Posts

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 ...

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>