Add custom attribute in magento admin product grid

We all know that magento admin product grid display some attribute of the product. Some time we require displaying the custom attribute value into that grid. So I post this blog to fulfill that requirement.

Step: 1: Create the attribute for the product and give the proper type.

Example: Crates attribute ‘newstatus’

 

Step: 2: Crate directory structure.

For that first we create the following directory structure in our magento.


[Magento]\app\code\local\Mage\Adminhtml\Block\Catalog\Product

 

Step: 3: Overwrite the default product grid.

For adding new attribute to grid, overwrite the default grid file. For that we copy the file “Grid.php” from the following location


[Magento]\app\code\core\Mage\Adminhtml\Block\Catalog\Product

And paste this file at our new created location. So path become like this:


[Magento]\app\code\local\Mage\Adminhtml\Block\Catalog\Product\Grid.php

 

Step: 4­: Add Attribute to grid.

First find out the following function.


protected function _prepareColumns()

Now add the code for displaying the attribute to grid. Here I insert the attribute ‘newstatus’ created at step-1.


$this->addColumn('newstatus',

array(

'header'=> Mage::helper('catalog')->__('Company Status'),

'width' => '80px',

'index' => 'newstatus',

'type'  => ‘text’,

));

Step: 5­: Add Attribute to filter grid.

Find the following function.


protected function _prepareCollection()

 

Add the fields in that code for filtration.


->addAttributeToSelect('newstatus')

 

Refresh the cache memory and reindexing the data. Now this attributes display into admin product grid.

I hope this will help you.

Thank you.

Advertisements

Registering android App with facebook

Hello Friends,

First of all you might be thinking that what is the need of registering your android application with facebook? Then I want to clarify that If you want to integrate Android application with facebook then  you need to register your android app with the facebook.

Today I am going to explain you how to register your android application with facebook.

Following are two  easy steps to do this.

Step: 1   Generating App Signature for Facebook Settings

You can generate your application signature (keyhash) using keytool that comes with java. But to generate signature you need openssl installed on your pc. If you don’t have one download openssl from here and set it in your system environment path.

Open your command prompt (CMD) and run the following command to generate your keyhash. While generating hashkey it should ask you password. Give password as android. If it don’t ask for password and don’t give you app signature then your keystore path is incorrect.

keytool -exportcert -alias androiddebugkey -keystore "C:\Users\Indies\.android\debug.keystore" | openssl sha1 -binary | openssl base64

Step: 2    Registering your Facebook Application

After generating your app signature successfully, register your facebook application by going to create new facebook   application and fill out all the information needed. And select Native Android App and give your hashkey there which you generated previously using keytool.


fbId

See the following image which shows application Id which you have to use in your application for accessing facebook:
2013-01-05_122015

Solve ECJ error in liferay IDE

You must have come across the errorTask cannot continue because ECJ is not installed. ECJ was automatically installed. Please rerun your task. Total time: 6 secondwhile ant running the build.xml file in liferay.

To solve this error follow the below steps:

In eclipse Go to Window (menu) –> Preferences and the below window gets opened up:2012-12-29_150309

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Where you can see an option named “Ant”. Under the Ant option select runtime, so you will see the above showed Runtime tab.

Select the Global Entries section, now on the right hand side click on the Add External Jar. Select the ecj.jar file kept in your computer.

You can find the ecj.jar in the liferay sdk/lib folder. And that’s it. Now build your project again. You will see a BUILD SUCCESSFFULL message.

Cheers!!!

Solving 404 error after upgrade magento to 1.7

Hello friends,

By doing many useful changes magento is improving a lot in the current competitive market. As a part of that Magento released the latest stable community version 1.7.0.2 on 5th July 2012.

Now it’s time for magento store owners to upgrade their store to latest version to get the maximum advantage of new functionalities.

To upgrade the magento store you can follow the steps given in the below link.

https://indiestechtips.wordpress.com/2012/05/19/magento-upgrade/

Now let’s come to the main topic. Just before a month I had a task to upgrade magento to 1.7. To do that task I followed the proper steps. But after upgrading I opened my site and it was giving “404 Error” on each page of site.

At that time I was surprised and confused about what happened with my site.

Then to solve that problem I searched the web and found the cause of problem and solution of it that I have discussed below.

Many times while doing any operation with magento connect manager such a 404 error encounters and our site get stopped working.

The cause of that problem is incorrect folder permission.

To solve that problem just download the magento-cleanup.php file from here, put it in your magento root folder and execute it.

Once you executed it you can see the list of messages that magento cleanup has reset the folder permission.

And if you have “maintenance.flag” file in your magento root folder then delete it.

That’s it.

Now open your site and see the result.

Also refer the under given link to get knowledge about some nasty issues which can occur after upgrading magento to 1.7.

https://indiestechtips.wordpress.com/2012/08/18/problems-with-magento-while-upgrading-to-1-7/

Hope this will help you.

Thanks.

Configure Magento Multistore with parked domain

The Magento script allows you to setup multiple stores using different domains which you would have to add as parked for your account. To setup Magento Multistore with parked domains follow this steps:

Note: This article assumes that you have already added a domain as parked for your account.

1) Login the Magento administration area

2) Navigate to “Catalog” -> “Manage Categories”

3) Click the “Add root category” button, which could be found on the left.

mage-root-cat

4) On the right side for “Name” enter your parked domain. For example : example.com. For “Is active” and “Is Anchor” select “yes” from the dropdown menu.

5) Click the “Save Category” button.

6) Now navigate to “System” -> “Manage Stores”

7) Click the “Create website” button.

8) For “Name” use example.com (in your case your parked domain). For code use example (or one by your choice). It is important to remember these settings as you will need them later.

mage-new-website

9) Save the website.

10) Now click on the “Create Store” button.

11) For website choose your example.com (your parked domain) from the dropdown menu. For “Name” you may enter “Example”. For “Root Category” select your parked domain again from the dropdown menu. Hit the “Save” button.

mage-new-store1

Once saved, click the “Create Store View” button.

12) For the “Store” select “Main Store” from the dropdown menu. For “Name” enter “English”. For the code you may use one by your choice. For “Status” select “Enabled”.

13) Save the “Store View”.

14) Navigate to “System” -> Configuration

15) Change “Current Configuration Scope” from “Default Configu” to example.com (or your parked domain).

16) From the left side menu select “Web”

17) For the “Secure” and “Unsecure” sections remove the mark for “Use Default” box. It could be found next to “Base URL”. Now enter the URL for your magento store: http://www.example.com.

mage-base-url

(you should change that with your actual URL)

18) Click the “Save Config” button.

19) Still under “System -> Configuration” change the “Current Configuration Scope” to “Default Config”.

20) Select “Web” from the left sidebar under the General section.

21) For “URL Options -> Auto-redirect to Base URL” set to “No”.

mage-url-redirect

22) Click the “Save Config” button.

23) Now using a text editor open the .htaccess file of your Magento script. Add the following lines in the end of the file:

SetEnvIf Host www\. example\.com MAGE_RUN_CODE=YOUR_CODE_HERE
SetEnvIf Host www\. example \.com MAGE_RUN_TYPE=website
SetEnvIf Host ^ example \.com MAGE_RUN_CODE=YOUR_CODE _HERE
SetEnvIf Host ^ example \.com MAGE_RUN_TYPE=website

You should change:
“example \.com” with your parked domain.

YOUR_CODE_HERE – with the actual code which you have used upon creating the store.

Done ! 🙂
Hope this will help you.
Thanks.

Expandable ListView in Android

Hello Friends,

Today,I will explain you about Expandable listview in android that what is actually Expandable Listview and how it works with simple example.

ExpandableListView is very useful when you want to sort lists into categories.
Like: If you want to make an app for downloading movies and  you might want to categories them by genre, so you can navigate through them easier using ExpandableListView.

A view that shows items in a vertically scrolling two-level list. This differs from the ListView by allowing two levels: groups which can individually be expanded to show its children. The items come from the  ExpandableListAdapter associated with this view.

Now, We will go through one simple example so you can get some idea.

1)  Lets first create a new Android project and name it “indies.expandListViewDemo”
and the build target for Android 2.2, and next set the following:
Application name: Movie expListView
Package name: com.indies.expandListView
Create Activity (Checked): MovieActivity
Then press Finish.

2)Basic Layout:

The layout is fairly simple.
Go to res->layout and open the file main.xml
There you’ll only find a LinearLayout and a TextView.
Remove the TextView and add the following

<ExpandableListView
android:id="@+id/ExpListview"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:groupIndicator="@null" />

So now, the code should look like this

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=<i>"http://schemas.android.com/apk/res/android"</i>
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#000000"
android:paddingLeft="5dip"
android:paddingRight="5dip"
android:paddingTop="5dip">

<ExpandableListView
android:id="@+id/ExpListView"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:cacheColorHint="#000000"
android:groupIndicator="@null"/>
</LinearLayout>

3)  Creating  classes for handle the data

Let’s start out by creating a new package in the src-folder and name com.indies.expandListView.Classes
In this package we are going to create 2 class-files, one named ExpandListGroup.java, and the other name ExpandListChild.java.
In this code we will only get and set the values.

The ExpandListChild.java is going to hold 1 value  Name :

package com.indies.expandListView.Classes;

public class ExpandListChild {

private String Name;
public String getName() {
return Name;
}

public void setName(String Name) {
this.Name = Name;
}}

And the ExpandListGroup.java is going to hold 2 values called Name and Items

package com.indies.expandListView.Classes;

import java.util.ArrayList;

public class ExpandListGroup {

private String Name;
private ArrayList<ExpandListChild> Items;

public String getName() {
return Name;
}

public void setName(String name) {
this.Name = name;
}

public ArrayList<ExpandListChild> getItems() {
return Items;
}
}

4) The Adapter: Here is the somewhat tricky part. the ExpandListAdapter, this is the code that will handle the Items so they can be displayed. For this part we are going to create a new package, and we are naming it com.indies.expandListView.Adapter In this package we are going to create a new class called ExpandListAdapter.java Here is the code for that class

package com.indies.expandListView.Adapter;

import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.ImageView;
import android.widget.TextView;

import android.widget.ExpandableListView.OnGroupCollapseListener;
import android.widget.ExpandableListView.OnGroupExpandListener;
import com.indies.expandListView.Classes.ExpandListGroup;
import com.indies.expandListView.Classes.ExpandListChild;
import com.indies.expandListView.R;

public class ExpandListAdapter extends BaseExpandableListAdapter {

private Context context;
private ArrayList<ExpandListGroup> groups;
private ExpandableListView mExpandableListView;
private int[] groupStatus;

public ExpandListAdapter(Context context,ExpandableListView pExpandableListView, ArrayList<ExpandListGroup> groups) {

this.context = context;
this.groups = groups;
mExpandableListView=pExpandableListView;
groupStatus = new int[groups.size()];
setListEvent();
}

private void setListEvent() {
mExpandableListView.setOnGroupExpandListener(new OnGroupExpandListener() {

@Override
public void onGroupExpand(int arg0) {
groupStatus[arg0] = 1;
}
});

mExpandableListView.setOnGroupCollapseListener(new OnGroupCollapseListener() {

@Override
public void onGroupCollapse(int arg0) {
groupStatus[arg0] = 0;
}
});
}

public void addItem(ExpandListChild item, ExpandListGroup group) {

if (!groups.contains(group)) {
groups.add(group);
}

int index = groups.indexOf(group);
ArrayList<ExpandListChild> ch = groups.get(index).getItems();
ch.add(item);
groups.get(index).setItems(ch);
}

public Object getChild(int groupPosition, int childPosition) {

ArrayList<ExpandListChild> chList = groups.get(groupPosition).getItems();
return chList.get(childPosition);
}

public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}

public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View view,

ViewGroup parent) {
ExpandListChild child = (ExpandListChild) getChild(groupPosition, childPosition);

if (view == null) {
LayoutInflater infalInflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
view = infalInflater.inflate(R.layout.<i>expandlist_child_item</i>, null);
}

TextView tv = (TextView) view.findViewById(R.id.<i>item_title);
tv.setText(child.getName().toString());
return view;
}

public int getChildrenCount(int groupPosition) {

ArrayList<ExpandListChild> chList = groups.get(groupPosition).getItems();
return chList.size();
}

public Object getGroup(int groupPosition) {
return groups.get(groupPosition);
}

public int getGroupCount() {
return groups.size();
}

public long getGroupId(int groupPosition) {
return groupPosition;
}

public View getGroupView(int arg0, boolean arg1, View arg2, ViewGroup arg3)  {

GroupHolder groupHolder;

if (arg2 == null) {
arg2 = LayoutInflater.from(this.context).inflate(R.layout.expandlist_group_item,null);

groupHolder = new GroupHolder();
groupHolder.img = (ImageView) arg2.findViewById(R.id.tag_img);
groupHolder.title = (TextView) arg2.findViewById(R.id.group_title);
arg2.setTag(groupHolder);
}
else
{
groupHolder = (GroupHolder) arg2.getTag();
}

if (groupStatus[arg0] == 0) {

groupHolder.img.setImageResource(R.drawable.down_arrow);
}
else {

groupHolder.img.setImageResource(R.drawable.up_arrow);
}

groupHolder.title.setText(groups.get(arg0).getName());
return arg2;
}

class GroupHolder {
ImageView img;
TextView title;
}

public boolean hasStableIds() {
return true;
}

public boolean isChildSelectable(int arg0, int arg1) {
return true;
}

}

Above code gets each group and draws it on the screen in the correct order. Then, when you expand one of them, it gets the Childs and draws them on the screen in the correct order. Above code also sets the displayed text for each group and child.

5)  Group and child layout Lets go into the res->layout and add 2 new xml files named expandlist_child_item.xml and expandlist_group_item.xml The code for each of them are very  simple. For the expandlist_group_item.xml

<?xml version=<i>"1.0"</i> encoding=<i>"utf-8"</i>?>
<RelativeLayout xmlns:android=<i>"http://schemas.android.com/apk/res/android"</i>

android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:paddingTop="5dip">

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="70dp"
android:background="#13a0d5"
android:gravity="center_vertical">

<TextView
android:id="@+id/group_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="15dip"
android:textColor="#ffffff"
android:textSize="25dip"
android:textStyle="bold"/>
</LinearLayout>

<ImageView
android:id="@+id/tag_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_alignParentRight="true"
android:src="@drawable/down_arrow"/>

</RelativeLayout>

Now, For the expandlist_child_item.xml

<?xml version=<i>"1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=<i>"http://schemas.android.com/apk/res/android"</i>

android:id="@+id/groupItem"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#0b5c7a"
android:clickable="true" >

<TextView
android:id="@+id/item_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dip"
android:layout_marginLeft="15dip"
android:text="sample"
android:textColor="#ffffff"
android:textSize="20sp"/>
</LinearLayout>

6)  Activity: Go in to src->com.indies.expandListView and open the MainActivity.java This is the code you’ll see.


package com.indies.expandListView;

import java.util.ArrayList;
import com.indies.expandListView.Adapter.ExpandListAdapter;
import com.indies.expandListView.Classes.*;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ExpandableListView;

public class MovieActivity extends Activity {
    /** Called when the activity is first created. */
	private ExpandListAdapter ExpAdapter;
	private ArrayList<ExpandListGroup> ExpListItems;
	private ExpandableListView ExpandList;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ExpandList = (ExpandableListView) findViewById(R.id.ExpListView);
        ExpListItems = SetStandardGroups();
        ExpAdapter=new ExpandListAdapter(getApplicationContext(),ExpandList,ExpListItems);
        ExpandList.setAdapter(ExpAdapter);
    }

    public ArrayList<ExpandListGroup> SetStandardGroups() {
    	ArrayList<ExpandListGroup> list = new ArrayList<ExpandListGroup>();
    	ArrayList<ExpandListChild> list2 = new ArrayList<ExpandListChild>();
        ExpandListGroup gru1 = new ExpandListGroup();
        gru1.setName("Action Movies");
        ExpandListChild ch1_1 = new ExpandListChild();
        ch1_1.setName("The Dark night");

        list2.add(ch1_1);
        ExpandListChild ch1_2 = new ExpandListChild();
        ch1_2.setName("Ghayal");
        list2.add(ch1_2);
        ExpandListChild ch1_3 = new ExpandListChild();
        ch1_3.setName("Sigham");
        list2.add(ch1_3);
        gru1.setItems(list2);
        list2 = new ArrayList<ExpandListChild>();

        ExpandListGroup gru2 = new ExpandListGroup();
        gru2.setName("Commmedy");
        ExpandListChild ch2_1 = new ExpandListChild();
        ch2_1.setName("Heraferi");
        list2.add(ch2_1);
        ExpandListChild ch2_2 = new ExpandListChild();
        ch2_2.setName("Chupke Chupke");
        list2.add(ch2_2);
        ExpandListChild ch2_3 = new ExpandListChild();
        ch2_3.setName("HouseFull-2");
        list2.add(ch2_3);
        gru2.setItems(list2);
        list.add(gru1);
        list.add(gru2);

        return list;
    }
}
 

Now we set some default items to a list, load the list to the Adapter, and apply the adapter to the ExpandableListView The finished product of this tutorial will look like this

image

Hope it helps.HaPpY Coding. 🙂