How to remove ecommerce test order - Ecommerce - Ecommerce - Progress Community

How to remove ecommerce test order


How to remove ecommerce test order

  • How to remove ecommerce test order
  • We are using sitefiniy ecommerce development. During the development stage, there are alot of test order data, how to complete delete these test order data(The sitefinity backend only can change the order stage but not really delete)? I noticed we can use orderManager.Provider.DeleteOrder(OrderName),  orderManager.Provider.DeleteCartOrder(OrderName) and etc to remove the data from database. but because i am not sure what data entity will be insert in database that have relation with order, eg. orderDetail, cartOrderDetail, orderAddress, orderdiscount, cartOrderPayment... .... I consider it's a basic need because we want deploy a pure envirement that not include all of these test data to customer. So would you please give me some guide? Thank you so much.
  • Hello,

    Thank you for contacting us.

    You can try the following sample to delete all customers and order:

    /// <summary>
            /// Deletes all orders
            /// </summary>
            public void DeleteAllOrders()
                var manager = OrdersManager.GetManager();
                var orders = manager.GetOrders();
                if (orders.Count() > 0)
                    foreach (Order order in orders)
      /// <summary>
            /// Delete Customers and Orders
            /// </summary>
            public  void DeleteAllCutomersOrders()
                    var manager = OrdersManager.GetManager();
                    var customers = manager.GetCustomers();
                    foreach (Customer customer in customers)
                        var orders = manager.GetOrders().Where(o => o.Customer.Id == customer.Id);
                        foreach (Order order in orders)
                        var customerAddresses = manager.GetCustomerAddresses().Where(a => a.Parent.Id == customer.Id);
                        foreach (CustomerAddress address in customerAddresses)
                        var customerStatistics = manager.GetCustomerStatistics().Where(s => s.Id == customer.StatisticId);
                        foreach (CustomerStatistic statisctic in customerStatistics)
                        var moneysSpent = manager.GetCustomerMoneys().Where(m => m.Parent == customer);
                        foreach (CustomerMoney moneySpent in moneysSpent)
                catch (Exception error)
                    throw new Exception("Orders cannot be deleted", error);

    The Api will take care of any relations and delete everything as required.

    I hope this helps.

    Atanas Valchev
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items