Beispiel #1
0
 /// <summary>
 /// Refreshes the price filters based on the list of items fed to it
 /// used in the list class to create and then filter lists of items.
 /// </summary>
 /// <param name="item_list">The item_list.</param>
 /// <param name="priceRanges">The price ranges.</param>
 /// <returns></returns>
 private static List<Dictionary<string, object>> GetPriceFilters(List<Commerce.Item> item_list,
 List<decimal> priceRanges)
 {
     List<Dictionary<string, object>> priceFilters = new List<Dictionary<string, object>>();
     int ptotal = priceRanges.Count;
     priceRanges.Sort(delegate(decimal p1, decimal p2) {
         return p1.CompareTo(p2);
     });
     for(int x = 0; ptotal > x; x++) {
         /* figure out the range */
         decimal low = 0;
         decimal high = 0;
         bool highest = false;
         if(x == 0) {
             low = 0;
             high = priceRanges[x];
         } else if(x == ptotal - 1) {
             low = priceRanges[x];
             high = decimal.MaxValue;
             highest = true;
         } else {
             low = priceRanges[x];
             high = priceRanges[x + 1];
         }
         List<Commerce.Item> currentPriceList = item_list.FindAll(delegate(Commerce.Item itm) {
             /* figure out the effective price */
             decimal ePrice = itm.GetEffectivePrice();
             return ePrice > low && ePrice < high;
         });
         Dictionary<string, object> l = new Dictionary<string, object>();
         /* find the highest value item */
         decimal maxValue = 0;
         foreach(Commerce.Item _i in currentPriceList) {
             decimal p = _i.GetEffectivePrice();
             maxValue = p > maxValue ? p : maxValue;
         }
         l.Add("id", priceRanges[x]);
         l.Add("low", low);
         l.Add("high", highest ? maxValue : high);
         l.Add("list", currentPriceList);
         l.Add("count", currentPriceList.Count);
         priceFilters.Add(l);
     }
     return priceFilters;
 }
Beispiel #2
0
 /// <summary>
 /// Gets the best shipment.
 /// </summary>
 /// <param name="shipments">The shipments.</param>
 /// <returns></returns>
 public static Commerce.Shipment GetBestShipment(List<Commerce.Shipment> shipments)
 {
     /* check for voided numbers and add them to a list */
     List<string> voidedTrackingNumbers = new List<string>();
     List<Commerce.Shipment> unvoidedShipments = new List<Commerce.Shipment>();
     foreach(Commerce.Shipment shipment in shipments) {
         string voidStatus = shipment.VoidStatus.Trim().ToLower();
         if(voidStatus == "y" || voidStatus == "true" || voidStatus == "voided" || voidStatus == "void" || voidStatus == "yes") {
             voidedTrackingNumbers.Add(shipment.Tracking);
         }
     }
     /* go through again and find all the shipments (hopefully just one) that are not voided */
     foreach(Commerce.Shipment shipment in shipments) {
         bool addShip = true;
         foreach(string trackingNo in voidedTrackingNumbers) {
             if(trackingNo == shipment.Tracking) {
                 addShip = false;
             }
         }
         if(addShip) {
             unvoidedShipments.Add(shipment);
         }
     }
     /* there's more than one?  Than try and find the lead tracking number */
     if(unvoidedShipments.Count > 1) {
         unvoidedShipments.Sort(delegate(Commerce.Shipment s1, Commerce.Shipment s2) {
             int t1 = 0;
             int t2 = 0;
             try {
                 if(s1.Tracking.Length > 4) {
                     int.TryParse(s1.Tracking.Substring(1, 5), out t1);
                 }
                 if(s2.Tracking.Length > 4) {
                     int.TryParse(s2.Tracking.Substring(1, 5), out t2);
                 }
             } catch(Exception e) {
                 (e.Message).Debug(8);
             }
             return t1.CompareTo(t2);
         });
     }
     return unvoidedShipments[0];
 }