Skip to main content

Posts

Magento - Get product by sku

Hi Everybody, I was working with magento products and found that how we can find product object using sku and I have found below solution. // Here $sku is our sku variable for product. $sku = 'A1001' ; //loadByAttribute function is helpful for getting product data $product = Mage:: getModel ( 'catalog/product' ) -> loadByAttribute ( 'sku' , $sku ) ;

Angular JS Table Filter and Sorting

Hi All, I am new to angular js and doing some random stuff. I am sharing the code here. Hope this will help you some where. <style> table, td  {   border: 1px solid grey;   border-collapse: collapse;   padding: 5px; } .sortorder:after {   content: '\25b2'; } .sortorder.reverse:after {   content: '\25bc'; } </style> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> <body> <div ng-app="myApp" ng-controller="customersCtrl"> <table>     <tr>         <td ng-click="order('Name')">           Customer Name           <span class="sortorder" ng-show="predicate === 'Name'" ng-class="{reverse:reverse}"></span>         </td>     ...

Add/Update product attribute using CSV in Magento

Hi All !!! As per my last post we have updated customer group prices in these I am sharing code to add/update product attributes whether its a custom or default attribute. Have a look at the code: <?php //Upload File if (isset($_POST['submit'])) {     if (is_uploaded_file($_FILES['filename']['tmp_name'])) {         echo "<h1>" . "File ". $_FILES['filename']['name'] ." uploaded successfully." . "</h1>";     }     //Import uploaded file to Database     $handle = fopen($_FILES['filename']['tmp_name'], "r");     $i=0;     while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {         if($i>0) {             $si = Mage::getModel('catalog/product')->loadByAttribute('sku',$data[0]);            ...

Add/Update Customer group product price using CSV in Magento

Hi Guys!!! After a long time I am back on posting. While working on a project I came with a problem of updating customer group pricing in magento using CSV. Well not  a big problem, let first discuss the logic. There are two tables in magento updates when you add customer group price: 1) catalog_product_index_group_price 2) catalog_product_entity_group_price So here is the code <?php //Upload File if (isset($_POST['submit'])) {     if (is_uploaded_file($_FILES['filename']['tmp_name'])) {         echo "<h1>" . "File ". $_FILES['filename']['name'] ." uploaded successfully." . "</h1>";         //readfile($_FILES['filename']['tmp_name']);     }     //Import uploaded file to Database     $handle = fopen($_FILES['filename']['tmp_name'], "r");     $i=0;     while (($data = fgetcsv($handle, 1000, ",...

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>           ...

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...