Page 1 of 1

Marking Products private (Off the site) after OrderPaid

Posted: Wed Jun 23, 2010 6:38 pm
by MMIKAL
We carry unique products, so we need to take the product OFF the site after an order is placed and paid.
(We set the Status trigger to De-Stock after order is paid and the Instock to 1 for every product and allow backorder is Off.)

What would be the best way to do that ?

We have created a database INSERT trigger on the orderItems table, so when a product is inserted in the orderItems table, the trigger will go and mark the product in Products table Private. It works fine, but most of the times it somehow empties the basket/Cart and when the customer wants to check out it shows "your cart is empty". We could not see the relationship.



Appriciate any help.

Re: Marking Products private (Off the site) after OrderPaid

Posted: Thu Jun 24, 2010 4:31 am
by mazhar
Instead of writing database trigger, put some code to handle this. In your ConLib/OnePageCheckout .acx.cs file locate CheckedOut event handler then place following code block just above the closing brace of IF block in this function.

Code: Select all

Order order = OrderDataSource.Load(e.OrderId, false);
            if (order.OrderStatus.Name == "Paid")
            {
                foreach (OrderItem orderItem in order.Items)
                {
                    if (orderItem.OrderItemType == OrderItemType.Product && orderItem.Product != null)
                    {
                        orderItem.Product.Visibility = CommerceBuilder.Catalog.CatalogVisibility.Private;
                        orderItem.Product.Save();
                    }
                }
            }
Where replace the word Paid with name of your desired order status for which you want to hide the products.