private OrderInfo CreateOrder() { // Get current cart ID string cartID = CurrentCart.GetInfo(PortalId, StoreSettings.SecureCookie).CartID; // Associate cart with this user or with impersonated user CartController cartController = new CartController(); if (IsLogged) { cartController.UpdateCart(cartID, UserId); } else { cartController.UpdateCart(cartID, StoreSettings.ImpersonatedUserID); } // Create order from cart content OrderInfo order = _orderController.CreateOrder(cartID); if (order != null) { SetOrderIdCookie(order.OrderID); // Create billing and shipping addresses BillingAddress = _addressProvider.GetAddress(Null.NullInteger); ShippingAddress = _addressProvider.GetAddress(Null.NullInteger); } return(order); }
protected void Page_Load(object sender, EventArgs e) { if (StoreSettings != null) { string templatePath = CssTools.GetTemplatePath(this, StoreSettings.PortalTemplates); // Read module settings and define cart properties MainCartSettings cartSettings = new ModuleSettings(ModuleId, TabId).MainCart; cartControl.ShowThumbnail = cartSettings.ShowThumbnail; cartControl.ThumbnailWidth = cartSettings.ThumbnailWidth; cartControl.GIFBgColor = cartSettings.GIFBgColor; cartControl.EnableImageCaching = cartSettings.EnableImageCaching; cartControl.CacheImageDuration = cartSettings.CacheImageDuration; cartControl.ProductColumn = cartSettings.ProductColumn.ToLower(); cartControl.LinkToDetail = cartSettings.LinkToDetail; cartControl.IncludeVAT = cartSettings.IncludeVAT; cartControl.TemplatePath = templatePath; cartControl.ModuleConfiguration = ModuleConfiguration; cartControl.StoreSettings = StoreSettings; cartControl.EditComplete += cartControl_EditComplete; _itemsCount = CurrentCart.GetInfo(PortalId, StoreSettings.SecureCookie).Items; if (IsPostBack == false) { CheckState(_itemsCount); } } }
/// <summary> /// This event should occur each time a change is made to the cart. /// All of the Checkout controls should be updated with the new cart information and the /// order updated. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void cartControl_EditComplete(object sender, EventArgs e) { CartInfo cart = CurrentCart.GetInfo(PortalId, StoreSettings.SecureCookie); if (cart != null && cart.Items > 0) { Order = _orderController.UpdateOrderDetails(Order.OrderID, cart.CartID); CalculateTaxAndShipping(null); UpdateCheckoutOrder(); } else { Response.Redirect(Globals.NavigateURL(StoreSettings.StorePageID)); } }
public HttpResponseMessage GetCart() { try { int portalID = PortalController.Instance.GetCurrentPortalSettings().PortalId; StoreInfo storeSettings = StoreController.GetStoreInfo(portalID); CartInfo cart = CurrentCart.GetInfo(portalID, storeSettings.SecureCookie); CartDTO cartDTO = new CartDTO { CartID = cart.CartID, Total = cart.Items > 0 ? cart.Total : 0 }; List <ItemInfo> cartItems = CurrentCart.GetItems(portalID, storeSettings.SecureCookie); List <ItemDTO> itemsDTO = new List <ItemDTO>(cartItems.Count); foreach (ItemInfo item in cartItems) { ItemDTO itemDTO = new ItemDTO { ItemID = item.ItemID, ProductID = item.ProductID, Manufacturer = item.Manufacturer, ModelNumber = item.ModelNumber, ModelName = item.ModelName, ProductImage = item.ProductImage, UnitCost = item.UnitCost, Quantity = item.Quantity, Discount = item.Discount }; itemsDTO.Add(itemDTO); } cartDTO.Items = itemsDTO; return(Request.CreateResponse(HttpStatusCode.OK, cartDTO)); } catch { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, LocalizeString("Unexpected.Error"))); } }
protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); int portalId = PortalSettings.PortalId; StoreInfo storeInfo = StoreController.GetStoreInfo(portalId); if (storeInfo != null) { NumberFormatInfo localFormat = (NumberFormatInfo)NumberFormatInfo.CurrentInfo.Clone(); string text; phControls.Visible = true; lblStoreMicroCartItemsTitle.CssClass = _itemsTitleCssClass; lblStoreMicroCartTotalTitle.CssClass = _totalTitleCssClass; lblStoreMicroCartItems.CssClass = _itemsCssClass; lblStoreMicroCartTotal.CssClass = _totalCssClass; string resource = TemplateSourceDirectory + "/App_LocalResources/MicroCart.ascx.resx"; lblStoreMicroCartItemsTitle.Text = Localization.GetString("CartItemsTitle.Text", resource); lblStoreMicroCartTotalTitle.Text = Localization.GetString("CartTotalTitle.Text", resource); try { CartInfo cartInfo = CurrentCart.GetInfo(portalId, storeInfo.SecureCookie); if (!string.IsNullOrEmpty(storeInfo.CurrencySymbol)) { localFormat.CurrencySymbol = storeInfo.CurrencySymbol; } ITaxProvider taxProvider = StoreController.GetTaxProvider(storeInfo.TaxName); ITaxInfo taxInfo = taxProvider.GetDefautTaxRates(portalId); bool showTax = taxInfo.ShowTax; decimal defaultTaxRate = taxInfo.DefaultTaxRate; text = Localization.GetString("CartItems.Text", resource); if (cartInfo != null && cartInfo.Items > 0) { lblStoreMicroCartItems.Text = string.Format(text, cartInfo.Items); decimal cartTotal = cartInfo.Total; if (showTax && _includeVAT && cartInfo.Total > 0) { cartTotal = (cartTotal + (cartTotal * (defaultTaxRate / 100))); } lblStoreMicroCartTotal.Text = cartTotal.ToString("C", localFormat); } else { lblStoreMicroCartItems.Text = string.Format(text, 0); lblStoreMicroCartTotal.Text = (0D).ToString("C", localFormat); } } catch { text = Localization.GetString("Error.Text", resource); lblStoreMicroCartItems.Text = text; lblStoreMicroCartTotalTitle.Text = text; } } else { phControls.Visible = false; } }
/// <summary> /// Retrieve the current order and addresses from the database. /// </summary> /// <returns></returns> private OrderInfo GetExistingOrder(int orderID, bool updateDetails) { OrderInfo order = null; if (orderID != Null.NullInteger) { try { order = _orderController.GetOrder(PortalId, orderID); if (order != null) { // Update order details if needed if (updateDetails) { order = _orderController.UpdateOrderDetails(order.OrderID, CurrentCart.GetInfo(PortalId, StoreSettings.SecureCookie).CartID); } // Load billing address or create a new one BillingAddress = _addressProvider.GetAddress(order.BillingAddressID); // Load shipping address or create a new one ShippingAddress = _addressProvider.GetAddress(order.ShippingAddressID); } } catch { order = null; } } return(order); }