Esempio n. 1
0
 /// <summary>
 /// Raises the onrecalculatecart event.
 /// </summary>
 /// <param name="args">The <see cref="Rendition.RecalculateCartEventArgs"/> instance containing the event data.</param>
 internal void raiseOnrecalculatecart( RecalculateCartEventArgs args )
 {
     if( RecalculatedCart != null ) { RecalculatedCart( this, args ); };
 }
Esempio n. 2
0
 /// <summary>
 /// Recalculates the selected cart by its SessionId
 /// </summary>
 /// <param name="args">The args.</param>
 /// <returns>
 /// {error:int,errorDescription:string,subTotal:float,taxTotal:float,estShipTotal:float,discountTotal:float,grandTotal:float}.
 /// </returns>
 public static Dictionary<string, object> Recalculate(Dictionary<string, object> args)
 {
     ("FUNCTION recalculate (cart)").Debug(10);
     Dictionary<string, object> j = new Dictionary<string, object>();
     Session session;
     if(args.ContainsKey("sessionId")) {
         session = new Session(Main.Site, new Guid(args["sessionId"].ToString()));
     } else {
         session = Main.GetCurrentSession();
     }
     if(args.ContainsKey("billToContactId") || args.ContainsKey("shipToContactId")) {
         /* gather bill to and ship to data, if any, from the request */
         Dictionary<string, object> btAddr = new Dictionary<string, object>();
         Dictionary<string, object> stAddr = new Dictionary<string, object>();
         foreach(KeyValuePair<string, object> field in args as Dictionary<string, object>) {
             if(field.Key.StartsWith("shipTo")) {
                 stAddr.Add(field.Key.Replace("shipTo", ""), field.Value);
             } else if(field.Key.StartsWith("billTo")) {
                 btAddr.Add(field.Key.Replace("billTo", ""), field.Value);
             }
         }
         if(args.ContainsKey("shipToContactId")) {
             stAddr.Add("contactId", stAddr["ContactId"].ToString());
             stAddr.Remove("ContactId");
         }
         if(args.ContainsKey("billToContactId")) {
             btAddr.Add("contactId", btAddr["ContactId"].ToString());
             btAddr.Remove("ContactId");
         }
         /* update the bill to and ship to addresses in the database
          * if the Address does not exist, validate it and insert it.
          */
         if(stAddr.Count > 0) {
             stAddr.Add("sessionId", session.Id.ToString());
             stAddr.Add("userId", session.UserId.ToString());
             Address.UpdateContact(stAddr);
         }
         if(btAddr.Count > 0) {
             btAddr.Add("sessionId", session.Id.ToString());
             btAddr.Add("userId", session.UserId.ToString());
             Address.UpdateContact(btAddr);
         }
     }
     /* if the cart isn't populated, do that now */
     if(session.Cart.Items.Count == 0) {
         session.Cart.Refresh();
     }
     /* execute recalculateCart events */
     RecalculateCartEventArgs ev = new RecalculateCartEventArgs(session.Cart,
     session, HttpContext.Current, args);
     Main.Site.raiseOnrecalculatecart(ev);
     /* refresh again to reflect changes in the addresses */
     session.Cart.Refresh();
     j.Add("error", 0);
     j.Add("description", "");
     j.Add("subTotal", (float)session.Cart.SubTotal);
     j.Add("taxTotal", (float)session.Cart.TaxTotal);
     j.Add("estShipTotal", (float)session.Cart.EstShipTotal);
     j.Add("discountTotal", (float)session.Cart.DiscountTotal);
     j.Add("grandTotal", (float)session.Cart.GrandTotal);
     j.Add("addresses", session.Cart.Addresses);
     return j;
 }