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

Magento: Describing Flat Catalog

Difference between EAV and Flat Catalog In EAV database model, data are stored in different smaller tables rather than storing in a single table. Like, product name is stored in catalog_product_entity_varchar table product id is stored in catalog_product_entity_int table product price is stored in catalog_product_entity_decimal table EAV database model is used by Magento for easy … Read more

Magento: Writing Custom Log Message

To be able to write your custom log message, you have to enable logging from Magento Admin. To enable logging, go to Magento Admin Panel -> System -> Configuration -> Developer -> Log Settings -> Enabled = Yes Then in your code, you can write the following: Mage::log("Your Log Message"); You can check it at … Read more

Magento: Load store specific product

Different stores can be set in Magento. A product can be made visible in selected stores. /** * get store id */ $storeId = Mage::app()->getStore()->getId(); /** * call the Magento catalog/product model * set the current store ID * load the product */ $product = Mage::getModel('catalog/product') ->setStoreId($storeId) ->load($key); Hope it helps. Thanks.