Table of Contents

Class OrderLineCollection

Namespace
Dynamicweb.Ecommerce.Orders
Assembly
Dynamicweb.Ecommerce.dll
Represents a collection of the OrderLine objects.
[Serializable]
public class OrderLineCollection : Collection<OrderLine>, IList<OrderLine>, ICollection<OrderLine>, IReadOnlyList<OrderLine>, IReadOnlyCollection<OrderLine>, IEnumerable<OrderLine>, IList, ICollection, IEnumerable, IWithPrice
Inheritance
OrderLineCollection
Implements
Inherited Members
Extension Methods

Constructors

OrderLineCollection()

[Obsolete("Use constructor that takes an order instance.")]
public OrderLineCollection()

OrderLineCollection(Order)

public OrderLineCollection(Order order)

Parameters

order Order

Properties

CountOnlyBom

Gets the count of BOM.
public int CountOnlyBom { get; }

Property Value

int

CountOnlyDiscounts

Gets the number of OrderLines of type "Discount" and "ProductDiscount".
public int CountOnlyDiscounts { get; }

Property Value

int

CountOnlyProducts

Gets the count of products.
public int CountOnlyProducts { get; }

Property Value

int

CountOnlyTaxes

Gets the number of OrderLines of type "Tax".
public int CountOnlyTaxes { get; }

Property Value

int

Order

Gets or sets the order.
public Order Order { get; set; }

Property Value

Order

Price

Gets the price.
public PriceInfo Price { get; }

Property Value

PriceInfo

Methods

Add(OrderLine)

Adds the specified order line.
public void Add(OrderLine orderLine)

Parameters

orderLine OrderLine
The order line.

Examples

public static OrderLineCollection GetOrderLineCollection(IDataReader dataReader, Order Order)
{
OrderLineCollection orderLines = new OrderLineCollection();

while (dataReader.Read())
{
OrderLine orderLine = new OrderLine(dataReader, Order);

if (orderLine.ParentLineID == "")
{
orderLine.Add(orderLine);
}
}

return orderLines;
}

Add(OrderLine, bool)

Adds the specified order line.
public void Add(OrderLine orderLine, bool doMerge)

Parameters

orderLine OrderLine
The order line.
doMerge bool
if set to true try to merge.

Examples

public static void CartAddSingleLine( int pageId, Dynamicweb.Frontend.PageView Pageview )
{

OrderLineCollection newOrderLines = new OrderLineCollection();

mProductId = Dynamicweb.Context.Current.Request("ProductID" + reqLineID, false).Replace("'", "''");
mVariantId = Dynamicweb.Context.Current.Request("VariantID" + reqLineID);
mVariantTxt = Dynamicweb.Context.Current.Request("VariantText" + reqLineID);
mUnitId = Dynamicweb.Context.Current.Request("UnitID" + reqLineID);
mQuantity = Dynamicweb.Context.Current.Request("Quantity" + reqLineID);
mType = Dynamicweb.Context.Current.Request("Type" + reqLineID);
mProductName = Dynamicweb.Context.Current.Request("ProductName" + reqLineID);
mProductNumber = Dynamicweb.Context.Current.Request("ProductNumber" + reqLineID);

if (mProductId != "")
{
OrderLine orderLine = OrderLineBuilder(Context.Cart, Converter.ToDouble(mQuantity), true, mProductId, mVariantId, mVariantTxt, mUnitId, Converter.ToString(Converter.ToInt32(mType)), RefUrl, pageId, mProductName, mProductNumber, false);
if (orderLine != null)
{
Context.Cart.OrderLines.Add(orderLine, true);
}
}

}

Add(OrderLineCollection)

Adds the specified order lines.
public void Add(OrderLineCollection orderLines)

Parameters

orderLines OrderLineCollection
The order lines.

Examples

public static void CartAddMultyLine( int pageId, Dynamicweb.Frontend.PageView Pageview )
{

OrderLineCollection newOrderLines = new OrderLineCollection();

foreach (string reqName in HttpContext.Current.Request.Form)
{

int reqLineID = 0;
if (reqName.StartsWith("ProductLoopCounter"))
{
reqLineID = Converter.ToInt32(HttpContext.Current.Request.Form[reqName]);
}

if (reqLineID <= 0)
{
continue;
}

mProductId = Dynamicweb.Context.Current.Request("ProductID" + reqLineID, false).Replace("'", "''");
mVariantId = Dynamicweb.Context.Current.Request("VariantID" + reqLineID);
mVariantTxt = Dynamicweb.Context.Current.Request("VariantText" + reqLineID);
mUnitId = Dynamicweb.Context.Current.Request("UnitID" + reqLineID);
mQuantity = Dynamicweb.Context.Current.Request("Quantity" + reqLineID);
mType = Dynamicweb.Context.Current.Request("Type" + reqLineID);
mProductName = Dynamicweb.Context.Current.Request("ProductName" + reqLineID);
mProductNumber = Dynamicweb.Context.Current.Request("ProductNumber" + reqLineID);

if (mProductId != "")
{
OrderLine orderLine = OrderLineBuilder(Context.Cart, Converter.ToDouble(mQuantity), true, mProductId, mVariantId, mVariantTxt, mUnitId, Converter.ToString(Converter.ToInt32(mType)), RefUrl, pageId, mProductName, mProductNumber, false);
if (orderLine != null)
{
orderLine.Id = "DW_NEWMULTIORDERLINEID_" + mProductId + "_" + reqLineID;
OrderLines.Add(orderLine);
}
}

}

if (OrderLines.Count > 0)
{
Context.Cart.OrderLines.Add(newOrderLines);
}

}

ClearCachedPrices()

Clears the cached prices for all OrderLines in this OrderLineCollection.
public void ClearCachedPrices()

ClearItems()

protected override void ClearItems()

GetTotalsByProductId(string)

public OrderLineCollection.TotalAndQuantity GetTotalsByProductId(string productId)

Parameters

productId string

Returns

OrderLineCollection.TotalAndQuantity

InsertItem(int, OrderLine)

protected override void InsertItem(int index, OrderLine item)

Parameters

index int
item OrderLine

Load(string, Order)

Loads the specified order lines.
[Obsolete("Please use the OrderLineService to get order lines.")]
public void Load(string sql, Order order)

Parameters

sql string
The SQL query.
order Order
The order.

Examples

public static OrderLineCollection GetOrderLineCollection( Order order)
{
OrderLineCollection productCollection = new OrderLineCollection();
string sql = String.Format("SELECT * FROM EcomOrderLines WHERE OrderLineOrderID = '{0}' ORDER BY OrderLineID, OrderLineParentLineID", order.Id);

productCollection.Load(sql, order);
return productCollection;
}

Load(string, Dictionary<string, Tuple<object, DbType>>, Order)

Loads the specified order lines.
[Obsolete("Please use the OrderLineService to get order lines.")]
public void Load(string sql, Dictionary<string, Tuple<object, DbType>> sqlParams, Order order)

Parameters

sql string
The SQL query.
sqlParams Dictionary<string, Tuple<object, DbType>>
Command parameters dictionary with key as a parameter name and value of tuple(parameter value, parameter db type)
order Order
The order.

Examples

public static OrderLineCollection GetOrderLineCollection( Order order)
{
OrderLineCollection productCollection = new OrderLineCollection();
string sql = String.Format("SELECT * FROM EcomOrderLines WHERE OrderLineOrderID = '{0}' ORDER BY OrderLineID, OrderLineParentLineID", order.Id);

productCollection.Load(sql, order);
return productCollection;
}

Remove(OrderLine)

Removes the specified order line.
public void Remove(OrderLine theOrderLine)

Parameters

theOrderLine OrderLine
The order line.

Examples

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 = Converter.ToBoolean(Dynamicweb.Configuration.SystemConfiguration.Instance.GetValue("/Globalsettings/Ecom/Product/DontShowProductIfNotOnStock"));
bool doCheckPrice = Converter.ToBoolean(Dynamicweb.Configuration.SystemConfiguration.Instance.GetValue("/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 == Converter.ToString(Converter.ToInt32(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();
}
}
}
}

RemoveDiscounts()

Removes the discounts.
public void RemoveDiscounts()

Examples

class MyPage : System.Web.UI.Page
{
public void ClearDiscounts()
{
Get the current cart
Order ecomCart = Dynamicweb.eCommerce.Common.Context.Cart;
if (ecomCart == null || !ecomCart.IsCart)
{
return;
}

ecomCart.OrderLines.RemoveDiscounts();
}
}

RemoveItem(int)

protected override void RemoveItem(int index)

Parameters

index int

RemoveLine(string)

Removes the order line.
public void RemoveLine(string orderlineId)

Parameters

orderlineId string
The order line ID.

Examples

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 = Converter.ToBoolean(Dynamicweb.Configuration.SystemConfiguration.Instance.GetValue("/Globalsettings/Ecom/Product/DontShowProductIfNotOnStock"));
bool doCheckPrice = Converter.ToBoolean(Dynamicweb.Configuration.SystemConfiguration.Instance.GetValue("/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 == Converter.ToString(Converter.ToInt32(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.ID);
productLine.Delete();
}
}
}
}

RemoveTaxes()

Removes all Tax OrderLines from the collection.
public void RemoveTaxes()

Save(string)

Saves the specified order ID.
public void Save(string orderId)

Parameters

orderId string
The order ID.

Examples

class MyPage : System.Web.UI.Page
{

public void SaveOrder( Order order )
{
IDbConnection objConn = Database.CreateConnection();
System.Data.IDbCommand objCommand = objConn.CreateCommand();
DataSet objDataset = new DataSet();
IDbDataAdapter objDataAdapter = Database.GetAdapter();
DataRow objRow = null;

Prepare adapter and fill data
string SQL = string.Format("SELECT * FROM EcomOrders WHERE OrderID = '{0}'", order.Id);
objCommand.CommandText = SQL;
objDataAdapter.SelectCommand = objCommand;
object objCommandBuilder = Database.GetCommandBuilder(objDataAdapter);
objDataAdapter.Fill(objDataset);

if (objDataset.Tables[0].Rows.Count > 0)
{
objRow = objDataset.Tables[0].Rows[0];
}
else
{
objRow = objDataset.Tables[0].NewRow();
objDataset.Tables[0].Rows.Add(objRow);
if (order.IsCart())
{
order.Id = NumberGenerator.GetNumber("CART");
}
else
{
order.Id = NumberGenerator.GetNumber("ORDER");
}
}

objRow["OrderID"] = order.Id;
objRow["OrderShopID"] = order.ShopID;
objRow["OrderDate"] = order.Date;
objRow["OrderModified"] = DateTime.Now;
objRow["OrderComplete"] = order.Complete;
objRow["OrderDeleted"] = order.Deleted;
objRow["OrderStateID"] = ((string.IsNullOrEmpty(order.StateID)) ? null : order.StateID);
objRow["OrderVAT"] = Convert.ToSingle(order.Price.VAT);
objRow["OrderTrackTraceNumber"] = order.TrackTraceNumber;
objRow["OrderShippingMethod"] = order.ShippingMethod;
objRow["OrderPaymentMethod"] = order.PaymentMethod;
objRow["OrderSalesDiscount"] = order.SalesDiscount;
objRow["OrderCurrencyName"] = order.CurrencyName;
objRow["OrderCurrencyRate"] = order.CurrencyRate;
objRow["OrderCurrencyCode"] = order.CurrencyCode;
objRow["OrderReSendEmail"] = order.ReSendEmail;
objRow["OrderCart"] = order.IsCart;
objRow["OrderFieldsXML"] = order.FieldsXML;
objRow["OrderCustomerAccessUserID"] = order.CustomerAccessUserID;
objRow["OrderCustomerAccessUserUserName"] = order.CustomerAccessUserUserName;
objRow["OrderCustomerNumber"] = order.CustomerNumber;
objRow["OrderCustomerCompany"] = order.CustomerCompany;
objRow["OrderCustomerName"] = order.CustomerName;
objRow["OrderCustomerAddress"] = order.CustomerAddress;
objRow["OrderTotalPrice"] = order.TotalPrice;

objRow["OrderPriceWithVAT"] = order.Price.PriceWithVAT;
objRow["OrderPriceWithoutVAT"] = order.Price.PriceWithoutVAT;
objRow["OrderPriceVAT"] = Convert.ToSingle(order.Price.VAT);
objRow["OrderPriceVATPercent"] = order.Price.VATPercent;

if (order.OrderFieldValues != null)
{
order.OrderFieldValues.Save(objRow);
}

objDataAdapter.Update(objDataset);

objDataset.Dispose();
objCommand.Dispose();
objConn.Close();
objConn.Dispose();

if (order.OrderLines != null)
{
order.OrderLines.Save(ID);
}

}
}

SetItem(int, OrderLine)

protected override void SetItem(int index, OrderLine item)

Parameters

index int
item OrderLine

UpdateBomOrderLine(OrderLine)

Updates the BOM order line.
public void UpdateBomOrderLine(OrderLine orderLine)

Parameters

orderLine OrderLine
The order line.

Examples

internal static void  UpdateOrderLine (int quantity, string orderLineID)
{
OrderLine line = new OrderLine(orderLineID);
Order EcomCart = Common.Context.Cart();
EcomCart.IsCart = true;

line.Modified = DateTime.Now;
line.Order = EcomCart;

if (quantity > 0)
{
line.Quantity = quantity;
EcomCart.OrderLines.UpdateBOMOrderLine(line);
}

line.ID = "";
SaveCart();
}

UpdateQuantity(OrderLine)

Updates the quantity.
public void UpdateQuantity(OrderLine orderLine)

Parameters

orderLine OrderLine
The order line.

Examples

internal static void  UpdateOrderLine (int quantity, string orderLineID)
{
OrderLine line = new OrderLine(orderLineID);
Order EcomCart = Common.Context.Cart();
EcomCart.IsCart = true;

line.Modified = DateTime.Now;
line.Order = EcomCart;

if (quantity > 0)
{
line.Quantity = quantity;
EcomCart.OrderLines.UpdateQuantity(line);
}

line.ID = "";
SaveCart();
}
To top