Dynamicweb 8 Documentation
Delete() Method
Example 

Deletes order line from DB
Syntax
'Declaration
 
Public Overloads Sub Delete() 
public void Delete()
Example
Removes all orderlines that is of type Product and that no longer exist in the database. Also removes products according to the control panel settings: Active, on stock, price is zero.
class MyPage : System.Web.UI.Page
{
    private Order order;
 
    public void RemoveNoneActiveProducts()
    {

        	//HACK: This prevents dbProduct.Price.Price below to call this method and create an endless loop
        	if (order.IsCart)
        	{
        		Context.SetCart(order);
        	}

        	bool doCheckStock = Base.ChkBoolean(Base.GetGs("/Globalsettings/Ecom/Product/DontShowProductIfNotOnStock"));
        	bool doCheckPrice = Base.ChkBoolean(Base.GetGs("/Globalsettings/Ecom/Product/DontShowProductIfHasNoPrice"));

        	//First build a list of ID's of the products to get from the database
        	List<string> ids = new List<string>();
        	List<OrderLine> productLines = new List<OrderLine>();
        	foreach (OrderLine orderLine in order.OrderLines)
        	{
        		if (orderLine.Type == Base.ChkString(Base.ChkInteger(orderLine.OrderLineType.Product)))
        		{
        			ids.Add(orderLine.Product.ID);
        			productLines.Add(orderLine);
        		}
        	}

        	//Get the products that match the ids
        	ProductCollection productsFromDatabase = Product.getProducts(ids.ToArray(), false);

        	//Remove the products that don't exist or is not active
        	foreach (OrderLine productLine in productLines)
        	{
        		bool doRemove = true;
        		Product product = productLine.Product;
        		foreach (Product dbProduct in productsFromDatabase)
        		{
        			if (product.ID == dbProduct.ID && product.VariantID == dbProduct.VariantID && product.LanguageID == dbProduct.LanguageID)
        			{
        				if (dbProduct.Active)
        				{
        					doRemove = false;
        				}
        				if (! doRemove && doCheckPrice && dbProduct.Price.Price <= 0)
        				{
        					doRemove = true;
        				}
        				if (! doRemove && doCheckStock && dbProduct.UnitStock <= 0)
        				{
        					doRemove = true;
        				}
        				break;
        			}
        		}
        		if (doRemove)
        		{
        			order.OrderLines.Remove(productLine);
        			productLine.Delete();
        		}
        	}
   }
}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

OrderLine Class
OrderLine Members
Overload List

Send Feedback