Wednesday 16 December 2015

How to use helpers in magento ?

In magento helpers is very useful functionality.Basically we can call helper functions anywhere in the site .

Each module has its own helper function

like in magento you use a below cart helper function to get cart url 

Mage::helper('checkout/cart')->getCartUrl()

the above helper function is created at below location

app/code/core/Mage/Checkout/Helper/Cart.php 

Lets create one new helper function in the end of Cart.php 

let say we need a function in which we need to get all ordered product items data 

 
For this i have create a new function as below

public function getordered_products_data($order_id){
        $cart =  Mage::getModel('sales/order')->load($order_id);
        print_r($cart->getData());die;
        foreach ($cart->getAllItems() as $item) {
        $loadproduct =     Mage::getModel('catalog/product')->load($item->getProduct()->getId());
        print_r($loadproduct->getData());
        }

}


and now we can use this function anywhere in the site as below

Mage::helper('checkout/cart')->getordered_products_data($your_order_id); // pass your order id here

and with this you can see all products data in order anywhere in the site by using above function.

thanks and hope it will help the magento comunity 


Thursday 3 December 2015

how to redirect http to https or vice versa through htaccess

To redirect the site from http to htttps just use the below code in the top of htaccess file


for htttps to http


RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]


for http to https 

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]