+1-888-365-2779
Try Now
More in this section

Forums / Ecommerce / How to remove ecommerce test order

How to remove ecommerce test order

2 posts, 0 answered
  1. Jason
    Jason avatar
    2 posts
    Registered:
    20 Oct 2014
    10 Jan 2015
    Link to this post
    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.
  2. Atanas Valchev
    Atanas Valchev avatar
    414 posts
    Registered:
    04 Jan 2016
    14 Jan 2015
    Link to this post
    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);
                }
            }

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

    I hope this helps.

    Regards,
    Atanas Valchev
    Telerik
     
    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
     
2 posts, 0 answered