protected ShoppingCartInfo GetNewCart() { ShoppingCartInfo newCart = ShoppingCartInfoProvider.CreateShoppingCartInfo(CMSContext.CurrentSite.SiteID); if (customerId > 0) { CustomerInfo ci = CustomerInfoProvider.GetCustomerInfo(customerId); if (ci != null) { UserInfo ui = null; if (ci.CustomerUserID > 0) { ui = UserInfoProvider.GetUserInfo(ci.CustomerUserID); newCart.User = ui; } //if (ui == null) //{ // ui = CMSContext.GlobalPublicUser; //} //newCart.UserInfoObj = ui; newCart.ShoppingCartCustomerID = customerId; } } return(newCart); }
/// <summary> /// Validates shopping cart content. /// </summary> public override bool IsValid() { // Force loading current values ShoppingCartInfoProvider.EvaluateShoppingCart(ShoppingCart); // Check inventory ShoppingCartCheckResult checkResult = ShoppingCartInfoProvider.CheckShoppingCart(ShoppingCart); if (checkResult.CheckFailed) { lblError.Text = checkResult.GetHTMLFormattedMessage(); return(false); } // Check if cart contains at least one product if (ShoppingCart.IsEmpty) { lblError.Text = GetString("com.checkout.cartisempty"); return(false); } return(true); }
/// <summary> /// Create Shopping cart with item by customer /// </summary> /// <param name="customerAddressID"></param> /// <param name="txtQty"></param> private void CreateShoppingCartByCustomer(SKUInfo product, int customerAddressID, int productQty, double skuPrice) { try { var customerAddress = AddressInfoProvider.GetAddressInfo(customerAddressID); if (!DataHelper.DataSourceIsEmpty(product)) { ShoppingCartInfo cart = new ShoppingCartInfo(); cart.ShoppingCartSiteID = CurrentSite.SiteID; cart.ShoppingCartCustomerID = customerAddressID; cart.ShoppingCartCurrencyID = CurrencyInfoProvider.GetMainCurrency(CurrentSite.SiteID).CurrencyID; cart.SetValue("ShoppingCartCampaignID", ProductCampaignID); cart.SetValue("ShoppingCartProgramID", ProductProgramID); cart.SetValue("ShoppingCartDistributorID", customerAddressID); cart.SetValue("ShoppingCartInventoryType", ProductType); cart.User = CurrentUser; cart.ShoppingCartShippingAddress = customerAddress; cart.ShoppingCartShippingOptionID = ProductShippingID; ShoppingCartInfoProvider.SetShoppingCartInfo(cart); ShoppingCartItemParameters parameters = new ShoppingCartItemParameters(product.SKUID, productQty); parameters.CustomParameters.Add("CartItemCustomerID", customerAddressID); ShoppingCartItemInfo cartItem = cart.SetShoppingCartItem(parameters); cartItem.SetValue("CartItemPrice", skuPrice); cartItem.SetValue("CartItemDistributorID", customerAddressID); cartItem.SetValue("CartItemCampaignID", ProductCampaignID); cartItem.SetValue("CartItemProgramID", ProductProgramID); ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(cartItem); cart.InvalidateCalculations(); } } catch (Exception ex) { EventLogProvider.LogException("CustomerCartOperations.ascx.cs", "CreateShoppingCartByCustomer()", ex); } }
/// <summary> /// Performs an inventory check for all items in the shopping cart and show message if required. /// </summary> /// <returns>True if all items are available in sufficient quantities, otherwise false</returns> private bool CheckShoppingCart() { // Remove error message before reevaluation lblError.Text = string.Empty; if (ShoppingCart.IsEmpty) { lblError.Visible = true; lblError.Text = ResHelper.GetString("com.checkout.cartisempty"); return(false); } var validationErrors = ShoppingCartInfoProvider.ValidateShoppingCart(ShoppingCart); // Try to show message through Message Panel web part if (validationErrors.Any() || orderChanged) { CMSEventArgs <string> args = new CMSEventArgs <string>(); args.Parameter = validationErrors .Select(e => HTMLHelper.HTMLEncode(e.GetMessage())) .Join("<br />"); ComponentEvents.RequestEvents.RaiseEvent(this, args, MESSAGE_RAISED); // If Message Panel web part is not present (Parameter is cleared by web part after successful handling), show error message in error label if (!string.IsNullOrEmpty(args.Parameter) && validationErrors.Any()) { lblError.Visible = true; lblError.Text = validationErrors .Select(e => HTMLHelper.HTMLEncode(e.GetMessage())) .Join("<br />"); } } return(!validationErrors.Any()); }
protected void ReloadData() { // Recalculate shopping cart ShoppingCartInfoProvider.EvaluateShoppingCart(ShoppingCart); gridData.DataSource = ShoppingCart.ContentTable; gridData.DataBind(); gridTaxSummary.DataSource = ShoppingCart.ContentTaxesTable; gridTaxSummary.DataBind(); gridShippingTaxSummary.DataSource = ShoppingCart.ShippingTaxesTable; gridShippingTaxSummary.DataBind(); // Show order related discounts plcMultiBuyDiscountArea.Visible = ShoppingCart.OrderRelatedDiscountSummaryItems.Count > 0; ShoppingCart.OrderRelatedDiscountSummaryItems.ForEach(d => { plcOrderRelatedDiscountNames.Controls.Add(new LocalizedLabel { Text = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(d.Name)) + ":", EnableViewState = false }); plcOrderRelatedDiscountNames.Controls.Add(new Literal { Text = "<br />", EnableViewState = false }); plcOrderRelatedDiscountValues.Controls.Add(new Label { Text = "- " + CurrencyInfoProvider.GetFormattedPrice(d.Value, ShoppingCart.Currency), EnableViewState = false }); plcOrderRelatedDiscountValues.Controls.Add(new Literal { Text = "<br />", EnableViewState = false }); }); // shipping option, payment method initialization InitPaymentShipping(); }
/// <summary> /// Removes the current cart item and the associated product options from the shopping cart. /// </summary> protected void Remove(object sender, EventArgs e) { // Delete all the children from the database if available foreach (ShoppingCartItemInfo scii in ShoppingCart.CartItems) { if ((scii.CartItemBundleGUID == ShoppingCartItemInfoObject.CartItemGUID) || (scii.CartItemParentGUID == ShoppingCartItemInfoObject.CartItemGUID)) { ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(scii); } } // Deletes the CartItem from the database ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(ShoppingCartItemInfoObject.CartItemGUID); // Delete the CartItem form the shopping cart object (session) ShoppingCartInfoProvider.RemoveShoppingCartItem(ShoppingCart, ShoppingCartItemInfoObject.CartItemGUID); // Log remove item activity Activity activity = new ActivityProductRemovedFromShoppingCart(ShoppingCartItemInfoObject, ResHelper.LocalizeString(ShoppingCartItemInfoObject.SKU.SKUName), ContactID, AnalyticsContext.ActivityEnvironmentVariables); activity.Log(); // Recalculate shopping cart ShoppingCartInfoProvider.EvaluateShoppingCart(ShoppingCart); // Raise the change event for all subscribed web parts ComponentEvents.RequestEvents.RaiseEvent(sender, e, SHOPPING_CART_CHANGED); }
/// <summary> /// Saves data /// </summary> protected override void SaveStepData(object sender, StepEventArgs e) { base.SaveStepData(sender, e); if (!StopProcessing) { // Set current address AddressInfo ai = addressForm.EditedObject as AddressInfo; if (ai != null) { CurrentCartAddress = ai; if (string.IsNullOrEmpty(ai.AddressPersonalName) && (ShoppingCart.Customer != null)) { ai.AddressPersonalName = TextHelper.LimitLength(string.Format("{0} {1}", ShoppingCart.Customer.CustomerFirstName, ShoppingCart.Customer.CustomerLastName), 200); } } } // Clear shipping address if shipping checkbox is unchecked if ((AddressType == SHIPPING) && (!chkShowAddress.Checked)) { ShoppingCart.ShoppingCartShippingAddress = null; } // Set shopping cart with current address change ShoppingCartInfoProvider.SetShoppingCartInfo(ShoppingCart); }
/// <summary> /// Page load event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { try { Cart = ShoppingCartInfoProvider.GetShoppingCartInfo(CartID); var capmaigns = DIContainer.Resolve<IKenticoCampaignsProvider>(); GetItems(); BindBusinessUnit(); if (InventoryType == (Int32)ProductType.GeneralInventory) { BindShippingOptions(); ddlShippingOption.SelectedValue = ValidationHelper.GetString(Cart.ShoppingCartShippingOptionID, default(string)); } else { OpenCampaignID = capmaigns.GetOpenCampaignID(); } ValidCart = true; BindRepeaterData(); } catch (Exception ex) { EventLogProvider.LogInformation("Kadena_CMSWebParts_Kadena_Cart_DistributorCartDetails", "Page_Load", ex.Message); } }
public void RemoveCartItem(int id) { // Method approach inspired by \CMS\CMSModules\Ecommerce\Controls\Checkout\CartItemRemove.ascx.cs var cart = ECommerceContext.CurrentShoppingCart; var item = cart.CartItems.FirstOrDefault(i => i.CartItemID == id); if (item == null) { return; } // Delete all the children from the database if available foreach (ShoppingCartItemInfo scii in cart.CartItems) { if ((scii.CartItemBundleGUID == item.CartItemGUID) || (scii.CartItemParentGUID == item.CartItemGUID)) { ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(scii); } } // Deletes the CartItem from the database ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(item.CartItemGUID); // Delete the CartItem form the shopping cart object (session) ShoppingCartInfoProvider.RemoveShoppingCartItem(cart, item.CartItemGUID); // Recalculate shopping cart ShoppingCartInfoProvider.EvaluateShoppingCart(cart); }
/// <summary> /// Saving billing requires recalculation of order. Save action is executed by this custom code. /// </summary> protected void editOrderBilling_OnBeforeSave(object sender, EventArgs e) { // Load the shopping cart to process the data ShoppingCartInfo sci = ShoppingCartInfoProvider.GetShoppingCartInfoFromOrder(Order.OrderID); // Update data only if shopping cart data were changed int paymentID = ValidationHelper.GetInteger(editOrderBilling.FieldEditingControls["OrderPaymentOptionID"].DataValue, 0); int currencyID = ValidationHelper.GetInteger(editOrderBilling.FieldEditingControls["OrderCurrencyID"].DataValue, 0); // Recalculate order if ((sci != null) && ((sci.ShoppingCartPaymentOptionID != paymentID) || (sci.ShoppingCartCurrencyID != currencyID))) { // Set order new properties sci.ShoppingCartPaymentOptionID = paymentID; sci.ShoppingCartCurrencyID = currencyID; // Evaluate order data ShoppingCartInfoProvider.EvaluateShoppingCart(sci); // Update order data ShoppingCartInfoProvider.SetOrder(sci, true); } // Update only one order property if (Order.OrderIsPaid != OrderIsPaid) { Order.OrderIsPaid = OrderIsPaid; OrderInfoProvider.SetOrderInfo(Order); } ShowChangesSaved(); // Stop automatic saving action editOrderBilling.StopProcessing = true; }
/// <summary> /// Validates shopping cart content. /// </summary> public override bool IsValid() { var cart = ShoppingCart; // Force loading current values ShoppingCartInfoProvider.EvaluateShoppingCart(cart); // Check inventory var checkResult = ShoppingCartInfoProvider.CheckShoppingCart(cart); // Check if selected shipping option is applicable if (!ShippingOptionInfoProvider.IsShippingOptionApplicable(cart, cart.ShippingOption)) { checkResult.ShippingOptionNotAvailable = true; } if (checkResult.CheckFailed) { lblError.Text = checkResult.GetHTMLFormattedMessage(); return(false); } // Check if cart contains at least one product if (ShoppingCart.IsEmpty) { lblError.Text = GetString("com.checkout.cartisempty"); return(false); } return(true); }
/// <summary> /// Adds an item to the shopping cart and saves the newly created cart into the database. Also saves the shopping cart if it wasn't saved yet. /// </summary> /// <param name="skuId">ID of the added product's SKU object.</param> /// <param name="quantity">Number of added product units.</param> public void AddItem(int skuId, int quantity = 1) { var parameters = new ShoppingCartItemParameters { SKUID = skuId, Quantity = quantity }; var cartItem = ShoppingCartInfoProvider.SetShoppingCartItem(OriginalCart, parameters); if (cartItem == null) { return; } if (OriginalCart.ShoppingCartID == 0) { Save(false); } ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(cartItem); mActivityLogger?.LogProductAddedToShoppingCartActivity(cartItem.SKU, quantity); mItems = null; }
/// <summary> /// Removes the current cart item and the associated product options from the shopping cart. /// </summary> protected void Remove(object sender, EventArgs e) { // Delete all the children from the database if available foreach (ShoppingCartItemInfo scii in ShoppingCart.CartItems) { if ((scii.CartItemBundleGUID == ShoppingCartItemInfoObject.CartItemGUID) || (scii.CartItemParentGUID == ShoppingCartItemInfoObject.CartItemGUID)) { ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(scii); } } // Deletes the CartItem from the database ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(ShoppingCartItemInfoObject.CartItemGUID); // Delete the CartItem form the shopping cart object (session) ShoppingCartInfoProvider.RemoveShoppingCartItem(ShoppingCart, ShoppingCartItemInfoObject.CartItemGUID); // Log remove item activity mActivityLogger.LogProductRemovedFromShoppingCartActivity(ShoppingCartItemInfoObject.SKU, ShoppingCartItemInfoObject.CartItemUnits, ContactID); // Recalculate shopping cart ShoppingCart.Evaluate(); // Make sure that in-memory changes persist (unsaved address, etc.) ECommerceContext.CurrentShoppingCart = ShoppingCart; // Raise the change event for all subscribed web parts ComponentEvents.RequestEvents.RaiseEvent(this, e, SHOPPING_CART_CHANGED); }
/// <summary> /// Removing Shopping Cart and cart items by cart id /// </summary> /// <param name="shoppingCartID"></param> private void RemovingProductFromShoppingCart(SKUInfo product, int shoppingCartID) { try { if (!DataHelper.DataSourceIsEmpty(product)) { ShoppingCartItemInfo item = null; ShoppingCartInfo cart = ShoppingCartInfoProvider.GetShoppingCartInfo(shoppingCartID); cart.User = CurrentUser; item = cart.CartItems.Where(g => g.SKUID == product.SKUID).FirstOrDefault(); if (!DataHelper.DataSourceIsEmpty(item)) { ShoppingCartInfoProvider.RemoveShoppingCartItem(cart, item.CartItemID); ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(item); if (cart.CartItems.Count == 0) { ShoppingCartInfoProvider.DeleteShoppingCartInfo(shoppingCartID); } cart.InvalidateCalculations(); } } } catch (Exception ex) { EventLogProvider.LogException("CustomerCartOperations.ascx.cs", "RemovingProductFromShoppingCart()", ex); } }
/// <summary> /// Performs an inventory check for all items in the shopping cart and show message if required. /// </summary> /// <returns>True if all items are available in sufficient quantities, otherwise false</returns> private bool CheckShoppingCart() { // Remove error message before reevaluation lblError.Text = string.Empty; if (ShoppingCart.IsEmpty) { lblError.Visible = true; lblError.Text = ResHelper.GetString("com.checkout.cartisempty"); return(false); } ShoppingCartCheckResult checkResult = ShoppingCartInfoProvider.CheckShoppingCart(ShoppingCart); // Try to show message through Message Panel web part if (checkResult.CheckFailed || orderChanged) { CMSEventArgs <string> args = new CMSEventArgs <string>(); args.Parameter = checkResult.GetHTMLFormattedMessage(); ComponentEvents.RequestEvents.RaiseEvent(this, args, MESSAGE_RAISED); // If Message Panel web part is not present (Parameter is cleared by web part after successful handling), show error message in error label if (!string.IsNullOrEmpty(args.Parameter) && checkResult.CheckFailed) { lblError.Visible = true; lblError.Text = checkResult.GetHTMLFormattedMessage(); } } return(!checkResult.CheckFailed); }
public override bool ProcessStep() { try { // Cleanup the ShoppingCart ViewState ShoppingCartControl.SetTempValue(SHIPPING_OPTION_ID, null); ShoppingCartControl.SetTempValue(PAYMENT_OPTION_ID, null); ShoppingCart.ShoppingCartShippingOptionID = selectShipping.SelectedID; ShoppingCart.ShoppingCartPaymentOptionID = selectPayment.SelectedID; // Update changes in database only when on the live site if (!ShoppingCartControl.IsInternalOrder) { ShoppingCartInfoProvider.SetShoppingCartInfo(ShoppingCart); } return(true); } catch (Exception ex) { lblError.Visible = true; lblError.Text = ex.Message; return(false); } }
/// <summary> /// Removes the current cart item and the associated product options from the shopping cart. /// </summary> protected void Remove(object sender, EventArgs e) { try { cart = ShoppingCartInfoProvider.GetShoppingCartInfo(CartID); foreach (ShoppingCartItemInfo scii in cart.CartItems) { if ((scii.CartItemBundleGUID == ShoppingCartItemInfoObject.CartItemGUID) || (scii.CartItemParentGUID == ShoppingCartItemInfoObject.CartItemGUID)) { ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(scii); } } ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(ShoppingCartItemInfoObject.CartItemGUID); ShoppingCartInfoProvider.RemoveShoppingCartItem(cart, ShoppingCartItemInfoObject.CartItemGUID); if (cart.CartItems.Count == 0) { ShoppingCartInfoProvider.DeleteShoppingCartInfo(cart.ShoppingCartID); } mActivityLogger.LogProductRemovedFromShoppingCartActivity(ShoppingCartItemInfoObject.SKU, ShoppingCartItemInfoObject.CartItemUnits, ContactID); ShoppingCartInfoProvider.EvaluateShoppingCart(cart); ComponentEvents.RequestEvents.RaiseEvent(sender, e, SHOPPING_CART_CHANGED); URLHelper.Redirect($"{Request.RawUrl}?status={QueryStringStatus.Deleted}"); } catch (Exception ex) { EventLogProvider.LogInformation("Kadena_CMSWebParts_Kadena_Cart_RemoveItemFromCart", "Remove", ex.Message); } }
public ActionResult PreviewAndPay(PreviewAndPayViewModel model) { // Gets the current shopping cart ShoppingCartInfo cart = shoppingService.GetCurrentShoppingCart(); // Validates the shopping cart var validationErrors = ShoppingCartInfoProvider.ValidateShoppingCart(cart); // Gets the selected payment method, assigns it to the shopping cart, and evaluates the cart shoppingService.SetPaymentOption(model.PaymentMethod.PaymentMethodID); // If the validation was not successful, displays the preview step again if (validationErrors.Any() || !IsPaymentMethodValid(model.PaymentMethod.PaymentMethodID)) { // Prepares a view model from the order review step PreviewAndPayViewModel viewModel = PreparePreviewViewModel(); // Displays the order review step again return(View("PreviewAndPay", viewModel)); } // Creates an order from the current shopping cart // If the order was created successfully, empties the cart OrderInfo order = shoppingService.CreateOrder(); // Redirects to the payment gateway return(RedirectToAction("Index", "Payment", new { orderID = order.OrderID })); }
/// <summary> /// Returns order item edit action HTML. /// </summary> protected string GetOrderItemEditAction(object value) { var editOrderItemElemHtml = ""; Guid itemGuid = ValidationHelper.GetGuid(value, Guid.Empty); if (itemGuid != Guid.Empty) { var item = ShoppingCartInfoProvider.GetShoppingCartItem(ShoppingCart, itemGuid); // Hide edit link for attribute product option if (item.IsAttributeOption) { return(null); } var query = "itemguid=" + itemGuid + GetCMSDeskShoppingCartSessionNameQuery(); var editItemUrl = ApplicationUrlHelper.GetElementDialogUrl(ModuleName.ECOMMERCE, "order.OrderItemProperties", 0, query); var priceDetailButton = new CMSGridActionButton { IconCssClass = "icon-edit", IconStyle = GridIconStyle.Allow, ToolTip = GetString("shoppingcart.editorderitem"), OnClientClick = ScriptHelper.GetModalDialogScript(editItemUrl, "OrderItemEdit", 720, 420) }; editOrderItemElemHtml = priceDetailButton.GetRenderedHTML(); } return(editOrderItemElemHtml); }
public ActionResult ShoppingCartCheckout() { var cart = mShoppingService.GetCurrentShoppingCart(); var validationErrors = ShoppingCartInfoProvider.ValidateShoppingCart(cart); cart.Evaluate(); if (!validationErrors.Any()) { var customer = GetCustomerOrCreateFromAuthenticatedUser(); if (customer != null) { mShoppingService.SetCustomer(customer); } mShoppingService.SaveCart(); return(RedirectToAction("DeliveryDetails")); } // Fill model state with errors from the check result ProcessCheckResult(validationErrors); var viewModel = mCheckoutService.PrepareCartViewModel(); return(View("ShoppingCart", viewModel)); }
public override bool ProcessStep() { try { //int paymentID = ValidationHelper.GetInteger(SessionHelper.GetValue("PaymentID"), 0); int paymentID = ShippingExtendedInfoProvider.GetCustomFieldValue(ShoppingCart, "ShoppingCartPaymentID"); // Cleanup the ShoppingCart ViewState ShoppingCartControl.SetTempValue(SHIPPING_OPTION_ID, null); ShoppingCartControl.SetTempValue(PAYMENT_OPTION_ID, null); //ShoppingCart.ShoppingCartShippingOptionID = selectShipping.ShippingID; //ShoppingCart.ShoppingCartPaymentOptionID = selectPayment.PaymentID; ShoppingCart.ShoppingCartShippingOptionID = IsShippingNeeded ? GetShippingID() : selectShipping.ShippingID; ShoppingCart.ShoppingCartPaymentOptionID = paymentID; // Update changes in database only when on the live site if (!ShoppingCartControl.IsInternalOrder) { ShoppingCartInfoProvider.SetShoppingCartInfo(ShoppingCart); } return(true); } catch (Exception ex) { lblError.Visible = true; lblError.Text = ex.Message + " /step " + IsShippingNeeded.ToString(); return(false); } }
public List <int> GetShoppingCartIDByInventoryType(int inventoryType, int userID, int campaignID = 0) { return(ShoppingCartInfoProvider.GetShoppingCarts(SiteContext.CurrentSiteID) .OnSite(SiteContext.CurrentSiteID) .WhereEquals("ShoppingCartUserID", userID) .WhereEquals("ShoppingCartCampaignID", campaignID) ?.ToList().Select(x => x.ShoppingCartID).ToList()); }
public ShoppingCart CreateEmptyShoppingCart() { var originalCart = ShoppingCartFactory.CreateCart(SiteID); ShoppingCartInfoProvider.SetShoppingCartInfo(originalCart); return(new ShoppingCart(originalCart, new EcommerceActivitiesLoggerFake(), null, null)); }
/// <summary> /// Removes current shopping cart data from database and from session. /// </summary> private void CleanUpShoppingCart() { if (ShoppingCart != null) { ShoppingCartInfoProvider.DeleteShoppingCartInfo(ShoppingCart.ShoppingCartID); ECommerceContext.CurrentShoppingCart = null; } }
/// <summary> /// Saves order information from ShoppingCartInfo object to database as new order. /// </summary> public override bool ProcessStep() { // Load first step if there is no address if (ShoppingCart.ShoppingCartBillingAddress == null) { ShoppingCartControl.LoadStep(0); return(false); } // Deal with order note ShoppingCartControl.SetTempValue(ORDER_NOTE, null); ShoppingCart.ShoppingCartNote = TextHelper.LimitLength(txtNote.Text.Trim(), txtNote.MaxLength); try { // Set order culture ShoppingCart.ShoppingCartCulture = LocalizationContext.PreferredCultureCode; // Create order ShoppingCartInfoProvider.SetOrder(ShoppingCart); } catch (Exception ex) { // Show error lblError.Text = GetString("Ecommerce.OrderPreview.ErrorOrderSave"); // Log exception Service.Resolve <IEventLogService>().LogException("Shopping cart", "SAVEORDER", ex, ShoppingCart.ShoppingCartSiteID); return(false); } // Track order activity string siteName = SiteContext.CurrentSiteName; if (LogActivityForCustomer) { var mainCurrency = CurrencyInfoProvider.GetMainCurrency(ShoppingCart.ShoppingCartSiteID); var grandTotalInMainCurrency = Service.Resolve <ICurrencyConverterService>().Convert(ShoppingCart.GrandTotal, ShoppingCart.Currency.CurrencyCode, mainCurrency.CurrencyCode, ShoppingCart.ShoppingCartSiteID); var formattedPrice = CurrencyInfoProvider.GetFormattedPrice(grandTotalInMainCurrency, mainCurrency); ShoppingCartControl.TrackActivityPurchasedProducts(ShoppingCart, siteName, ContactID); ShoppingCartControl.TrackActivityPurchase(ShoppingCart.OrderId, ContactID, SiteContext.CurrentSiteName, RequestContext.CurrentRelativePath, grandTotalInMainCurrency, formattedPrice); } // Raise finish order event ShoppingCartControl.RaiseOrderCompletedEvent(); if (chkSendEmail.Checked) { // Send order notification emails OrderInfoProvider.SendOrderNotificationToAdministrator(ShoppingCart); OrderInfoProvider.SendOrderNotificationToCustomer(ShoppingCart); } return(true); }
/// <summary> /// Validates the shopping cart. In case of error user is able to go through CHOP again with the same cart object. /// </summary> /// <param name="shoppingCart">The shopping cart.</param> /// <param name="errorMessage">The error message.</param> private bool ValidateShoppingCart(ShoppingCartInfo shoppingCart, out string errorMessage) { bool valid = true; StringBuilder sb = new StringBuilder(); // Check shopping cart items. // The following conditions must be met to pass the check: // 1)All shopping cart items are enabled 2)Max units in one order are not exceeded // 3)There is enough units in the inventory 4) Customer is registered, if there is a membership type product in the cart // 5)Product validity is valid, if there is a membership or e-product type product in the cart // 6)Selected shipping option is applicable to cart var result = ShoppingCartInfoProvider.CheckShoppingCart(shoppingCart); if (result.CheckFailed || shoppingCart.IsEmpty) { valid = false; sb.Append(result.GetHTMLFormattedMessage()); sb.Append(HTML_SEPARATOR); } // Check PaymentOption if (shoppingCart.PaymentOption == null) { valid = false; sb.Append(GetString("com.checkout.paymentoptionnotselected")); sb.Append(HTML_SEPARATOR); } // Check whether payment option is valid for user. string message; if (!CheckPaymentOptionIsValidForUser(shoppingCart, out message)) { valid = false; sb.Append(message); sb.Append(HTML_SEPARATOR); } // Check payment is valid for cart shipping if (!CheckPaymentIsAllowedForShipping(shoppingCart, shoppingCart.ShoppingCartPaymentOptionID)) { valid = false; sb.Append(GetString("com.checkout.paymentoptionnotapplicable")); sb.Append(HTML_SEPARATOR); } // If there is at least one product that needs shipping and shipping is not selected if (shoppingCart.IsShippingNeeded && (shoppingCart.ShippingOption == null)) { valid = false; sb.Append(GetString("com.checkoutprocess.shippingneeded")); sb.Append(HTML_SEPARATOR); } errorMessage = TextHelper.TrimEndingWord(sb.ToString(), HTML_SEPARATOR); return(valid); }
/// <summary> /// Removes all items from the shopping cart. /// </summary> public void RemoveAllItems() { OriginalCart.CartItems.ForEach(cartItem => { mActivityLogger?.LogProductRemovedFromShoppingCartActivity(cartItem.SKU, cartItem.CartItemUnits); }); ShoppingCartInfoProvider.EmptyShoppingCart(OriginalCart); mItems = null; }
private void SaveCartItem(ShoppingCartItemInfo scii) { // Set new cart if (ShoppingCart.ShoppingCartID == 0) { ShoppingCartInfoProvider.SetShoppingCartInfo(ShoppingCart); } ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(scii); }
/// <summary> /// Updates the unit count for the current cart item and it's children. /// </summary> public void Update(object sender, EventArgs e) { // Disable update operation for ReadOnly mode if (ReadOnly) { return; } if ((ShoppingCartItemInfoObject != null) && !ShoppingCartItemInfoObject.IsProductOption) { var count = ValidationHelper.GetInteger(unitCountFormControl.Value, -1); // Do nothing (leave old value) for invalid/same input if ((count < 0) || (count == ShoppingCartItemInfoObject.CartItemUnits)) { return; } if (count == 0) { // Delete all the children from the database if available foreach (var scii in ShoppingCart.CartItems.Where(scii => scii.CartItemParentGUID == ShoppingCartItemInfoObject.CartItemGUID)) { ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(scii); } // Deletes the CartItem from the database ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(ShoppingCartItemInfoObject.CartItemGUID); // Delete the CartItem form the shopping cart object (session) ShoppingCartInfoProvider.RemoveShoppingCartItem(ShoppingCart, ShoppingCartItemInfoObject.CartItemGUID); } else { // Check if the current item has children, if yes, update the product option unit count foreach (var scii in ShoppingCart.CartItems.Where(s => s.CartItemParentGUID == ShoppingCartItemInfoObject.CartItemGUID)) { scii.CartItemUnits = count; SaveCartItem(scii); } // Update units of child bundle items foreach (var bundleItem in ShoppingCartItemInfoObject.BundleItems) { bundleItem.CartItemUnits = count; SaveCartItem(bundleItem); } ShoppingCartItemInfoObject.CartItemUnits = count; SaveCartItem(ShoppingCartItemInfoObject); } // Invalidate the shopping cart so it is recalculated with the correct values ShoppingCart.InvalidateCalculations(); } // Raise the change event for all subscribed web parts ComponentEvents.RequestEvents.RaiseEvent(sender, e, SHOPPING_CART_CHANGED); }
void editOrderBilling_OnAfterSave(object sender, EventArgs e) { if (recalculateOrder) { ShoppingCartInfo sci = ShoppingCartInfoProvider.GetShoppingCartInfoFromOrder(Order.OrderID); // Evaluate order data ShoppingCartInfoProvider.EvaluateShoppingCart(sci); // Update order data ShoppingCartInfoProvider.SetOrder(sci, true); } }