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

Magento: Get Set Unset Session

Here are code to Get, Set, and Unset Session in Magento. Set session with variable Name ‘testing_magento‘. The session value here is ‘hello‘. Mage::getSingleton(‘core/session’)->setTestingMagento(‘hello’); Get session ‘testing_magento’ $test = Mage::getSingleton(‘core/session’)->getTestingMagento(); Unset session Mage::getSingleton(‘core/session’)->setTestingMagento(); Note: Use customer or core session in frontend. Use adminhtml session in the backend. Core Session:- Mage::getSingleton(‘core/session’) Customer Session:- Mage::getSingleton(‘customer/session’) Admin Session:- … Read more

Javascript: Add Remove HTML elements

You can add html elements dynamically with Javascript. In this article, I will show you how to do so. I have created two Javascript functions. One for creating html elements and the other for removing them. In my html elements, I have created ‘li’ and ‘strong’ elements inside ‘div’. The div id is ‘summary’. I … Read more

PHP : Read Write XML with DOMDocument

In this article, I will be showing you how to create and read xml document with php’s DOMDocument. The DOM extension allows you to operate on XML documents through the DOM API with PHP 5. Below is the code to create XML file. I have named the output file ‘example.xml’. For better understanding, I have … Read more

PHP Javascript : Playing with multi-dimensional array

I had to work on multi-dimensional array with javascript and php. I had a multi-dimensional array in php. I had to load it into javascript array and then populate the html selection list. The challenge for me was to create multi-dimensional array in javascript and populate selection list with for loop in javascript. Here is … Read more

PHP : Read Write XML with SimpleXML

In this article, I will be showing you how to create and read xml document with php’s SimpleXML extension. The SimpleXML extension provides a very simple and easily usable toolset to convert XML to an object that can be processed with normal property selectors and array iterators. Below is the code to create XML file. … Read more