This code will print the role name of the user whose id is store in $user_id...

 

According to magento characteristics, we can get the custom created product attributes at front side in easy way by $_product->getCustomCreateAttribute() But when we create an attribute for an category then magento does not show by $_main_category->getCustomCreateAttribute() Magento only show the attribute value at front side which created by system or Magento. So for this we have to use below code to show category attribute by forcefully. Here, $categoryForcefully is an object of...

 

This is helpful during write the plugin or widget for...

 

many times we need to do operation on two column values and show in the admin panel. for this we have to follow these steps: 1. Add column in your Grid.php file: 2. Now create a folder in the AdminHtml folder with name 'Renderer' 3. Create a new php file with name 'Qty.php' 4. Write below code in the Qty.php file: Ref: http://www.magentocommerce.com/boards/viewthread/192232/#t239222 That's...

 

Mostly all wordpress developers write the code to create widgets in admin side. and he use following code: var ajaxurl =''; var data = { action: 'action_function_name' }; // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php jQuery.post(ajaxurl, data, function(response) { alert(response); }); But when he wants to use Ajax at front side without login in Admin side area. then admin-ajax.php file will not run because it is...

 

Many times we need to show all roles in a dropdown for our widget and we try to find in database but we are unable to get correct value.. so here I am providing a good solution to get all list of roles:

get_names();

         // Below code will print the all list of roles.
         print_r($roles);        
?>

 

Mostly all Models in the Magento have a corresponding Collection object that can be used to fetch multiple instances of a Model. To instantiate a Product collection, do the following $collection = Mage::getModel('catalog/product')->getCollection(); Products are a Magento EAV style Model, so you'll need to add on any additional attributes that you want to return. $collection = Mage::getModel('catalog/product')->getCollection(); //fetch name and weight into...

 

Today I have work in magento and work was save multiple dates in an attribute witout entering multiple values in one field. and need to provide multiple text box ( with date icon to select date )where user can select date and submit the form. On the submit time I have to fill all text boxes value in a single attribute. And this was good news for me that I have written code for this. Here I am providing basic code to create multiple text fields (elements) by javascript. Insert below code in...

 

My last two posts told to create javascript and html file. This post will tell you last step to drag and drop div are with pure javascript ( without jQuery ). Add below css code to head tags in the index.html file: body{ font-family: Trebuchet MS, Lucida Sans Unicode, Arial, sans-serif; height:100%; width:100%; margin:10px; padding-left:0px; } form{ display:inline; } .imageBox:hover{ cursor:move; } .imageBox,.imageBoxHighlighted{ width:130px; /*...

 

After reading my previous post Drag and Drop div area with pure javascript - Step 1, you have created javascript file draganddrop.js. Means you can add this javascript file to html page. so create a file index.html file and put below content in the head tag : And put below code inside the body tag: Image number 1 Image number 2 Image number 3 Image number 4 Image number 5 Image number...

 

Today I have to work on drag and drop functionality and I found that on mostly sites it provides using Jquery but I have to develop with pure javascript. so I found best code for it. and this was the solution : First create a file draganddrop.js and put below code in this file: var operaBrowser = false; if(navigator.userAgent.indexOf('Opera')>=0)operaBrowser=1; var MSIE = navigator.userAgent.indexOf('MSIE')>=0?true:false; var navigatorVersion = navigator.appVersion.replace(/.*?MSIE...

 

If you want to show any div area in the middle on click any link or button then follow these steps: 1. First download and add JQuery js in your file. 2. now create a function If you want to show any div area in the middle on click any link or button then follow these steps: 1. First download and add JQuery js in your file. 2. now create a function function showPageOnClick(divId) { // divId is an Id of the div var WindowHeight = 0; var WindowWidth = 0; // the more standards...

 

This is most useful when you don't know that what will be table prefix on server side. This situation may be generate when you are developing project at local system and you know table prefix and you have no access on server side so you are not able to know what table prefix used during magento installation on server phpmyadmin. That time you can use below code for write the table name in your custom query. $tableName =...

 

Any developer wants to check what sql is executing during page load. so he can check and identify the getting errors: To print the sql go to folder : app\code\core\Mage\Catalog\Model\ and open file Layer.php search the function : and replace : to and save and run front page again... you will see all Sqls are showing on the...

 

Javascript Trim Functions Use the code below to make trim a method of all Strings. These are useful to place in a global Javascript file included by all your pages. String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g,""); } String.prototype.ltrim = function() { return this.replace(/^\s+/,""); } String.prototype.rtrim = function() { return this.replace(/\s+$/,""); } // example of using trim, ltrim, and rtrim var myString = " hello my name is...

 

Magento comes with built in function for retrieving URL paths. Function is called getBaseUrl() and its located under Mage class. However, function is not documented as it should be. Documentation only states that function retrieves $type parametar which is by default equal to “base”. Here is the list of all the available parameters I found. As you can see, they all come from Mage_Core_Model_Store. Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS); //...

 

Its a very simple: