in

dashCommerce

An ASP.NET Open Source e-Commerce Application

Reformat Order Number

Last post 06-16-2008 9:31 AM by admin. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 06-13-2008 11:29 AM

    • oyoon
    • Top 25 Contributor
    • Joined on 03-22-2008
    • Posts 33

    Reformat Order Number

    Hi,

    Order number format is a bit difficult for non English speaking shoppers. I'd like to change the format to one such as '080614-00001' etc. How can I achive this?

     

    Thanks

  • 06-13-2008 2:46 PM In reply to

    Re: Reformat Order Number

    Core.CoreUtility.GenerateRandomString is where the current version is. Good points on the non english speakers - we'll change this to a numeric string as you suggest.

    Submit a patch if you get to it before us. Big Smile

    --
    Support dashCommerce - Buy Our Stuff!!


    Find a bug? Create a Work Item for a fast response.. Want to help? Create a patch for us! Documentation? Help us write some!
  • 06-16-2008 9:08 AM In reply to

    • oyoon
    • Top 25 Contributor
    • Joined on 03-22-2008
    • Posts 33

    Re: Reformat Order Number

    I don't know much about how to call stored procedures from dc and used a typical database call.

    1. create a config table

        configKey : varchar(50);

        configValue: varchar(50)

          configKey                                         configValue

       'MaxOrderNumberLength'                            11

        'lastordernumber'                                        0

    2. create a stored procedure

    CREATE proc [dbo].[dashCommerce_Store_FetchNextOrderNumber] @strNextOrderNumber varchar(50) OUT

    AS

    BEGIN

    -- Declare the return variable here

    DECLARE @Result varchar(101) -- inlcuding 50 zeros at max plus '-'.

    DECLARE @intLength int

     

    SELECT @intLength = CAST(configValue as int) -- get a Length of order number.

    FROM dbo.dashCommerce_Store_Config WHERE configKey = 'MaxOrderNumberLength'

    if @intLength <11 -- must be equal to or longer than 11

    SET @intLength = 11;

     

    if @intLength > 50 -- must be less than or equal to 50.

    SET @intLength = 50;

    Declare @intOrderNumber int

     

    SELECT @intOrderNumber = CAST( ConfigValue AS int) + 1 -- get the last order number used and add one to it

    FROM dbo.dashCommerce_Store_Config

    WHERE ConfigKey = 'lastordernumber';

     

    -- Make the integer order number to string.

    SET @strNextOrderNumber = Cast(@intOrderNumber AS varchar(50))

    -- 7 means the length of 'YYMMDD-' which is a prefix of order numbers. eg. 080616-00000001

    IF LEN(@strNextOrderNumber ) >= @intLength -7 -- if meaningful number length is longer than exprected, then do not remoev any.

    SELECT @Result = @strNextOrderNumber;

    ELSE

    BEGIN

    SELECT @Result = '0000000000000000000000000000000000000000000000000' + RTRIM(@strNextOrderNumber);

     

    SELECT @Result = Right (@Result, @intLength -7);

     

    END

    SELECT @Result = convert(varchar(6), getdate(), 12 ) + '-' + @Result;

     

    -- SET the last order number back to config table.

    UPDATE dbo.dashCommerce_Store_Config SET ConfigValue = @strNextOrderNumber

    WHERE ConfigKey = 'lastordernumber';

    SELECT @strNextOrderNumber = LEFT(@Result, 50) -- RETURN only first 50.

     

    END

    3. Modify the core.coreUtility.GenerateRandomString()

    public static string GenerateRandomString(int length)

    {

    //order number will be "YYMMDD-000123456"; //some shoppers just add some to a cart and left. But still looks good because the number keeps increased 

    // for instance, 080616-00101  seems to be looking better than just 080616-00002 with one purchase in a day. 

    string nextOrderNumber = "";

    SqlConnection con;

    SqlCommand cmd;

     

    try

    {

    string strConnectionString = "Server=localhost;Initial Catalog=csk3r;User Id=xxxxx;Password=xxxxxx;";con = new SqlConnection(strConnectionString);

    con.Open();

    cmd = new SqlCommand("[dbo].[dashCommerce_Store_FetchNextOrderNumber]", con);

    cmd.CommandType = CommandType.StoredProcedure;SqlParameter prm = new SqlParameter("@strNextOrderNumber", SqlDbType.VarChar);

    prm.Size=50;

    prm.Direction =
    ParameterDirection.Output;

    cmd.Parameters.Add (prm);

    cmd.ExecuteNonQuery();

    nextOrderNumber = cmd.Parameters[
    "@strNextOrderNumber"].Value.ToString();

     

    return nextOrderNumber;

    }

    catch (Exception e)

    {

    throw;

    }

    finally

    {

     

    cmd =
    null;con = null;

     

    }

    }

     

     

  • 06-16-2008 9:31 AM In reply to

    Re: Reformat Order Number

    In the 3.0.1 Release there is a new procedure in CoreUtility to generate a 4X4 numeric OrderNumber, so it will look like XXXX-XXXX-XXXX-XXXX.

    Hope this helps.

    --
    Support dashCommerce - Buy Our Stuff!!


    Find a bug? Create a Work Item for a fast response.. Want to help? Create a patch for us! Documentation? Help us write some!
    Filed under:
Page 1 of 1 (4 items)