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) manager.DeleteOrder(order.Id); manager.SaveChanges(); /// <summary> /// Delete Customers and Orders /// </summary> public void DeleteAllCutomersOrders() try 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) manager.DeleteOrder(order); manager.Provider.DeleteOrder(order); manager.SaveChanges(); var customerAddresses = manager.GetCustomerAddresses().Where(a => a.Parent.Id == customer.Id); foreach (CustomerAddress address in customerAddresses) manager.DeleteCustomerAddress(address); var customerStatistics = manager.GetCustomerStatistics().Where(s => s.Id == customer.StatisticId); foreach (CustomerStatistic statisctic in customerStatistics) manager.DeleteCustomerStatistic(statisctic); var moneysSpent = manager.GetCustomerMoneys().Where(m => m.Parent == customer); foreach (CustomerMoney moneySpent in moneysSpent) manager.DeleteCustomerMoney(moneySpent); manager.DeleteCustomer(customer); manager.SaveChanges(); catch (Exception error) throw new Exception("Orders cannot be deleted", error);