Tuesday, October 11, 2011

Magento: Find subcategories for a root category

We can use the below code to find all child categories for a particular category
in Magento
 
<?php
//get category model
    $category_model = Mage::getModel('catalog/category'); 
 //$categoryid for which we have to find the child categories
    $_category = $category_model->load($categoryid); 
 //array that contains all child categories id
        $all_child_categories = $category_model->getResource()->getAllChildren($_category);
?>

Magento:Add/Edit HTML of success/failure message

Edit success/failure messages html in magento
Go to file
\app\code\core\Mage\Core\Block\Messages.php
find
public function getGroupedHtml()
    {
......................
Edit HTML here
......................
     }

Magento admin images donot show or upload

This is a common error in magento.
Product images in admin donot show or upload.
Fix:
In file
js/mage/adminhtml/product.js

replace
this.images.toJSON();
with:
Object.toJSON(this.images);

Wednesday, October 5, 2011

Redirect domain from index.php


If you are not able to redirect url(domain) from htaccess 

there is a simple solution .

Put this code at top in your index.php



<?
Header( "HTTP/1.1 301 Moved Permanently" ); 
Header( "Location: http://www.url.com" );       
?>

Secure url for cart, checkout and contacts page


In magento admin put https://domainname/  in secure url
Make "Use Secure URLs in Frontend" as Yes
Then  for checkout in  
/ app /code/core/Mage/Checkout/etc/config.xml file search <secure_url>
Just below Put
           <checkout_cart>/checkout/cart</checkout_cart>
            <checkout_onepage>/checkout/onepage</checkout_onepage>
            <checkout_multishipping>/checkout/multishipping</checkout_multishipping>


And  for contacts in  
/httpdocs/app/code/core/Mage/Contacts/etc/config.xml file
search <frontend>
Just below Put
 <frontend>
               <secure_url>
                       <contacts>/contacts</contacts>
               </secure_url>

</frontend> 
 
Further if you need more help visit the below url
More Help 

Saturday, October 1, 2011

Redirect non www to www url

It is very important from SEO point of view for a site to open from single url.
If you want that your site should only open with www preceding the url you should
just copy and paste the code below in your .htaccess file and you are done.For
example if a site opens with 'abc.com'  and  also with 'www.abc.com'  and you want
that it should always open with 'www.abc.com' and if one tries to open with
'abc.com' it should redirect it to 'www.abc.com'.

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

Thursday, September 8, 2011

Regular expression tutorial

Complete tutorial for custom regular expression formation
http://www.zytrax.com/tech/web/regex.htm