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

Javascript: Show/Hide HTML elements

Here, I will be demonstrating on showing or hiding a div when a link is clicked. I have done this with Javascript and CSS. I have called showHideDiv() Js function when the link is clicked. The display of the div where content is present, is visible or hidden on each click. For this, CSS styling … 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.

Magento: Get parent id of simple product associated to configurable product

Scenario: A simple product is associated with a configurable product. You have the id of the simple product. Now, you need the id of the configurable product with which the simple product is associated. Get parent product id, i.e. get id of configurable product from a simple product. Note: This method is deprecated after 1.4.2.0 … Read more

Magento: Resize Image

You can resize image with fixed height and variable width. Or, you can resize with fixed width and variable height. Following code shows how you do it in Magento. Fixed width of 600px <?php echo $this->helper('catalog/image')->init($_product, 'image') ->constrainOnly(TRUE) ->keepAspectRatio(TRUE) ->keepFrame(FALSE) ->resize(600,null) ?> Fixed height of 600px <?php echo $this->helper('catalog/image')->init($_product, 'image') ->constrainOnly(TRUE) ->keepAspectRatio(TRUE) ->keepFrame(FALSE) ->resize(null,600) ?> … Read more

Magento: Get current URL of the page

Getting URL of a current page you are visiting or working on is a common requirement in any web development project. There are various ways you can get the current URL of a page in Magento. Here are some :- From Mage_Core_Helper_Url class $currentUrl = Mage::helper('core/url')->getCurrentUrl(); From Mage_Core_Model_Store class $currentUrl = Mage::app()->getStore()->getCurrentUrl(false); If you want … Read more

Magento: Format Price

When you fetch product data, you get the price as integer. Now, you have to display the price with currency suffix. You can format price with the following code. Let $_finalPrice be the integer price fetched. To display price with currency symbol: $formattedPrice = Mage::helper('core')->currency($_finalPrice,true,false); // OR $formattedPrice = Mage::helper('core')->formatPrice($_finalPrice, false); To display price without … Read more