/// <summary> /// Loads a collection of orders associated to the given coupon code /// </summary> /// <param name="couponCode">Coupon Code for which to load the associated orders</param> /// <param name="startDate">start date to consider when loading orders</param> /// <param name="endDate">end date to consider when loading orders</param> /// <param name="sortExpression">Sort expression to use for sorting the loaded objects</param> /// <returns>A collection of orders associated to the given coupon code</returns> public static OrderCollection LoadForCouponCode(string couponCode, DateTime startDate, DateTime endDate, string sortExpression) { StringBuilder selectQuery = new StringBuilder(); selectQuery.Append("SELECT "); selectQuery.Append(Order.GetColumnNames("O")); selectQuery.Append(" FROM ac_Orders O INNER JOIN ac_OrderCoupons C ON O.OrderId = C.OrderId"); selectQuery.Append(" WHERE C.CouponCode = @couponCode"); selectQuery.Append(" AND O.StoreId = @storeId"); List <OrderStatus> reportStatuses = OrderStatusDataSource.GetReportStatuses(); selectQuery.Append(" AND " + ReportDataSource.GetStatusFilter(reportStatuses, "O")); if (startDate > DateTime.MinValue) { selectQuery.Append(" AND O.OrderDate >= @startDate"); } if (endDate > DateTime.MinValue) { selectQuery.Append(" AND O.OrderDate <= @endDate"); } if (!string.IsNullOrEmpty(sortExpression)) { selectQuery.Append(" ORDER BY " + sortExpression); } Database database = Token.Instance.Database; DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString()); database.AddInParameter(selectCommand, "@couponCode", System.Data.DbType.String, couponCode); database.AddInParameter(selectCommand, "@storeId", System.Data.DbType.Int32, Token.Instance.StoreId); if (startDate > DateTime.MinValue) { database.AddInParameter(selectCommand, "@startDate", System.Data.DbType.DateTime, LocaleHelper.FromLocalTime(startDate)); } if (endDate > DateTime.MinValue) { database.AddInParameter(selectCommand, "@endDate", System.Data.DbType.DateTime, LocaleHelper.FromLocalTime(endDate)); } ReportDataSource.SetStatusFilterParams(reportStatuses, database, selectCommand); OrderCollection results = new OrderCollection(); using (IDataReader dr = database.ExecuteReader(selectCommand)) { while (dr.Read()) { Order order = new Order(); Order.LoadDataReader(order, dr); results.Add(order); } dr.Close(); } return(results); }
/// <summary> /// Gets coupons codes used for orders /// </summary> /// <param name="startDate">The starting date for orders to be checked for coupons</param> /// <param name="endDate">The ending date for orders to be checked for coupons</param> /// <returns>An array of string with the codes of coupons used</returns> public static string[] GetCouponCodes(DateTime startDate, DateTime endDate) { StringBuilder selectQuery = new StringBuilder(); selectQuery.Append("SELECT DISTINCT(C.CouponCode)"); selectQuery.Append(" FROM ac_Orders O INNER JOIN ac_OrderCoupons C ON O.OrderId = C.OrderId"); selectQuery.Append(" WHERE O.StoreId = @storeId"); if (startDate > DateTime.MinValue) { selectQuery.Append(" AND O.OrderDate >= @startDate"); } if (endDate > DateTime.MinValue) { selectQuery.Append(" AND O.OrderDate <= @endDate"); } List <OrderStatus> reportStatuses = OrderStatusDataSource.GetReportStatuses(); selectQuery.Append(" AND " + ReportDataSource.GetStatusFilter(reportStatuses, "O")); selectQuery.Append(" ORDER BY C.CouponCode"); Database database = Token.Instance.Database; DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString()); database.AddInParameter(selectCommand, "@storeId", System.Data.DbType.Int32, Token.Instance.StoreId); if (startDate > DateTime.MinValue) { database.AddInParameter(selectCommand, "@startDate", System.Data.DbType.DateTime, LocaleHelper.FromLocalTime(startDate)); } if (endDate > DateTime.MinValue) { database.AddInParameter(selectCommand, "@endDate", System.Data.DbType.DateTime, LocaleHelper.FromLocalTime(endDate)); } ReportDataSource.SetStatusFilterParams(reportStatuses, database, selectCommand); List <string> results = new List <string>(); using (IDataReader dr = database.ExecuteReader(selectCommand)) { while (dr.Read()) { results.Add(dr.GetString(0)); } dr.Close(); } if (results.Count == 0) { return(null); } return(results.ToArray()); }
/// <summary> /// This creates the base order object / record without child data /// </summary> /// <param name="basket">The basket to generate an order record for.</param> /// <returns>The order generated from the basket</returns> /// <remarks>This is the first stage of the checkout sequence, following order /// generation all child data must be recorded. This method makes no alteration /// to the basket object.</remarks> internal static Order GenerateOrderObject(Basket basket) { //CREATE THE ORDER RECORD Order order = new Order(); order.OrderNumber = StoreDataSource.GetNextOrderNumber(true); order.OrderStatusId = OrderStatusDataSource.GetNewOrderStatus().OrderStatusId; order.OrderDate = LocaleHelper.LocalNow; //SET USER DATA order.UserId = basket.UserId; //CHECK USER AFFILIATE User user = basket.User; Affiliate affiliate = user.Affiliate; if (affiliate != null) { //IF AFFILIATE IS NOT NULL IT MEANS THAT ITS ALREADY VALIDATED BY User.ValidateAffiliate METHOD SO ASSING IT TO THE ORDER order.AffiliateId = affiliate.AffiliateId; } //SET BILLING ADDRESS CheckoutHelper.RecordBillingAddress(user, order); //SET VALUES FROM HTTPCONTEXT HttpContext context = HttpContext.Current; if (context != null) { if (context.Session != null) { string url = (string)context.Session["SessionReferrerUrl"]; if (!string.IsNullOrEmpty(url)) { order.Referrer = StringHelper.Truncate(url, 255); } } order.RemoteIP = StringHelper.Truncate(context.Request.UserHostAddress, 39); } //SAVE THE ORDER order.Save(false); return(order); }
/// <summary> /// Saves this OrderStatus object to the database. /// </summary> /// <returns><b>SaveResult</b> enumeration that represents the result of the save operation.</returns> public virtual SaveResult Save() { if (this.IsDirty) { Database database = Token.Instance.Database; bool recordExists = true; //SET EMPTY STOREID TO CURRENT CONTEXT if (this.StoreId == 0) { this.StoreId = Token.Instance.StoreId; } if (this.OrderStatusId == 0) { recordExists = false; } if (this.OrderBy < 0) { this.OrderBy = OrderStatusDataSource.GetNextOrderBy(); } if (recordExists) { //verify whether record is already present StringBuilder selectQuery = new StringBuilder(); selectQuery.Append("SELECT COUNT(*) As RecordCount FROM ac_OrderStatuses"); selectQuery.Append(" WHERE OrderStatusId = @OrderStatusId"); using (DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString())) { database.AddInParameter(selectCommand, "@OrderStatusId", System.Data.DbType.Int32, this.OrderStatusId); if ((int)database.ExecuteScalar(selectCommand) == 0) { recordExists = false; } } } int result = 0; if (recordExists) { //UPDATE StringBuilder updateQuery = new StringBuilder(); updateQuery.Append("UPDATE ac_OrderStatuses SET "); updateQuery.Append("StoreId = @StoreId"); updateQuery.Append(", Name = @Name"); updateQuery.Append(", DisplayName = @DisplayName"); updateQuery.Append(", InventoryActionId = @InventoryActionId"); updateQuery.Append(", IsActive = @IsActive"); updateQuery.Append(", IsValid = @IsValid"); updateQuery.Append(", OrderBy = @OrderBy"); updateQuery.Append(" WHERE OrderStatusId = @OrderStatusId"); using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString())) { database.AddInParameter(updateCommand, "@OrderStatusId", System.Data.DbType.Int32, this.OrderStatusId); database.AddInParameter(updateCommand, "@StoreId", System.Data.DbType.Int32, this.StoreId); database.AddInParameter(updateCommand, "@Name", System.Data.DbType.String, this.Name); database.AddInParameter(updateCommand, "@DisplayName", System.Data.DbType.String, NullableData.DbNullify(this.DisplayName)); database.AddInParameter(updateCommand, "@InventoryActionId", System.Data.DbType.Int16, this.InventoryActionId); database.AddInParameter(updateCommand, "@IsActive", System.Data.DbType.Boolean, this.IsActive); database.AddInParameter(updateCommand, "@IsValid", System.Data.DbType.Boolean, this.IsValid); database.AddInParameter(updateCommand, "@OrderBy", System.Data.DbType.Int16, this.OrderBy); //RESULT IS NUMBER OF RECORDS AFFECTED result = database.ExecuteNonQuery(updateCommand); } } else { //INSERT StringBuilder insertQuery = new StringBuilder(); insertQuery.Append("INSERT INTO ac_OrderStatuses (StoreId, Name, DisplayName, InventoryActionId, IsActive, IsValid, OrderBy)"); insertQuery.Append(" VALUES (@StoreId, @Name, @DisplayName, @InventoryActionId, @IsActive, @IsValid, @OrderBy)"); insertQuery.Append("; SELECT Scope_Identity()"); using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString())) { database.AddInParameter(insertCommand, "@OrderStatusId", System.Data.DbType.Int32, this.OrderStatusId); database.AddInParameter(insertCommand, "@StoreId", System.Data.DbType.Int32, this.StoreId); database.AddInParameter(insertCommand, "@Name", System.Data.DbType.String, this.Name); database.AddInParameter(insertCommand, "@DisplayName", System.Data.DbType.String, NullableData.DbNullify(this.DisplayName)); database.AddInParameter(insertCommand, "@InventoryActionId", System.Data.DbType.Int16, this.InventoryActionId); database.AddInParameter(insertCommand, "@IsActive", System.Data.DbType.Boolean, this.IsActive); database.AddInParameter(insertCommand, "@IsValid", System.Data.DbType.Boolean, this.IsValid); database.AddInParameter(insertCommand, "@OrderBy", System.Data.DbType.Int16, this.OrderBy); //RESULT IS NEW IDENTITY; result = AlwaysConvert.ToInt(database.ExecuteScalar(insertCommand)); this._OrderStatusId = result; } } this.SaveChildren(); //OBJECT IS DIRTY IF NO RECORDS WERE UPDATED OR INSERTED this.IsDirty = (result == 0); if (this.IsDirty) { return(SaveResult.Failed); } else { return(recordExists ? SaveResult.RecordUpdated : SaveResult.RecordInserted); } } //SAVE IS SUCCESSFUL IF OBJECT IS NOT DIRTY return(SaveResult.NotDirty); }
/// <summary> /// Deletes an Order Status, reassociating any orders with the specified order status. /// </summary> /// <param name="newOrderStatusId">The order status that associated orders should be switched to</param> /// <returns>True if the order status is deleted, false otherwise.</returns> public virtual bool Delete(int newOrderStatusId) { OrderStatusDataSource.MoveOrders(this.OrderStatusId, newOrderStatusId); return(this.Delete()); }
/// <summary> /// Updates order status of the given order /// </summary> /// <param name="order">The order for which to update the order status</param> /// <param name="newStatusId">The new OrderStatusId to set fort the order</param> public static void UpdateOrderStatus(Order order, int newStatusId) { OrderStatus newStatus = OrderStatusDataSource.Load(newStatusId); UpdateOrderStatus(order, newStatus); }
public static OrderStatus Load(Int32 orderStatusId) { return(OrderStatusDataSource.Load(orderStatusId, true)); }
public static OrderStatusCollection LoadForEmailTemplate(Int32 emailTemplateId, int maximumRows, int startRowIndex) { return(OrderStatusDataSource.LoadForEmailTemplate(emailTemplateId, maximumRows, startRowIndex, string.Empty)); }
public static OrderStatusCollection LoadForEmailTemplate(Int32 emailTemplateId, string sortExpression) { return(OrderStatusDataSource.LoadForEmailTemplate(emailTemplateId, 0, 0, sortExpression)); }
public static OrderStatusCollection LoadForEmailTemplate(Int32 emailTemplateId) { return(OrderStatusDataSource.LoadForEmailTemplate(emailTemplateId, 0, 0, string.Empty)); }
/// <summary> /// Update the order status for this order /// </summary> /// <param name="orderStatusId">Id of the new order status to set</param> public void UpdateOrderStatus(int orderStatusId) { OrderStatus orderStatus = OrderStatusDataSource.Load(orderStatusId); this.UpdateOrderStatus(orderStatus); }