Friday 29 July 2011

Improve the Speed of Your Magento Site

Caching is useful for files on a web server that very rarely change. Images, pdf files and other content can be cached, reducing the network traffic between the server, the client, and the HTTP proxies in between them.

Change in your .htaccess file and it will improve your site speed.

Note: first backup your htaccess file.

1.)
############################################
## enable apache served files compression
## http://developer.yahoo.com/performance/rules.html#gzip
    # Insert filter on all content
    SetOutputFilter DEFLATE
    # Insert filter on selected content types only
    #AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
    # 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 sure proxies don't deliver the wrong content
    Header append Vary User-Agent env=!dont-vary
2.)
############################################
## Add default Expires header
## http://developer.yahoo.com/performance/rules.html#expires
       ExpiresActive on
       ExpiresDefault "access plus 1 year"
    #ExpiresDefault "access plus 1 year"
3.)
Header unset Pragma
FileETag None
Header unset ETag
# cache images/pdf docs for 10 days

Header set Cache-Control "max-age=864000, public, must-revalidate"
Header unset Last-Modified

# cache html/htm/xml/txt diles for 2 days
Header set Cache-Control "max-age=7200, must-revalidate"  
4.)

Enable all catch from your site backend form System->Catch manegement

Tuesday 26 July 2011

Add Extra Fee Shopping Cart Price Rules Magento

Under the Promotions tab in your admin panel there is a shopping cart price rule int this you can't add minus value to for rule. But now it is possible to add minus value and this value was added as extra fee to cart and checkout.

Note: we are going to change Magento Core files. Please make a backup of your files before continuing.

1). Go to app/code/core/Mage/Rule/Model/Rule.php

Find this:

            if ((int)$this->getDiscountAmount() < 0) {
                        Mage::throwException(Mage::helper('rule')->__('Invalid discount amount.'));
           }

Just add some bars // to comment the code: it look like this

            //if ((int)$this->getDiscountAmount() < 0) {
                        //Mage::throwException(Mage::helper('rule')->__('Invalid discount amount.'));
            //}

2). Now go to: app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Actions.php

find this

            'class' => 'validate-not-negative-number',

and coomment it

            //'class' => 'validate-not-negative-number',

3). Translate the discount word. Go to app/locale/es_ES (I'm using the Spainish translation so maybe yours would be en_US) Find a file called Mage_Sales.csv. Inside look for the word discount you will find something like:

            "Discount (%s)","Discount (%s)"

You can change the value in order to show your own text. For example:

            "Discount (%s)","Extra Fee (%s)"

4). If you want to apply this rule to whole cart than do this goto app\code\core\Mage\SalesRule\Model\validator.php find this below code it is near to line 280 to 300.

case 'cart_fixed':
            $cartRules = $address->getCartFixedRules();
             if (!isset($cartRules[$rule->getId()]) > 0) {
                        $cartRules[$rule->getId()] = $rule->getDiscountAmount();
             }
             if ($cartRules[$rule->getId()]) {

replace by

case 'cart_fixed':
            $cartRules = $address->getCartFixedRules();
            if (!isset($cartRules[$rule->getId()])) {
                        $cartRules[$rule->getId()] = $rule->getDiscountAmount();
            }
            if ($cartRules[$rule->getId()]) {

Monday 25 July 2011

Add WYSIWYG editor to admin custom field

To enable the editor for a certain editable textfield, just use 'wysiwyg' => true, instead of 'wysiwyg' => false. and add 'config' => Mage::getSingleton('cms/wysiwyg_config')->getConfig(). i.e.:

$fieldset->addField('description', 'editor', array(
'name' => 'description',
'label' => Mage::helper('sevents')->__('Description'),
'title' => Mage::helper('sevents')->__('Description'),
'style' => 'height:12em;width:500px;',
'wysiwyg' => false,
'required' => true,
));

After Change

$fieldset->addField('description', 'editor', array(
'name' => 'description',
'label' => Mage::helper('sevents')->__('Description'),
'title' => Mage::helper('sevents')->__('Description'),
'style' => 'height:12em;width:500px;',
'wysiwyg' => true,
'required' => true,
'config' => Mage::getSingleton('cms/wysiwyg_config')->getConfig(),
));

also add this to your controller initAction() before return.

if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {
 $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
}

That's all done.

Thursday 21 July 2011

Magento Category List

To display all root category list add this code to your file where you want display category.

$category = Mage::getModel('catalog/category')->load(2);
$subcategory = $category->getAllChildren(true);
array_shift($subcategory);
if($subcategory!=null)
{
 foreach ($subcategory as $sub)
    {
        $sub1 = Mage::getModel('catalog/category')->load( $sub);
        echo $sub1->getUrl();
        echo $sub1->getName();
        echo $sub1->getImageUrl();
    }
}