How to add new products on Homepage in Magento

March 24, 2013 1 comment

I is really difficult to learn Magento, after making it login the next step is how to create products and display it on homepage

Sudar60 posted a good article on this here: http://www.magentomela.com/blog/new-products-on-homepage-in-magento/

However, there are two more thing you need to check to  make sure the product is able to display on homepage

1) Make sure that Catalog > Manage products > Select a product > Inventory > Stock Availability is always In Stock (remeber to input value for Qty* item)

2) In the CMS > Pages > Home page > Page Information > Design > Layout Update XML: make sure to uncomment the XML source before processing

Categories: Magento

.NET free browser-based IDE

December 8, 2009 1 comment

Have you ever experienced a ASP.NET browser-based IDE? i found this site that supports this great function while browsing around the Internet. Of course it still has some limitation but i think i would be a convenience in some case to repair ASP.NET code without Visual Studio setup.

Categories: ASP.NET

Date handle functions in Java

September 24, 2009 1 comment

I showed a small function about how to get a day of week based on the inputted date in my previous article. But there are still some more functions related to Date that i usually have to deal with, so i also want to share them here

1. Plus a date and a year

public static Date addYear(Date date, int value) {
        GregorianCalendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.add(Calendar.YEAR, value);

        return calendar.getTime();
}

2. Plus a date and a month

public static Date addMonth(Date date, int value) {
        GregorianCalendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.add(Calendar.MONTH, value);

        return calendar.getTime();
}

3. Plus a date and a day

public static Date addDay(Date date, int value) {
        GregorianCalendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.add(Calendar.DAY_OF_MONTH, value);

        return calendar.getTime();
}

4. Plus a date and minute

public static Date addMinute(Date date, int value) {
        GregorianCalendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.add(Calendar.MINUTE, value);

        return calendar.getTime();
}

5. Calculate years old

// bornDate is a date string based on [yyyyMMdd] format
public static String calAge(String bornDate) throws Exception {
        // If the input date is null
        if (bornDate == null || bornDate.length() == 0) {
            bornDate = "00000000";
        }

        Calendar cal = new GregorianCalendar(new Integer(bornDate.substring(0, 4)), 
                                             new Integer(bornDate.substring(4, 6)) - 1, 
                                             new Integer(bornDate.substring(6, 8)));
        
        Calendar now = new GregorianCalendar();
        
        int age = now.get(Calendar.YEAR) - cal.get(Calendar.YEAR);
        
        if(cal.get(Calendar.MONTH) > now.get(Calendar.MONTH)
          || (cal.get(Calendar.MONTH) == now.get(Calendar.MONTH)
          && cal.get(Calendar.DAY_OF_MONTH) > now.get(Calendar.DAY_OF_MONTH))) {
            age--;
        }

        return age + " years old";
}

6. Get first day of week

public static Date getFirstDayOfWeek(Date date) {
        GregorianCalendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.set(
                Calendar.DAY_OF_WEEK,
                calendar.getActualMinimum(Calendar.DAY_OF_WEEK));

        return calendar.getTime();
}

7. Get day of week

 public static int getDayOfWeek(Date date) {
        GregorianCalendar calendar = new GregorianCalendar();
        calendar.setTime(date);

        return calendar.get(Calendar.DAY_OF_WEEK);
}

8. Get first day of month

public static Date getFirstDayOfMonth(Date date) {
        GregorianCalendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.set(
                Calendar.DAY_OF_MONTH,
                calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
        
        return calendar.getTime();
}

9. Get last day of month

public static Date getLastDayOfMonth(Date date) {
        GregorianCalendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.set(
                Calendar.DAY_OF_MONTH,
                calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
        
        return calendar.getTime();
}
Categories: Java Tags: ,

Calculate day of week

September 23, 2009 2 comments

Below is a small java program used to calculate which day in week a date is based on the input date. This function is implemented without using any function of Date library.

public class Cal {
public static void main (String args[]) {
int y = 2009;
int m = 9;
int d = 20;

int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};

y -= ((m < 3) ? 1 : 0);

System.out.println("Result:" +(y + y/4 - y/100 + y/400 + t[m-1] + d) % 7);
}
}

The output result’ll be a number from [0] to [6] that is corresponding to [Sunday] ~ [Saturday] in a week

Categories: Java Tags:

Currency TextInput

August 29, 2009 2 comments

In my project, i needed to create some action as below for TextInput:

  • Focus Out: Automatically format the inputted value as currency
  • Focus In: Remove all currency characters and display as normal Number
  • Text attribute: always return as normal number characters string (Without [,]  and [$])

One more requirement is that, it must be a components for later use.
currency

I think it’s enough introduction. Actually, this can be done easily by creating a class that extends TextInput class. I also override focusOutHandler() and focusInHandler() to process the display data as i want before showing it on TextInput. The last thing is Text property,  because i must use CurrencyFormatter to format data each time the focus is out, so if user call the Text attribute, the result which user can receive is a formatted string and cannot insert into a number column in database. To do that, i must remove all [,] and [$] out of the string.

Here is my source:

package components {

import flash.events.FocusEvent;
import mx.controls.TextInput;
import mx.formatters.CurrencyFormatter;

/**
*  Currency TextInput component
*
*/
public class CurrencyTextInput extends TextInput {

private var reg:RegExp = /[,$]/g;
private var formatter:CurrencyFormatter = null;

override public function get text():String {
return super.text.replace(reg, "");
}

/**
* Constructor
*/
public function CurrencyTextInput() {
// create new formatter
formatter = new CurrencyFormatter();
// set defafult currency symbol
formatter.currencySymbol = "$";
}

/**
* Format data before lost focus event happen
*
* @param    event
*/
override protected function focusOutHandler(event:FocusEvent):void {
text = formatter.format(text);

super.focusOutHandler(event);
}

/**
* Flush out [,] and [$] characters
* before getting focus
*
* @param    event
*/
override protected function focusInHandler(event:FocusEvent):void {

text = text.replace(reg, "");

super.focusInHandler(event);
}
}
}

And then, how to use it in mxml

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:custom="components.*">
<custom:CurrencyTextInput id="unit_price" width = "150"/>
</mx:Application>

This is still simple but you can add other attributes to allow user to control the format pattern more easily.

Hope this help!

Categories: Adobe Flex/Air Tags:

Get selected cell value of DataGrid in FLex

August 26, 2009 6 comments

In the DataGrid control of Flex, it doesn’t support any property related to the selected column index so we cannot get its value directly. Instead, we have to use other way. DataGrid supports events called [ItemClick] or [ItemDoubleClick], when using these events, we can retrieve the column index of the clicked item.

To demonstrate this action, i created an sample that includes a DataGrid and a PopupWindow. When user click on an item of DataGrid, it’ll get the selected column value and display on the PopupWindow. (the two forms must be put at the same directory)

The first is MainForm.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Script>
<![CDATA[
import flash.events.Event;
import mx.controls.DataGrid;
import mx.events.ListEvent;
import mx.collections.ArrayCollection;
import mx.containers.TitleWindow;
import mx.events.DataGridEvent;
import mx.managers.PopUpManager;
import PopupForm;</code>

[Bindable]
private var dgArrayCollection:ArrayCollection =
new ArrayCollection([
{id:'1', name:'John'},
{id:'2', name:'Alex'},
{id:'3', name:'Peter'},
{id:'4', name:'Sam'},
{id:'5', name:'Alis'},
{id:'6', name:'Robin'},
{id:'7', name:'Mark'},
{id:'8', name:'Steave'},
{id:'9', name:'Fill'},
{id:'10', name:'Abraham'},
{id:'11', name:'Hennery'},
{id:'12', name:'Luis'},
{id:'13', name:'Herry'},
{id:'14', name:'Markus'},
{id:'15', name:'Flip'}
]);

private var newPopUp:PopupForm;

private function showPopUp(event:ListEvent):void {
var newPopUp:PopupForm = PopupForm(PopUpManager.createPopUp(this, PopupForm, true));

// Get the target of this event (Datagrid)
var dataGrid:DataGrid = event.target as DataGrid;
// Get selected column index
var dsColumnIndex:Number = event.columnIndex;
// based on the selected column index
// Get the DataGridColumn object to get the selected column name
var col:DataGridColumn = dataGrid.columns[dsColumnIndex];
// Get selected cell value from the selected row and column name
var newValue:String = dataGrid.selectedItem[col.dataField];

newPopUp.txtFromOutSide = newValue;

PopUpManager.centerPopUp(newPopUp);
}
]]>
</mx:Script>
<mx:VBox width="300" height="100%" horizontalAlign="center" verticalAlign="middle">
<mx:DataGrid id="dg" width="50%" height="100%" borderStyle="none"
dataProvider="{dgArrayCollection}" doubleClickEnabled="true" itemDoubleClick="showPopUp(event)" >
<mx:columns>
<mx:DataGridColumn dataField="id" headerText="ID"/>
<mx:DataGridColumn dataField="name" headerText="Name"/>
</mx:columns>
</mx:DataGrid>
</mx:VBox>
</mx:Application>

The second form is PopupForm.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml"
width="200" height="150" borderStyle="solid"
borderColor="0xCCCCCC" cornerRadius="5">

<mx:Script>
<![CDATA[
import mx.managers.PopUpManager;

[Bindable]
public var txtFromOutSide: String;

private function onClose():void {
PopUpManager.removePopUp(this);
}

]]>

</mx:Script>

<mx:VBox width="100%" horizontalAlign="center" verticalAlign="middle">
<mx:Label id="lbl" text="{txtFromOutSide}" textAlign="center"/>
<mx:Button label="OK" click="onClose()"/>
</mx:VBox>
</mx:TitleWindow>

Hope this help!

Categories: Adobe Flex/Air Tags: