How are Custom Fields added to OrderItems in ViewOrder.aspx?

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
Mike718NY
Commodore (COMO)
Commodore (COMO)
Posts: 485
Joined: Wed Jun 18, 2008 5:24 pm

How are Custom Fields added to OrderItems in ViewOrder.aspx?

Post by Mike718NY » Thu Nov 05, 2009 8:02 am

I want to add a CheckBox to the Order Contents in ViewOrder.aspx (see pic):
How do I update the status of the CheckBox when it has previously been checked?
Last edited by Mike718NY on Sun Nov 08, 2009 1:33 pm, edited 1 time in total.

Mike718NY
Commodore (COMO)
Commodore (COMO)
Posts: 485
Joined: Wed Jun 18, 2008 5:24 pm

Re: How are Custom Fields added to OrderItems in ViewOrder.aspx?

Post by Mike718NY » Sun Nov 08, 2009 1:31 pm

I don't know how to implement the custom fields to tie it to a checkbox.
I added a checkbox to the Grid: <asp:GridView ID="OrderItemGrid" . . .

<asp:CheckBox ID="chkFlagItem" AutoPostBack="true" OnCheckedChanged="chkFlagItem_CheckedChanged" . . .

I update the database, but don't know how to get the CheckBox status set, using the custom field.

Code: Select all

protected void chkFlagItem_CheckedChanged(object sender, EventArgs e)
  {
    CheckBox checkbox = (CheckBox)sender;
    GridViewRow row = (GridViewRow)checkbox.NamingContainer;
    string productId = ((Label)row.FindControl("lblProdId")).Text;

    if (checkbox.Checked)  // not working: always returning true and checked
    {
      string query = "UPDATE ac_OrderItems SET InStock = 1 WHERE ProductId = " + productId + " AND OrderId = " + Request.QueryString["OrderId"];
      Microsoft.Practices.EnterpriseLibrary.Data.Database database = Token.Instance.Database;
      System.Data.Common.DbCommand updateCommand = database.GetSqlStringCommand(query);
      int result = (int)database.ExecuteNonQuery(updateCommand);

      checkbox.Checked = true;   // not working
    }
    else
    {
      string query = "UPDATE ac_OrderItems SET InStock = 0 WHERE ProductId =  . . . 
      ..........
      checkbox.Checked = false;  // not working
    }

  }
Where would I put this and how would it work with the checkbox:

OrderItem myItem;
myItem.CustomFields["YOURCUSTOMFIELDNAME"] = "your custom field data";
myItem.Save();
string myValue = myItem.CustomFields["YOURCUSTOMFIELDNAME"];

Mike718NY
Commodore (COMO)
Commodore (COMO)
Posts: 485
Joined: Wed Jun 18, 2008 5:24 pm

Re: How are Custom Fields added to OrderItems in ViewOrder.aspx?

Post by Mike718NY » Mon Nov 09, 2009 8:12 am

I dont' see a "ac_OrderItemsCustomFields" for order custom fields like there is
for products "ac_ProductCustomFields" in the database? Where are they stored?

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: How are Custom Fields added to OrderItems in ViewOrder.aspx?

Post by mazhar » Mon Nov 09, 2009 8:56 am

custom fields are being stored in ac_OrderItems, see the CustomFields column. These are stored in key value type fashion.

Mike718NY
Commodore (COMO)
Commodore (COMO)
Posts: 485
Joined: Wed Jun 18, 2008 5:24 pm

Re: How are Custom Fields added to OrderItems in ViewOrder.aspx?

Post by Mike718NY » Tue Nov 10, 2009 7:55 am

I was able add a Product Custom Field using Joe's tutorial, but I have no
idea how to add an Order item custom field. Does anybody know?

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: How are Custom Fields added to OrderItems in ViewOrder.aspx?

Post by mazhar » Tue Nov 10, 2009 9:01 am

You need to do something like

Code: Select all

orderItem.CustomFields.Add("custom_field_name", "custom_field_value");

Mike718NY
Commodore (COMO)
Commodore (COMO)
Posts: 485
Joined: Wed Jun 18, 2008 5:24 pm

Re: How are Custom Fields added to OrderItems in ViewOrder.aspx?

Post by Mike718NY » Tue Nov 10, 2009 9:40 am

I added that and got:
"The name 'orderItem' does not exist in the current context"

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: How are Custom Fields added to OrderItems in ViewOrder.aspx?

Post by mazhar » Tue Nov 10, 2009 9:59 am

Word "orderItem" provided in above example was representing the OrderItem class object and provided it to just tell you how you can add custom field. Obviously first you need to load order then iterate over its order items and finally add custom field to desired order item.

Mike718NY
Commodore (COMO)
Commodore (COMO)
Posts: 485
Joined: Wed Jun 18, 2008 5:24 pm

Re: How are Custom Fields added to OrderItems in ViewOrder.aspx?

Post by Mike718NY » Tue Nov 10, 2009 10:48 am

>> Obviously first you need to load order then iterate over its order items and finally . .

I hope it's more obvious that I don't know how to do this.

sfeher
Captain (CAPT)
Captain (CAPT)
Posts: 220
Joined: Fri Jun 04, 2004 1:58 pm
Location: Steubenville, Ohio

Re: How are Custom Fields added to OrderItems in ViewOrder.aspx?

Post by sfeher » Fri Dec 30, 2011 12:43 pm

Mazhar -
Look for some sample code on allowing a custom field to appear on the ViewOrder.aspx page.

These links above aren't helping me enough, I'm afraid.
I have a field named "BundleQTY" and I need to display the value in that field that corresponds with each item in the order after checkout.

I'm unsure how to correctly call this value in the codebehind page to adequately display the field value in the .aspx page.
Any help would be greatly appreciated!

Post Reply