Posts made in June, 2012

How to Use Ajax in Magento to submit forms?

In magento if you want to submit a form using ajax and refresh only a specific area in a form, then follow the procedure below: Create a form with a label and textbox like as shown below: <form name="addcost" id="addcost" method="post" action="<?php echo $this->getUrl('*/*/addCost);?>"> <label>xxx</label><input type="text" name="cost[]" id="cost"/> <label>yyy</label><input type="text"...

Read More

How to get the value of product id or order id from the URL in Magento?

Suppose if we have the URL like this: http://xxxx.com/index.php/admin/catalog_product/edit/id/1149/key/1bc8580308130f6a3191a4494c2c10ed/ Use this code to get the value of product Id : <?php echo $id = $this->getRequest()->getParam('id'); ?> the above id will output 1149. Yeah! Bcoz getParam(‘id‘) means value next to the id, which means 1149.   If you need to output key, then use this: <?php echo...

Read More

Reset All special price and date of all products in magento?

If you have to reset all discount and special price of all products except “Deal of the day” and “Today’s only”, then create a button anywhere in the backend with controller redirected to the below function: <?php public function massDeleteAction() { // get the product collection $products = Mage::getModel('catalog/product')->getCollection(); //load all the product by id in the for loop foreach...

Read More

How to check if condition in ternary operator in php?

We can use ternary operator ?:  for short hand of if else. Example is as follows: $prod=($product == 5)? 'Ladies' : 'Men\'s'; Above example illustrates, if product value ==5 then it returns Ladies or else it will return Men’s. Also we can use like below for checking empty values using ternary operators: $serial = $serialOrder ?: $serialProduct; It will return  $serialOrder when the value is set. If the value of  $serialOrder is empty...

Read More

How to remove white space around the product image in Magento

Magento consists of inbuilt resize function which is used in many phtml files like list.phtml and product view pages.It looks like this: <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(122, 106); ?>" /> This default resize function resize the images with white spaces around the images. To avoid this Situation We have to add a line before that resize...

Read More

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.