AI agents: the content index is at /llms.txt. Every page is also available as Markdown — send the request header Accept: text/markdown, or append .md to the page URL.
Xperience Docs

Cookie consent

We use necessary cookies (opens in a new tab) to run our website and improve your experience while browsing. Additional cookies are only used with your consent. You may revoke your consent on the Cookies Policy (opens in a new tab) page or in your browser at any time.

Configure (opens in a new tab)
  • Documentation
    InstallationUsing the Xperience interfaceDeveloping websitesConfiguring XperienceManaging usersSecuring websitesDeploying websitesManaging website contentMultilingual websitesMacro expressionsExternal utilitiesIntegrating 3rd party systemsCustom developmentE-commerce featuresOn-line marketing featuresRelease notes - Xperience 13Xperience terminology glossary
  • Tutorial
    Using the Xperience interfaceDeveloper tutorialBusiness tutorialResource hub for marketers
  • API Examples
    ConfigurationContent managementDevelopmentE-commerceOn-line marketingSocial media
  1. Home
  2. E-commerce
  3. Orders

Orders


Was this page helpful?

Send us feedback Go back to top
  • Community Questions & Answers (opens in a new tab)
  • Contact support (opens in a new tab)

List of examples:

  • Orders
    • Creating a new order
    • Updating an order
    • Updating multiple orders
    • Deleting an order
  • Order items
    • Creating an order item
    • Updating an order item
    • Updating multiple order items
    • Deleting an order item
  • Order statuses
    • Creating an order status
    • Updating an order status
    • Updating multiple order statuses
    • Deleting an order status
    • Changing an order's status to the next enabled order status
    • Deleting the status history of an order
  • Invoices
    • Updating an invoice

Orders

Creating a new order

C#
// Gets the first customer whose last name is 'Smith'
CustomerInfo customer = CustomerInfo.Provider.Get()
                                            .WhereEquals("CustomerLastName", "Smith")
                                            .TopN(1)
                                            .FirstOrDefault();

// Gets a status for the order
OrderStatusInfo orderStatus = OrderStatusInfo.Provider.Get("NewStatus", SiteContext.CurrentSiteID);

// Gets a currency for the order
CurrencyInfo currency = CurrencyInfo.Provider.Get("NewCurrency", SiteContext.CurrentSiteID);

// Gets the customer's address
AddressInfo customerAddress = AddressInfo.Provider.Get()
                                                    .WhereEquals("AddressCustomerID", customer.CustomerID)
                                                    .TopN(1)
                                                    .FirstOrDefault();

if ((customer != null) && (orderStatus != null) && (currency != null) && (customerAddress != null))
{
    // Creates a new order object and sets its properties
    OrderInfo newOrder = new OrderInfo
    {
        OrderInvoiceNumber = "1",
        OrderTotalPrice = 200,
        OrderGrandTotal = 200,
        OrderTotalTax = 30,
        OrderDate = DateTime.Now,
        OrderStatusID = orderStatus.StatusID,
        OrderCustomerID = customer.CustomerID,
        OrderSiteID = SiteContext.CurrentSiteID,
        OrderCurrencyID = currency.CurrencyID
    };

    // Saves the order to the database
    OrderInfo.Provider.Set(newOrder);

    var addressConverter = Service.Resolve<IAddressConverter>();

    // Prepares the order addresses from the customer's address
    OrderAddressInfo orderBillingAddress = addressConverter.Convert(customerAddress, newOrder.OrderID, AddressType.Billing);
    OrderAddressInfo orderShippingAddress = addressConverter.Convert(customerAddress, newOrder.OrderID, AddressType.Shipping);

    // Sets the order addresses
    OrderAddressInfo.Provider.Set(orderBillingAddress);
    OrderAddressInfo.Provider.Set(orderShippingAddress);
}
> Back to list of examples

Updating an order

C#
// Gets the first customer whose last name is 'Smith'
CustomerInfo customer = CustomerInfo.Provider.Get()
                                            .WhereEquals("CustomerLastName", "Smith")
                                            .TopN(1)
                                            .FirstOrDefault();

if (customer != null)
{
    // Gets the customer's first order
    OrderInfo order = OrderInfo.Provider.Get()
                                    .WhereEquals("OrderCustomerID", customer.CustomerID)
                                    .TopN(1)
                                    .FirstOrDefault();
    if (order != null)
    {
        // Updates the price of the order
        order.OrderTotalPrice = order.OrderTotalPrice + 200;
        order.OrderGrandTotal = order.OrderGrandTotal + 200;

        // Saves the changes to the database
        OrderInfo.Provider.Set(order);
    }
}
> Back to list of examples

Updating multiple orders

C#
// Gets the first customer whose last name is 'Smith'
CustomerInfo customer = CustomerInfo.Provider.Get()
                                            .WhereEquals("CustomerLastName", "Smith")
                                            .TopN(1)
                                            .FirstOrDefault();

if (customer != null)
{
    // Gets the customer's orders
    var orders = OrderInfo.Provider.Get().WhereEquals("OrderCustomerID", customer.CustomerID);

    // Loops through the customer's orders
    foreach (OrderInfo order in orders)
    {
        // Updates the price of the order
        order.OrderTotalPrice = order.OrderTotalPrice + 200;
        order.OrderGrandTotal = order.OrderGrandTotal + 200;

        // Saves the changes to the database
        OrderInfo.Provider.Set(order);
    }
}
> Back to list of examples

Deleting an order

C#
// Gets the first customer whose last name is 'Smith'
CustomerInfo customer = CustomerInfo.Provider.Get()
                                            .WhereEquals("CustomerLastName", "Smith")
                                            .TopN(1)
                                            .FirstOrDefault();

if (customer != null)
{
    // Gets the customer's order
    OrderInfo order = OrderInfo.Provider.Get()
                                    .WhereEquals("OrderCustomerID", customer.CustomerID)
                                    .TopN(1)
                                    .FirstOrDefault();
    if (order != null)
    {
        // Deletes the order
        OrderInfo.Provider.Delete(order);
    }
}
> Back to list of examples

Order items

Creating an order item

C#
// Gets the 'NewProduct' product
SKUInfo product = SKUInfo.Provider.Get()
                   .WhereEquals("SKUName", "NewProduct")
                   .TopN(1)
                   .FirstOrDefault();

// Gets the first customer whose last name is 'Smith'
CustomerInfo customer = CustomerInfo.Provider.Get()
                                            .WhereEquals("CustomerLastName", "Smith")
                                            .TopN(1)
                                            .FirstOrDefault();

if (customer != null)
{
    // Gets the customer's first order
    OrderInfo order = OrderInfo.Provider.Get()
                                            .WhereEquals("OrderCustomerID", customer.CustomerID)
                                            .TopN(1)
                                            .FirstOrDefault();

    if ((order != null) && (product != null))
    {
        // Creates a new order item object and sets its properties
        OrderItemInfo newItem = new OrderItemInfo
        {
            OrderItemSKUName = "NewProduct",
            OrderItemOrderID = order.OrderID,
            OrderItemSKUID = product.SKUID,
            OrderItemUnitPrice = 200,
            OrderItemUnitCount = 1
        };

        // Saves the order item object to the database
        OrderItemInfo.Provider.Set(newItem);
    }
}
> Back to list of examples

Updating an order item

C#
// Gets the first customer whose last name is 'Smith'
CustomerInfo customer = CustomerInfo.Provider.Get()
                                            .WhereEquals("CustomerLastName", "Smith")
                                            .TopN(1)
                                            .FirstOrDefault();

if (customer != null)
{
    // Gets the customer's first order
    OrderInfo order = OrderInfo.Provider.Get()
                                            .WhereEquals("OrderCustomerID", customer.CustomerID)
                                            .TopN(1)
                                            .FirstOrDefault();

    if (order != null)
    {
        // Gets the first item in the order
        OrderItemInfo orderItem = OrderItemInfoProvider.GetOrderItems(order.OrderID).FirstOrDefault();
        if (orderItem != null)
        {
            // Updates the order item's SKU name
            orderItem.OrderItemSKUName = orderItem.OrderItemSKUName.ToLowerCSafe();

            // Saves the changes to the database
            OrderItemInfo.Provider.Set(orderItem);
        }
    }
}
> Back to list of examples

Updating multiple order items

C#
// Gets the first customer whose last name is 'Smith'
CustomerInfo customer = CustomerInfo.Provider.Get()
                                            .WhereEquals("CustomerLastName", "Smith")
                                            .TopN(1)
                                            .FirstOrDefault();

if (customer != null)
{
    // Gets the customer's first order
    OrderInfo order = OrderInfo.Provider.Get()
                                            .WhereEquals("OrderCustomerID", customer.CustomerID)
                                            .TopN(1)
                                            .FirstOrDefault();

    if (order != null)
    {
        // Gets all items in the given order
        var orderItems = OrderItemInfoProvider.GetOrderItems(order.OrderID);

        // Loops through the order items
        foreach (OrderItemInfo orderItem in orderItems)
        {
            // Updates the order item's SKU name
            orderItem.OrderItemSKUName = orderItem.OrderItemSKUName.ToUpperCSafe();

            // Saves the order item to the database
            OrderItemInfo.Provider.Set(orderItem);
        }
    }
}
> Back to list of examples

Deleting an order item

C#
// Gets the first customer whose last name is 'Smith'
CustomerInfo customer = CustomerInfo.Provider.Get()
                                            .WhereEquals("CustomerLastName", "Smith")
                                            .TopN(1)
                                            .FirstOrDefault();

if (customer != null)
{
    // Gets the customer's first order
    OrderInfo order = OrderInfo.Provider.Get()
                                            .WhereEquals("OrderCustomerID", customer.CustomerID)
                                            .TopN(1)
                                            .FirstOrDefault();

    if (order != null)
    {
        // Gets the first item from the order
        OrderItemInfo orderItem = OrderItemInfoProvider.GetOrderItems(order.OrderID).FirstOrDefault();
        if (orderItem != null)
        {
            // Deletes the order item
            OrderItemInfo.Provider.Delete(orderItem);
        }
    }
}
> Back to list of examples

Order statuses

Creating an order status

C#
// Creates a new order status object
OrderStatusInfo newStatus = new OrderStatusInfo();

// Sets the order status properties
newStatus.StatusDisplayName = "New status";
newStatus.StatusName = "NewStatus";
newStatus.StatusEnabled = true;
newStatus.StatusSiteID = SiteContext.CurrentSiteID;
newStatus.StatusOrder = 1;

// Saves the order status to the database
OrderStatusInfo.Provider.Set(newStatus);
> Back to list of examples

Updating an order status

C#
// Gets the order status
OrderStatusInfo updateStatus = OrderStatusInfo.Provider.Get("NewStatus", SiteContext.CurrentSiteID);
if (updateStatus != null)
{
    // Updates the display name of the order status
    updateStatus.StatusDisplayName = updateStatus.StatusDisplayName.ToLowerCSafe();

    // Saves the changes to the database
    OrderStatusInfo.Provider.Set(updateStatus);
}
> Back to list of examples

Updating multiple order statuses

C#
// Gets all order statuses on the current site whose code name starts with 'NewStatus'
var statuses = OrderStatusInfo.Provider.Get()
                                        .OnSite(SiteContext.CurrentSiteID)
                                        .WhereStartsWith("StatusName", "NewStatus");

// Loops through the order statuses
foreach (OrderStatusInfo modifyStatus in statuses)
{
    // Updates the display name of the order status
    modifyStatus.StatusDisplayName = modifyStatus.StatusDisplayName.ToUpperCSafe();

    // Saves the changes to the database
    OrderStatusInfo.Provider.Set(modifyStatus);
}
> Back to list of examples

Deleting an order status

C#
// Gets the order status
OrderStatusInfo deleteStatus = OrderStatusInfo.Provider.Get("NewStatus", SiteContext.CurrentSiteID);

if (deleteStatus != null)
{
    // Deletes the order status
    OrderStatusInfo.Provider.Delete(deleteStatus);
}
> Back to list of examples

Changing an order's status to the next enabled order status

C#
// Gets the first customer whose last name is 'Smith'
CustomerInfo customer = CustomerInfo.Provider.Get()
                                            .WhereEquals("CustomerLastName", "Smith")
                                            .TopN(1)
                                            .FirstOrDefault();

if (customer != null)
{
    // Gets the customer's first order
    OrderInfo order = OrderInfo.Provider.Get()
                                            .WhereEquals("OrderCustomerID", customer.CustomerID)
                                            .TopN(1)
                                            .FirstOrDefault();

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

        if (nextOrderStatus != null)
        {
            // Creates a new object representing an order status change (performed by a specific user)
            OrderStatusUserInfo orderStatusChange = new OrderStatusUserInfo()
            {
                OrderID = order.OrderID,
                ChangedByUserID = MembershipContext.AuthenticatedUser.UserID,
                FromStatusID = order.OrderStatusID,
                ToStatusID = nextOrderStatus.StatusID,
                Date = DateTime.Now
            };

            // Saves the status change to the order's history
            OrderStatusUserInfo.Provider.Set(orderStatusChange);

            // Assigns the new order status to the order
            order.OrderStatusID = nextOrderStatus.StatusID;

            // Saves the updated order to the database
            OrderInfo.Provider.Set(order);
        }
    }
}
> Back to list of examples

Deleting the status history of an order

C#
// Gets the first customer whose last name is 'Smith'
CustomerInfo customer = CustomerInfo.Provider.Get()
                                            .WhereEquals("CustomerLastName", "Smith")
                                            .TopN(1)
                                            .FirstOrDefault();

if (customer != null)
{
    // Gets the customer's first order
    OrderInfo order = OrderInfo.Provider.Get()
                                            .WhereEquals("OrderCustomerID", customer.CustomerID)
                                            .TopN(1)
                                            .FirstOrDefault();

    if (order != null)
    {
        // Gets the order status changes in the order's history
        var statuses = OrderStatusUserInfoProvider.GetOrderStatusHistory(order.OrderID);

        // Loops through the order status changes
        foreach (OrderStatusUserInfo status in statuses)
        {
            // Deletes the order status changes
            OrderStatusUserInfo.Provider.Delete(status);
        }
    }
}
> Back to list of examples

Invoices

Updating an invoice

C#
// Gets the current site name
string siteName = SiteContext.CurrentSiteName;

// Gets the current site's invoice template
string invoice = ECommerceSettings.InvoiceTemplate(siteName);

if (!String.IsNullOrEmpty(invoice))
{
    // Prepares a new string with the invoice text
    invoice = "<h1>Updated invoice</h1>" + invoice;

    // Saves the invoice changes to the database
    SettingsKeyInfoProvider.SetValue(ECommerceSettings.INVOICE_TEMPLATE, siteName, invoice);
}
> Back to list of examples