Category: Magento

Modify item price in cart after placing order using sales_quote_add_item

We can easily modify product price after placing order in magento using the event sales_quote_add_item. We can see this hook registered in app/code/core/Mage/Sales/Model/Quote.php line:874. This is the event created by magento.Mage::dispatchEvent(‘sales_quote_add_item’, array(‘quote_item’ => $item)); We can access $item values using its registered event name sales_quote_add_item and we can modify the price with our logic. Follow […]

Read More…

Override magento controller

Modifying magento core file is not at all good idea. All core files that we have modified will be smashed while magento upgrade.Magento have a feature to keep our custom code in local(app/code/local) folder. Inside that folder we can keep our custom codes safely.There are 2 way to override magento core module. Create same folder […]

Read More…

Delete single order in magento using SQL query

Here is the query to delete single order in magento. All we need to do is just replace ‘xxxxxxxxx’ with your order_id and run it in phpMyAdmin. It works fine in Magento 1.4.x and 1.7.x version. SET @orderId = ‘XXXXXXXXX’; #replace this WITH your ORDER NUMBERSET FOREIGN_KEY_CHECKS = 1;DELETE FROM sales_flat_order WHERE increment_id = @orderId;DELETE […]

Read More…

Add tinyMCE editor in magento custom module

If we have created a custom module using Magento Module creator means, it will not contain ‘wysiwyg(tinyMCE)’ editor feature.We can add the ‘wysiwyg’ editor in custom module within 2 steps.Step 1:Add the following code in /controllers/Adminhtml/BlogController.php under the line $this->getLayout()->getBlock(‘head’)->setCanLoadExtJs(true). if (Mage::getSingleton(‘cms/wysiwyg_config’)->isEnabled()) { $this->getLayout()->getBlock(‘head’)->setCanLoadTinyMce(true);} Step 2:Add the following code in /Block/Adminhtml/Blog/Edit/Tab/Form.php file, within your field […]

Read More…

Add success or error message using magento session

Error message Set error message for front page. $message = $this->__(‘Got an error’);Mage::getSingleton(‘core/session’)->addError($message); Set error message for admin page. $message = $this->__(‘Got an error’);Mage::getSingleton(‘adminhtml/session’)->addError($message); Success message Set success message for front page. $message = $this->__(‘Got an error’);Mage::getSingleton(‘core/session’)->addSuccess($message); Set success message for admin page. $message = $this->__(‘Got an error’);Mage::getSingleton(‘adminhtml/session’)->addSuccess($message); If you are unable to view the […]

Read More…

Update order status programmatically in magento

We can update order status of product in magento by using this below code. setState() function will do this for us, all we need is just pass the required arguments like state to be updated, status of the state, comment for the status change. $order = Mage::getModel(‘sales/order’)->loadByIncrementId($orderId); $state = ‘new’;$status = ‘label_generated_by_user’;$comment = ‘You have […]

Read More…