Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Update System table - OrderStatusUser table View modes: 
User avatar
Member
Member
Sonam.Marda-bitwiseglobal - 1/7/2014 1:39:51 AM
   
Update System table - OrderStatusUser table
I am using Kentico's inbuilt shopping cart module. I have integrated third party payment tool with it. After successful payment, I want to access data from OrderStatus system table and change the ToStatusId column in OrderStatusUser system table.
So please tell me how to access and update data of system table?? I am creating an inline control for this.

Thanks.

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 1/7/2014 7:59:08 AM
   
RE:Update System table - OrderStatusUser table
I'm a little confused here. You want to update the Order's status or the actual Statuses used by an order?

Here are some samples, I got out of the CMSAPIExamples that is typically installed with your Kentico installation.

Update a Status used by an order.
private bool GetAndUpdateOrderStatus()
{
// Get the order status
OrderStatusInfo updateStatus = OrderStatusInfoProvider.GetOrderStatusInfo("MyNewStatus", CMSContext.CurrentSiteName);
if (updateStatus != null)
{
// Update the properties
updateStatus.StatusDisplayName = updateStatus.StatusDisplayName.ToLowerCSafe();

// Update the order status
OrderStatusInfoProvider.SetOrderStatusInfo(updateStatus);

return true;
}

return false;
}

Update an Order's status
private bool ChangeOrderStatus()
{
// Prepare the parameters
string where = "CustomerLastName LIKE N'My New Registered%'";
CustomerInfo customer = null;
OrderInfo order = null;

// Get the customer
DataSet customers = CustomerInfoProvider.GetCustomers(where, null);
if (!DataHelper.DataSourceIsEmpty(customers))
{
// Create object from DataRow
customer = new CustomerInfo(customers.Tables[0].Rows[0]);
}

if (customer != null)
{
string whereOrder = "OrderCustomerID = " + customer.CustomerID;

// Get the order
DataSet orders = OrderInfoProvider.GetOrders(whereOrder, null);
if (!DataHelper.DataSourceIsEmpty(orders))
{
// Create object from DataRow
order = new OrderInfo(orders.Tables[0].Rows[0]);
}

if (order != null)
{
// Get next enabled order status
OrderStatusInfo nextOrderStatus = OrderStatusInfoProvider.GetNextEnabledStatus(order.OrderStatusID);

if (nextOrderStatus != null)
{
// Create new order status user object
OrderStatusUserInfo newUserStatus = new OrderStatusUserInfo();

// Set the properties
newUserStatus.OrderID = order.OrderID;
newUserStatus.ChangedByUserID = CMSContext.CurrentUser.UserID;
newUserStatus.FromStatusID = order.OrderStatusID;
newUserStatus.ToStatusID = nextOrderStatus.StatusID;
newUserStatus.Date = DateTime.Now;

// Set the order status user
OrderStatusUserInfoProvider.SetOrderStatusUserInfo(newUserStatus);

// Set next order status to order
order.OrderStatusID = nextOrderStatus.StatusID;

// Change the order status
OrderInfoProvider.SetOrderInfo(order);

return true;
}
}
}

return false;
}

User avatar
Certified Developer 13
Certified Developer 13
kentico_josefd - 1/8/2014 6:12:40 AM
   
RE:Update System table - OrderStatusUser table
Hello,

This is the solution we would recommend. It is not a good practice to update database columns directly in, as they may be cached by Kentico, leading to data inconsistency. Using API is the best way.

If this is not what you are looking for, let us know more details about what are you trying to do achieve and we will try to assist further.

On a side note, this section of the code:

// Create new order status user object
OrderStatusUserInfo newUserStatus = new OrderStatusUserInfo();

// Set the properties
newUserStatus.OrderID = order.OrderID;
newUserStatus.ChangedByUserID = CMSContext.CurrentUser.UserID;
newUserStatus.FromStatusID = order.OrderStatusID;
newUserStatus.ToStatusID = nextOrderStatus.StatusID;
newUserStatus.Date = DateTime.Now;

// Set the order status user
OrderStatusUserInfoProvider.SetOrderStatusUserInfo(newUserStatus);


Is not necessary if you do not need to set specific ChangedByUser information and is in the API examples for demonstration purposes. CurrentUser will always be shown in the Order Status History.

Regards,
Josef Dvorak