Magento: Get store information

Magento allows to maintain multiple websites from single backend admin. Furthermore, each website can have multiple stores. Below is the code to get Magento store information like store id, store code, store name, etc. All of these functions can be found in class Mage_Core_Model_Store. Get store data array // Get all store data in an … Read more

Magento: Get height and width of Product Image

The following functions can be used to get product’s image height and width. Image functions are defined in Mage_Catalog_Helper_Image class. getOriginalWidth gives width of image. getOriginalHeigh or getOriginalHeight gives height of image. getOriginalSizeArray gives the height and width of an image in array. $_product = $this->getProduct(); $imageWidth = $this->helper('catalog/image')->init($_product, 'image')->getOriginalWidth(); if($imageWidth > 600) { $lightboxImage … Read more

Magento: How to call static block from template (.phtml) file?

You can easily call any static block from template (phtml) file. At first, you have to create a static block. Let us suppose, you created a static block with the identifier cool_items. Now, you can call the static block from any phtml file with the help of following code: echo $this->getLayout() ->createBlock('cms/block') ->setBlockId('cool_items') ->toHTML(); Thanks.

Magento: How to call block directly from phtml file without defining in layout?

You can call your block directly from a phtml file with the following code. You can keep this code and call the block from any phtml file. I have assumed my module name as Newmodule and my block name as Newblock.php. The phtml file for the block is assumed to be newmodule/newblock.phtml echo $this->getLayout() ->createBlock('newmodule/newblock') … Read more

Magento: Get order option of configurable and bundle product in cart

We are not allowed to order configurable and bundle products directly. We have to select product options from product detail page of configurable or bundle product. Only then we can add the product to cart. The following code fetches the order option selected for configurable and bundle products: // For configurable product Mage::getModel('catalog/product_type_configurable')->getOrderOptions($this->getProduct()); // For … Read more

Magento: How to get attribute name and value?

Attribute in Magento is like a property. All Products, Categories, Orders, Customers, etc. have attributes. For example, the attribute of a product is its name, sku, description, image, etc. This article will show you how to get attribute name and value for any product. Get attribute’s name, value, type, and other parameters The attribute code … Read more

Magento: Redirect functions

The redirect functions are present in Mage_Core_Controller_Varien_Action class. /* Redirect to certain url  */ _redirectUrl($url) /* Redirect to certain path */ _redirect($path, $arguments=array()) /* Redirect to success page */ _redirectSuccess($defaultUrl) /* Redirect to error page */ _redirectError($defaultUrl) /* Set referer url for redirect in response */ _redirectReferer($defaultUrl=null) /*  Identify referer url via all accepted methods … Read more

Magento: How to delete System Attribute?

Suppose, you want to delete an attribute. But there is no delete option while you edit the attribute. This means that the attribute is system attribute. System attributes cannot be deleted. Only user defined attributes can be deleted. To delete the attribute, you have to make it user defined. – Go to phpmyadmin – Go … Read more