Magento More View Image Switcher On MouseOver Product Page

Step1. open file on location given below

Step2. Search the code in media.phtml file
<a href=”#” onclick=”popWin(‘<?php echo $this->getGalleryUrl($_image) ?>’, ‘gallery’, ‘width=300,height=300,left=50,top=50,location=no,status=yes,scrollbars=yes,resizable=yes’); return false;”>
<!–nested img tag stays the same–>

Step 3. Replace searched code with code below.
<a href=”<?php echo $this->helper(‘catalog/image’)->init($this->getProduct(), ‘image’, $_image->getFile()); ?>” title=”<?php echo $_product->getName();?>” onmouseover=”$(‘image’).src = this.href; return false;”>
<!–nested img tag stays the same–>


Magento Product and Category Related Functions

Magneto Product Collection

$collection = Mage::getModel(‘catalog/product’)->getCollection()->addAttributeToSelect(‘*’);

Get product of particular category

$products = Mage::getModel(‘catalog/category’)->load(category_id); //put your category id here
$productslist = $products->getProductCollection()->addAttributeToSelect(‘*’);

Product details from Product ID.

$model = Mage::getModel(‘catalog/product’) //getting product model
$_product = $model->load($productid); //getting product object for particular product id
echo $_product->getShortDescription(); //product’s short description
echo $_product->getDescription(); // product’s long description
echo $_product->getName(); //product name
echo $_product->getPrice(); //product’s regular Price
echo $_product->getSpecialPrice(); //product’s special Price
echo $_product->getProductUrl(); //product url
echo $_product->getImageUrl(); //product’s image url
echo $_product->getSmallImageUrl(); //product’s small image url
echo $_product->getThumbnailUrl(); //product’s thumbnail image url

product collection from the category and then refine it down from there.

$products = Mage::getModel(‘catalog/category’)->load(410)
->addAttributeToFilter(‘status’, 1)
->addAttributeToFilter(‘visibility’, 4)
->addAttributeToFilter(‘special_price’, array(‘neq’ => “”))
->addAttributeToFilter(‘discontinued’, array(‘neq’ => 1))
->setOrder(‘price’, ‘ASC’);

Get Current product category id

$_helper = $this->helper(‘catalog/output’);
echo $_category_detail->getName(); //gives current category name
echo $_category_detail->getId(); //gives current category id

Display all categories in magento

function get_categories(){
$category = Mage::getModel(‘catalog/category’);
$tree = $category->getTreeModel();
$ids = $tree->getCollection()->getAllIds();
$arr = array();
if ($ids){
foreach ($ids as $id){
$cat = Mage::getModel(‘catalog/category’);
$arr[$id] = $cat->getName();
return $arr;
$arr = get_categories();
$arr = array_flip($arr);

Get Parent Category of current category

echo $cat_idd = $this->getCurrentCategory()->getParentCategory()->getId();

Get the category ID by product id

$productObj = Mage::getModel(‘catalog/product’)->load($product_id);
$categoryIds = $productObj->getCategoryIds();

To find the parent ID of current category

$_cat = new Mage_Catalog_Block_Navigation();
$curent_cat = $_cat->getCurrentCategory();
$curent_cat_id = $curent_cat->getId();

Get all categories for a product in Magento

$product = Mage::getModel(‘catalog/product’)->load($productId);
$cats = $product->getCategoryIds();
foreach ($cats as $category_id) {
$_cat = Mage::getModel(‘catalog/category’)->load($category_id) ;
echo $_cat->getName();

Frequently Used Magento Extensions

Magento EasyTabs Community Module
Description: Add tabs to the product page
Download link:

Reduced checkout
Description: Skip Shipping Method or Skip Payment Method
Download link:

Layered Navigation SEO
Description: Layered Navigation SEO: ajax, seo urls, price slider, multiple filters for the same attribute.
Download link:

Responsive Custom Menu
Description: Extension allows to customize top menu drop downs. Display all sub categories at once.
Download link:

Simple Order Export
Description: Exports selected orders to csv
Download link:

CCAvenue Payment Gateway Free
Description: Easily integrate your Magento store with the CC Avenue payment gateway.
Download link:

Manage Category, Customer and Customer Address Attributes
Description: You can easily manage custom attributes for category, cusomer and customer address attributes
Download link:

Customer attributes manager
Description: A Customer Attributes Manager extension which can help developers manage attribute easily
Download link:

Optimise Web Mass 301 Redirects
Description: The Optimise Web Redirects extension helps set up bulk 301 redirects by uploading the URL data in a CSV file.
Download link:

Simple Admin Payment
Description: Simple payment method for orders that are created in Magento Admin.
Download link:

Color Swatches Free
Description: Free Color Swatches Magento Extension, Color Switcher
Download link:

Banner Slider by Magestore
Description: Display unlimited magento banners as a slider on top of Homepage or category. Upload links to detail pages.
Download link:

CorlleteLab Imagezoom
Description: Image Zoom for product images. Configurable and Grouped products are also supported.
Download link:

Description: This extension replaces the image gallery with the cloudZoom widget.
Download link:

WebRotate 360 Product Viewer with prettyPhoto Lightbox Image Gallery
Description: Integrate advanced 360 product views created with WebRotate 360 Product Viewer.
Download link:

KM Shippingcarriers
Description: Integrate Aramex, Bluedart and AFL carrier partners and track your shipment from Magento’s admin panel
Download link:

Magento Set, Retrieve and Unset Session Variables

To set a Magento session variable:

$Insertid = 'Hello World';

To Retrieve:

$Insertid = '';

To Unset:


Note that Insertid can be any text you want but ‘set’, ‘get’ and ‘uns’ prefixes are required.

Magento Frequently used fuctions

Magento Home URL
– Mage::getBaseUrl();

Magento Home Directory
– Mage::getBaseDir();

URL of a file in the skin directory
– $this->getSkinUrl(‘images/myfile.png’); // in a template or Block
– Mage::getDesign()->getSkinUrl(‘images/myfile.png’); // from anywhere

Format a price value
– Mage::helper(‘core’)->formatPrice($amount);

Get the display value of a (multi-)select product attribute
– echo $product->getAttributeText(‘manufacturer’);

Create an object instance in magento
– Mage::getModel(‘module/class’); // for models
– Mage::helper(‘module/class’); // for helpers
– Mage::app()->getLayout()->createBlock(‘module/class’, ‘name_in_layout’); // for blocks

GET/POST parameters
– Mage::app()->getRequest()->getParam(‘param_name’); // single parameter
– Mage::app()->getRequest()->getParams(); // all parameters

Get the Id of the curent store view
– Mage::app()->getStore()->getId();

Get all Store Views
– Mage::app()->getStores(); // pass true to include the admin store view, too

Get the configurable/grouped/bundled product a simple product belongs to
– $simpleProduct->loadParentProductIds();
– $parentProductIds = $simpleProduct->getParentProductIds();

Get the simple products assigned to a configurable product

Get an instance of an attribute
Mage::getSingleton(‘eav/config’)->getAttribute($entityType, $attributeCode);

Magento: How to select, insert, update, and delete data?

Here, I will be showing how to select, insert/add, update/edit and delete data in the Magento way.

It’s about implementing the CRUD (Create Read Update Delete) concept. 🙂

Suppose, I have a database table named ‘news‘ with the following fields:-

id : int, auto increment, primary key
title : varchar
content : text
status : 0 or 1

Suppose, I have a module named ‘mynews‘. Here follows the code to select, insert, update, and delete data from the ‘news‘ table.


$data contains array of data to be inserted. The key of the array should be the database table’s field name and the value should be the value to be inserted.

$data = array('title'=>'hello there','content'=>'how are you? i am fine over here.','status'=>1);
 $model = Mage::getModel('mynews/mynews')->setData($data);
 try {
$insertId = $model->save()->getId();
echo "Data successfully inserted. Insert ID: ".$insertId;

 catch (Exception $e){
echo $e->getMessage();


$item->getData() prints array of data from ‘news’ table.
$item->getTitle() prints the only the title field.
Similarly, to print content, we need to write $item->getContent().

$model = Mage::getModel('mynews/mynews');
 $collection = $model->getCollection();
 foreach($collection as $item){


$id is the database table row id to be updated.
$data contains array of data to be updated. The key of the array should be the database table’s field name and the value should be the value to be updated.

// $id = $this->getRequest()->getParam('id');
 $id = 2;
 $data = array('title'=>'hello test','content'=>'test how are you?','status'=>0);
 $model = Mage::getModel('mynews/mynews')->load($id)->addData($data);
 try {
echo "Data updated successfully.";

catch (Exception $e){
echo $e->getMessage();


$id is the database table row id to be deleted.

// $id = $this->getRequest()->getParam('id');

$id = 3;
 $model = Mage::getModel('mynews/mynews');
 try {
echo "Data deleted successfully.";

catch (Exception $e){
echo $e->getMessage();

In this way you can perform select, insert, update and delete in your custom module and in any magento code.

Magento get logged in customers name, email

if($customer = Mage::getSingleton(‘customer/session’)->isLoggedIn()) {
$customer = Mage::getSingleton(‘customer/session’)->getCustomer();
$customerData = Mage::getModel(‘customer/customer’)->load($customer->getId())->getData();
$email = $customer->getEmail();
$firstname = $customer->getFirstname();
$lastname= $customer->getLastname();
// print_r($customerData);