Skip to main content

Posts

Showing posts from April, 2014

Send emails using cronjob in Magento

Hi All !! While working on one of my project client ask me to create a cronjob which send emails to customers. Firstly, I thought it might be difficult but it was so easy. In this post we will learn it. Suppose package name is 'MyPackage' and module name is 'MyModule. MyModule is in local directory. Following are the files on which we have to work: 1) app/code/local/MyPackage/MyModule/etc/config.xml 2) app/code/local/MyPackage/MyModule/etc/system.xml 3) app/code/local/MyPackage/MyModule/Model/Observer.php 4) app/locale/en_US/template/email/<custom_email_template> Step 1: 1) File Name:   app/code/local/MyPackage/MyModule/etc/config.xml Add below code inside config tag <config>  <crontab>     <jobs>         <your_cronjob_code>             <schedule>                 <cron_expr>* * * * *</cron_expr>             </schedule>             <run>                 <model>MyModule/observe

Change Admin Password using MySql query in magento

Hello friends, Sometimes we forgot admin password and then we are stuck. In that case we can change the admin password using below sql query. Before that we need to understand how the password is stored in magento. Magento stores admin password by concatenating two string: 1) one is randomly generated string having two alphabets one in capital letters and another in small letters like: aU, gE etc. 2) Password and the randomly generated string in MD5 format. For example if we want to use 'admin123' as password then string will be 'aUadmin123'. Magento concatenate both two strings and stores it. Admin details are stored in admin_user table so we have to use update query on admin_user table. Now we know about that how magento stores password it will be easy for us to create an update query. Update 'admin_user'  set password= CONCAT(MD5( 'aUadmin123') , ':aU') where username = 'admin'; That's all, now you can easily chang

Add Products to cart Programmatically in Magento

Sometimes we need to add products into cart programmatically in controller. Below is the code which you can use to add product to cart.   1) For Simple Products If you are working in magento controller and wants to add a simple product programmatically then here is the code: Suppose our product id value stored in $productId.         // Below code will create instance of cart         $cart = Mage::getModel('checkout/cart');         // This will initialize cart         $cart->init();         // Get the product collection by passing product id         $productCollection = Mage::getModel('catalog/product')->load($productId); This product collection will be required as we have to pass it at the time of adding product to cart. For adding the product we have to call addProduct() function. In this function we have to pass two parameters first is productcollection and second is an array. This array contains product id and quantity which we are going