Jun 16, 2014

How to add custom new or update or delete category attribute in Magento using SQL setup

1. How to add new category attribute:

 
      
    <?php

    /** @var $this Mage_Eav_Model_Entity_Setup */

    $this->startSetup();



    /** Add new atribute */

    $this->addAttribute('catalog_category', 'ur_custom_attribute_name', array(

     'group'         => 'General Information',

     'input'         => 'textarea',

     'type'          => 'text',

     'label'         => 'ur custom attribute title',

     'backend'       => '',

     'visible'       => 1,

     'required'      => 0,

     'user_defined'     => 1,   

     'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,

    ));



    $this->endSetup();



    ?>

      

 


2. How to remove category attribute:
                   
<?php

    /** @var $this Mage_Eav_Model_Entity_Setup */

    $this->startSetup();



    /** Remove existing atribute */

    $this->removeAttribute('catalog_category', 'ur_custom_attribute_name');



    $this->endSetup();



    ?>



      

 


3. How to update category attribute:
                 
 <?php

     /** @var $this Mage_Eav_Model_Entity_Setup */

     $this->startSetup();



     /** Update existing atribute */

     $categoryEntityTypeId = $this->getEntityTypeId('catalog_category');

     $this->updateAttribute($categoryEntityTypeId, 'ur_custom_attribute_name', 'is_wysiwyg_enabled', 1);

     $this->updateAttribute($categoryEntityTypeId, 'ur_custom_attribute_name', 'is_html_allowed_on_front', 1);



     $this->endSetup();



     ?>


      

 


Note: Please add '<class>Mage_Catalog_Model_Resource_Setup</class>' in config.xml 

           
       Path: <resources>

      <affiliatetrack_setup>

       <setup>

        <module>Urnameapce_Urmodulename</module>

        <class>Mage_Catalog_Model_Resource_Setup</class>

      



 


Ignore it, if already done.
Assumption: You have created your custom module.

Jun 12, 2014

Object Oriented Programming in Javascript

Object Oriented Programming concept in Javascript is very similar to other object oriented programming language concept for example : C++, JAVA, C#, Python, PHP, Ruby and Objective-C

This is not the Rocket Science, it very simple if you already have the knowledge of OOPS in any programming language.

Ok. Lets start with the introduction of Object Oriented Javascript.

Introduction 
JavaScript has several objects included in its core; for example, there are objects like Math, Object, Array, and String. The example below shows how to use the Math object to get a random number by using its random() method.

       

           Example: alert(Math.random());


       
 

Every object in JavaScript is an instance of the object Object and therefore inherits all its properties and methods.

Javascript Class:
JavaScript is a prototype-based language which contains no class statement, such as is found in C++ or Java. This is sometimes confusing for programmers accustomed to languages with a class statement. Instead, JavaScript uses functions as classes. Defining a class is as easy as defining a function. In the example below we define a new class called Person


       

          Example: function Person() { }

       
 

Javascript Object (Class Instance):
To create a new instance of an object obj we use the statement new obj, assigning the result (which is of type obj) to a variable to access it later.

In the example below we define a class named Person and we create two instances (person1 and person2).
Example:
       

          function Person() { }

var person1 = new Person();

var person2 = new Person();


       
 

Javascript Property (object attribute):
Properties are variables contained in the class; every instance of the object has those properties. Properties should be set in the prototype property of the class (function) so that inheritance works correctly.

Working with properties from within the class is done by the keyword this, which refers to the current object. Accessing (reading or writing) a property outside of the class is done with the syntax: InstanceName.Property; this is the same syntax used by C++, Java, and a number of other languages. (Inside the class the syntax this.Property is used to get or set the property's value.)

In the example below we define the gender property for the Person class and we define it at instantiation.

       

function Person(gender) {

  this.gender = gender;

  alert('Person instantiated');

}



var person1 = new Person('Male');

var person2 = new Person('Female');



//display the person1 gender

alert('person1 is a ' + person1.gender); // person1 is a Male


       
 

This is just a sample of Object Oriented Javascript Programming, Please read below article for details.

Reference:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScript

http://www.functionx.com/javascript/Lesson07.htm

Jun 4, 2014

How to create virtual host for phpmyadmin to access database in Ubuntu (LAMP)

Step 1 — Create the Directory Structure:
- Create a folder name as "phpmyadmin" in /var/www directory.
sudo mkdir -p /var/www/phpmyadmin

Step 2 — Grant Permissions:
sudo chown -R $USER:$USER /var/www/phpmyadmin
sudo chmod -R 755 /var/www

Step 3 — Create New Virtual Host Files
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/phpmyadmin.conf
Now Open the new file as follow
sudo gedit /etc/apache2/sites-available/phpmyadmin.conf

Copy the code below and replace with all old text inside this file.
<VirtualHost *:8080>
    ServerAdmin admin@test.phpmyadmin
    ServerName phpmyadmin
    ServerAlias www.phpmyadmin
    DocumentRoot /usr/share/phpmyadmin/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Save and close the file.

Step 4 — Link our virtual host with localhost in /etc/hosts file:
Open file hosts as follow
sudo gedit /etc/hosts
Add the below line in host file
127.0.1.1 phpmyadmin
Save and close the file.

Step 5 — Enable the New Virtual Host Files
We can use the a2ensite tool to enable each of our sites like this:
sudo a2ensite phpmyadmin.conf

// Reload the apache configuration
  sudo service apache2 reload

  // Restart Apache
  sudo service apache2 restart

Step 6 — Test your phpmyadmin site
http://phpmyadmin

Finished!!!!!!!

Jun 3, 2014

How To Create Virtual Host on Ubuntu OS (LAMP)

## Note:: Assuming you have installed LAMP ##

Case: We want to create a virtual host name as "test.localhost"

Step 1 — Create the Directory Structure:
- Create a folder name as "test.localhost" in /var/www directory.
sudo mkdir -p /var/www/test.localhost

Step 2 — Grant Permissions:
sudo chown -R $USER:$USER /var/www/test.localhost
sudo chmod -R 755 /var/www

Step 3 — Create Demo Page for Virtual Host
- Create index.php file inside the folder /var/www/test.localhost
and write below sample text in index.php file and save.
<?php
echo 'Virtual host testing succesfullly done...';
?> 

Step 4 — Create New Virtual Host Files
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/test.localhost.conf
Now Open the new file as follow
sudo gedit /etc/apache2/sites-available/test.localhost.conf

Copy the code below and replace with all old text inside this file

<VirtualHost *:80>
    ServerAdmin admin@test.localhost
    ServerName test.localhost
    ServerAlias www.test.localhost
    DocumentRoot /var/www/test.localhost
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Save and close the file.

Step 5 — Link our virtual host with localhost in /etc/hosts file:
Open file hosts as follow
sudo gedit /etc/hosts
Add the below line in host file
127.0.1.1 test.localhost
Save and close the file.

Step 6 — Enable the New Virtual Host Files
We can use the a2ensite tool to enable each of our sites like this:
sudo a2ensite test.localhost.conf

When you are finished, you need to restart Apache to make these changes take affect:
sudo service apache2 restart

Step 7 — Test your site
http://test.localhost

You should see a page that looks like this:
Virtual host testing succesfullly done...

Finished!!!!!!!