public OrderCollection Search(OrderSearchCriteria criteria, int maximumRows, int startRowIndex, string sortExpression) { //CREATE RETURN SET OrderCollection orders = new OrderCollection(); //GET LIST OF ORDER IDS THAT FIT THE CRITERIA Database database = Token.Instance.Database; DbCommand selectCommand = criteria.BuildSelectCommand(sortExpression); List <int> orderIdList = new List <int>(); //EXECUTE THE COMMAND TO OBTAIN ORDER ID List using (IDataReader dr = database.ExecuteReader(selectCommand)) { while (dr.Read()) { orderIdList.Add(dr.GetInt32(0)); } dr.Close(); } //NOW GET ORDER DETAIL FOR CORRECT INDEXES int rowIndex = startRowIndex; int rowCount = 0; if (maximumRows < 1) { maximumRows = 1000; } while ((rowCount < maximumRows) && (rowIndex < orderIdList.Count)) { Order order = OrderDataSource.Load(orderIdList[rowIndex]); orders.Add(order); rowIndex++; rowCount++; } //RETURN ORDER DETAIL MATCHING CRITERIA return(orders); }
public static Order Load(Int32 orderId) { return(OrderDataSource.Load(orderId, true)); }
/// <summary> /// Gets coupons codes used for orders /// </summary> /// <returns>An array of string with the codes of coupons used</returns> public static string[] GetCouponCodes() { return(OrderDataSource.GetCouponCodes(DateTime.MinValue, DateTime.MinValue)); }
public static OrderCollection Search(int orderStatusId, OrderPaymentStatus paymentStatus, OrderShipmentStatus shipmentStatus, DateTime startDate, DateTime endDate, string sortExpression) { return(OrderDataSource.Search(orderStatusId, paymentStatus, shipmentStatus, startDate, endDate, 0, 0, sortExpression)); }
/// <summary> /// Recalculate the current payment status of an order /// </summary> /// <param name="triggerEvents">If true events are triggered on change of payment status</param> /// <remarks>We should not rely on this kind of recalculation for setting /// our statuses. If a status updates here, it is because it did not occur in /// some other, more appropriate place. Therefore we should log these occurrences as /// the warnings so they can be analyzed and corrected.</remarks> public void RecalculatePaymentStatus(bool triggerEvents) { //FIRST RECALCULATE THE STORED VALUES LSDecimal productSubtotal = this.GetProductSubtotal(); LSDecimal totalCharges = this.Items.TotalPrice(); LSDecimal totalPayments = this.Payments.TotalProcessed(); bool updated = OrderDataSource.UpdateCalculatedTotals(this, productSubtotal, totalCharges, totalPayments); //KEEP TRACK OF NEW STATUS TO DETECT CHANGES OrderPaymentStatus newStatus; //GET THE CURRENT BALANCE (EXCLUDING PENDING PAYMENTS) LSDecimal balance = (totalCharges - totalPayments); if (balance > 0) { //CHECK IF THE LAST PAYMENT RESULTED IN A PROBLEM Payment lastPayment = this.Payments.LastPayment; if ((lastPayment != null) && (lastPayment.IsFailed)) { newStatus = OrderPaymentStatus.Problem; } else { newStatus = OrderPaymentStatus.Unpaid; } } else { newStatus = OrderPaymentStatus.Paid; } //CHECK IF PAYMENT STATUS CHANGED if (this.PaymentStatus != newStatus) { OrderDataSource.UpdatePaymentStatus(this, newStatus); if (newStatus == OrderPaymentStatus.Paid) { if (balance == 0) { if (triggerEvents) { StoreEventEngine.OrderPaid(this); } else if (this.HasShippableItems) { StoreEventEngine.UpdateOrderStatus(StoreEvent.OrderPaid, this); } else { StoreEventEngine.UpdateOrderStatus(StoreEvent.OrderPaidNoShipments, this); } } else { if (triggerEvents) { StoreEventEngine.OrderPaidCreditBalance(this); } else { StoreEventEngine.UpdateOrderStatus(StoreEvent.OrderPaidCreditBalance, this); } } } } }
/// <summary> /// Recalculates the current shipment status for this order. /// </summary> public void RecalculateShipmentStatus() { //KEEP TRACK OF UPDATED STATUS TO DETECT CHANGES OrderShipmentStatus newStatus; //CHECK WHETHER THE ORDER HAS ANY SHIPMENTS if (this.Shipments.Count > 0) { //MAKE SURE THERE ARE NO SHIPPABLE ITEMS bool foundShippable = false; int i = 0; while ((i < this.Shipments.Count) && (!foundShippable)) { OrderShipment shipment = this.Shipments[i]; if (!shipment.IsShipped) { foundShippable = true; } i++; } if (foundShippable) { newStatus = OrderShipmentStatus.Unshipped; } else { newStatus = OrderShipmentStatus.Shipped; } } else { //THERE ARE NO SHIPMENTS, THIS ORDER IS NON-SHIPPABLE newStatus = OrderShipmentStatus.NonShippable; } //UNLESS WE KNOW THE ORDER IS UNSHIPED, //CHECK FOR SHIPPABLE PRODUCTS NOT IN A SHIPMENT if (this.ShipmentStatus != OrderShipmentStatus.Unshipped) { bool foundShippable = false; int i = 0; while ((i < this.Items.Count) && (!foundShippable)) { OrderItem item = this.Items[i]; if ((item.OrderItemType == OrderItemType.Product) && (item.OrderShipmentId == 0) && (item.Shippable != Shippable.No)) { foundShippable = true; } i++; } if (foundShippable) { newStatus = OrderShipmentStatus.Unshipped; } } //CHECK FOR CHANGES if (this.ShipmentStatus != newStatus) { OrderDataSource.UpdateShipmentStatus(this, newStatus); } }