/// <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> /// 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); } }
/// <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; } }
protected void Page_Load(object sender, EventArgs e) { if (ECommerceContext.CurrentShoppingCart != null) { ShoppingCartInfoProvider.DeleteShoppingCartInfo(ECommerceContext.CurrentShoppingCart); ECommerceContext.CurrentShoppingCart = null; } string strOrderId = QueryHelper.GetText("orderID", string.Empty); int orderid = ValidationHelper.GetInteger(strOrderId, 0); string status = QueryHelper.GetString("STATUS", string.Empty);//HttpContext.Current.Request.QueryString["STATUS"]; ev.LogEvent("I", DateTime.Now, "status", status); ev.LogEvent("I", DateTime.Now, "orderid", strOrderId); if (status == "5" && orderid > 0) { ev.LogEvent("I", DateTime.Now, "ICI 2", ""); var order = OrderInfoProvider.GetOrderInfo(orderid); if (order != null) { ev.LogEvent("I", DateTime.Now, "Order found", ""); // Update the property order.OrderIsPaid = true; order.OrderStatusID = 7; // Update the order OrderInfoProvider.SetOrderInfo(order); //Sendmail link of download to customer var listModel = GetDownLoadFile(orderid); var oi = OrderInfoProvider.GetOrderInfo(orderid); var currentCust = CustomerInfoProvider.GetCustomerInfo(oi.OrderCustomerID); string mail = currentCust.CustomerEmail; ev.LogEvent("I", DateTime.Now, "cust mail : " + mail, ""); if (listModel != null) { ev.LogEvent("I", DateTime.Now, "send mail to : " + mail, ""); SendMail(mail, listModel); } } } }
/// <summary> /// Removes the current cart item and the associated product options from the shopping cart. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void linkRemoveItem_Click(object sender, EventArgs e) { try { RepeaterItem item = (sender as LinkButton).Parent as RepeaterItem; int cartItemID = int.Parse((item.FindControl("lblCartItemID") as Label).Text); ShoppingCartItemInfoProvider.DeleteShoppingCartItemInfo(cartItemID); ShoppingCartInfoProvider.RemoveShoppingCartItem(Cart, cartItemID); if (Cart.CartItems.Count == 0) { ShoppingCartInfoProvider.DeleteShoppingCartInfo(Cart.ShoppingCartID); } ShoppingCartInfoProvider.EvaluateShoppingCart(Cart); ComponentEvents.RequestEvents.RaiseEvent(sender, e, SHOPPING_CART_CHANGED); Response.Cookies["status"].Value = QueryStringStatus.Deleted; Response.Cookies["status"].HttpOnly = false; URLHelper.Redirect(Request.RawUrl); } catch (Exception ex) { EventLogProvider.LogInformation("Kadena_CMSWebParts_Kadena_Cart_RemoveItemFromCart", "Remove", ex.Message); } }
public override bool ProcessStep() { string siteName = SiteContext.CurrentSiteName; if (IsExistingAccount()) { // Sign in customer with existing account // Authenticate user //UserInfo ui = UserInfoProvider.GetUserInfo(txtLogin.Text); UserInfo ui = AuthenticationHelper.AuthenticateUser(txtLogin.Text.Trim(), txtMotDePasse.Text, SiteContext.CurrentSiteName); if (ui == null) { // ShowError(ResHelper.GetString("ShoppingCartCheckRegistration.LoginFailed")); return(false); } // Set current user MembershipContext.AuthenticatedUser = new CurrentUserInfo(ui, true); UserInfoProvider.SetPreferredCultures(ui); // Sign in FormsAuthentication.SetAuthCookie(ui.UserName, false); // Registered user has already started shopping as anonymous user -> Drop his stored shopping cart ShoppingCartInfoProvider.DeleteShoppingCartInfo(ui.UserID, siteName); // Assign current user to the current shopping cart ShoppingCart.User = ui; // Save changes to database // Already done in the end of this method if (!this.ShoppingCartControl.IsInternalOrder) { ShoppingCartInfoProvider.SetShoppingCartInfo(this.ShoppingCartInfObj); } //Create a customer for the user if do not yet exist CustomerInfo ci = CustomerInfoProvider.GetCustomerInfoByUserID(this.ShoppingCartControl.UserInfo.UserID); if (ci == null) { ci = new CustomerInfo(); ci.CustomerUserID = this.ShoppingCartControl.UserInfo.UserID; ci.CustomerEnabled = true; } // Old email address //string oldEmail = ci.CustomerEmail.ToLower(); ; ci.CustomerFirstName = ui.FirstName; ci.CustomerLastName = ui.LastName; ci.CustomerEmail = ui.Email; ci.CustomerCompany = ""; ci.CustomerOrganizationID = ""; ci.CustomerTaxRegistrationID = ""; // Update customer data CustomerInfoProvider.SetCustomerInfo(ci); // Set the shopping cart customer ID this.ShoppingCart.ShoppingCartCustomerID = ci.CustomerID; } else if (IsNewAccount()) { txtEmail2.Text = txtEmail2.Text.Trim(); pnlCompanyAccount1.Visible = chkCorporateBody.Checked; // Check if user exists UserInfo ui = UserInfoProvider.GetUserInfo(txtEmail2.Text); if (ui != null) { lblError.Visible = true; lblError.Text = GetString("ShoppingCartUserRegistration.ErrorUserExists"); return(false); } // Check all sites where user will be assigned string checkSites = (String.IsNullOrEmpty(ShoppingCartControl.AssignToSites)) ? SiteContext.CurrentSiteName : ShoppingCartControl.AssignToSites; if (!UserInfoProvider.IsEmailUnique(txtEmail2.Text.Trim(), checkSites, 0)) { lblError.Visible = true; lblError.Text = GetString("UserInfo.EmailAlreadyExist"); return(false); } // Create new customer and user account and sign in // User ui = new UserInfo(); ui.UserName = txtEmailRegistration.Text.Trim(); ui.Email = txtEmailRegistration.Text.Trim(); ui.FirstName = txtFirstName.Text.Trim(); ui.FullName = UserInfoProvider.GetFullName(txtFirstName.Text.Trim(), String.Empty, txtLastName.Text.Trim()); ui.LastName = txtLastName.Text.Trim(); ui.Enabled = true; ui.UserIsGlobalAdministrator = false; ui.UserURLReferrer = MembershipContext.AuthenticatedUser.URLReferrer; ui.UserCampaign = AnalyticsHelper.Campaign; ui.UserSettings.UserRegistrationInfo.IPAddress = RequestContext.UserHostAddress; ui.UserSettings.UserRegistrationInfo.Agent = HttpContext.Current.Request.UserAgent; try { UserInfoProvider.SetPassword(ui, txtMotDePasseRegistration.Text); string[] siteList; // If AssignToSites field set if (!String.IsNullOrEmpty(ShoppingCartControl.AssignToSites)) { siteList = ShoppingCartControl.AssignToSites.Split(';'); } else // If not set user current site { siteList = new string[] { siteName }; } foreach (string site in siteList) { UserInfoProvider.AddUserToSite(ui.UserName, site); // Add user to roles if (ShoppingCartControl.AssignToRoles != "") { AssignUserToRoles(ui.UserName, ShoppingCartControl.AssignToRoles, site); } } // Log registered user AnalyticsHelper.LogRegisteredUser(siteName, ui); Activity activity = new ActivityRegistration(ui, DocumentContext.CurrentDocument, AnalyticsContext.ActivityEnvironmentVariables); if (activity.Data != null) { activity.Data.ContactID = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui); activity.Log(); } } catch (Exception ex) { lblError.Visible = true; lblError.Text = ex.Message; return(false); } // Customer CustomerInfo ci = new CustomerInfo(); ci.CustomerFirstName = txtFirstName.Text.Trim(); ci.CustomerLastName = txtLastName.Text.Trim(); ci.CustomerEmail = txtEmailRegistration.Text.Trim(); ci.CustomerCompany = ""; ci.CustomerOrganizationID = ""; ci.CustomerTaxRegistrationID = ""; if (chkCorporateBody.Checked) { ci.CustomerCompany = txtCompany1.Text.Trim(); if (mShowOrganizationIDField) { ci.CustomerOrganizationID = txtOrganizationID.Text.Trim(); } if (mShowTaxRegistrationIDField) { ci.CustomerTaxRegistrationID = txtTaxRegistrationID.Text.Trim(); } } ci.CustomerUserID = ui.UserID; ci.CustomerSiteID = 0; ci.CustomerEnabled = true; ci.CustomerCreated = DateTime.Now; CustomerInfoProvider.SetCustomerInfo(ci); // Track successful registration conversion string name = ShoppingCartControl.RegistrationTrackConversionName; ECommerceHelper.TrackRegistrationConversion(ShoppingCart.SiteName, name); // Log "customer registration" activity and update profile var activityCustomerRegistration = new ActivityCustomerRegistration(ci, MembershipContext.AuthenticatedUser, AnalyticsContext.ActivityEnvironmentVariables); if (activityCustomerRegistration.Data != null) { if (ContactID <= 0) { activityCustomerRegistration.Data.ContactID = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui); } activityCustomerRegistration.Log(); } // Sign in if (ui.UserEnabled) { CMSContext.AuthenticateUser(ui.UserName, false); ShoppingCart.User = ui; ContactID = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui); Activity activity = new ActivityUserLogin(ContactID, ui, DocumentContext.CurrentDocument, AnalyticsContext.ActivityEnvironmentVariables); activity.Log(); } ShoppingCart.ShoppingCartCustomerID = ci.CustomerID; // Send new registration notification email if (ShoppingCartControl.SendNewRegistrationNotificationToAddress != "") { SendRegistrationNotification(ui); } /**aadrresse*/ // Process billing address //------------------------ int CountryID = ValidationHelper.GetInteger(ddlShippingCountry.SelectedValue, 0); AddressInfo ai = null; bool newAddress = true; ai = new AddressInfo(); string mCustomerName = ci.CustomerFirstName + " " + ci.CustomerLastName; // newAddress.AddressName = mCustomerName + " , " + txtAdresse.Text + " - " + txtCodePostale.Text + " " + txtVille.Text; ai.AddressPersonalName = mCustomerName + " , " + txtAdresse.Text + " - " + txtCodePostale.Text + " " + txtVille.Text; ai.AddressLine1 = txtAdresse.Text.Trim(); ai.AddressLine2 = txtAdresse.Text.Trim(); ai.AddressCity = txtVille.Text.Trim(); ai.AddressZip = txtCodePostale.Text.Trim(); ai.AddressCountryID = CountryID; if (newAddress) { ai.AddressIsBilling = true; ai.AddressIsShipping = !chkShippingAddr.Checked; ai.AddressEnabled = true; } ai.AddressCustomerID = ci.CustomerID; ai.AddressName = AddressInfoProvider.GetAddressName(ai); // Save address and set it's ID to ShoppingCartInfoObj AddressInfoProvider.SetAddressInfo(ai); // Update current contact's address ModuleCommands.OnlineMarketingMapAddress(ai, ContactID); ShoppingCart.ShoppingCartBillingAddressID = ai.AddressID; // If shopping cart does not need shipping if (!ShippingOptionInfoProvider.IsShippingNeeded(ShoppingCart)) { ShoppingCart.ShoppingCartShippingAddressID = 0; } // If shipping address is different from billing address else if (chkShippingAddr.Checked) { //// Check country presence //if (CountrySelector2.CountryID <= 0) //{ // lblError.Visible = true; // lblError.Text = GetString("countryselector.selectedcountryerr"); // return false; //} //if (!CountrySelector2.StateSelectionIsValid) //{ // lblError.Visible = true; // lblError.Text = GetString("countryselector.selectedstateerr"); // return false; //} //newAddress = false; //// Process shipping address ////------------------------- //ai = AddressInfoProvider.GetAddressInfo(Convert.ToInt32(drpShippingAddr.SelectedValue)); //if (ai == null) //{ // ai = new AddressInfo(); // newAddress = true; //} ai.AddressPersonalName = txtadresseshipping.Text.Trim(); ai.AddressLine1 = txtadresseshipping.Text.Trim(); ai.AddressLine2 = txtadresseshipping.Text.Trim(); ai.AddressCity = txtvilleshipping.Text.Trim(); ai.AddressZip = txtcpshipping.Text.Trim(); ai.AddressCountryID = CountryID; if (newAddress) { ai.AddressIsShipping = true; ai.AddressEnabled = true; ai.AddressIsBilling = false; ai.AddressIsCompany = false; ai.AddressEnabled = true; } ai.AddressCustomerID = ci.CustomerID; ai.AddressName = AddressInfoProvider.GetAddressName(ai); // Save address and set it's ID to ShoppingCartInfoObj AddressInfoProvider.SetAddressInfo(ai); ShoppingCart.ShoppingCartShippingAddressID = ai.AddressID; } // Shipping address is the same as billing address else { ShoppingCart.ShoppingCartShippingAddressID = ShoppingCart.ShoppingCartBillingAddressID; } /**finadrress*/ this.ShoppingCartControl.ButtonNextClickAction(); } try { if (!this.ShoppingCartControl.IsInternalOrder) { ShoppingCartInfoProvider.SetShoppingCartInfo(this.ShoppingCart); } return(true); } catch { return(false); } }
/// <summary> /// Process valid values of this step. /// </summary> public override bool ProcessStep() { if (plcAccount.Visible) { string siteName = SiteContext.CurrentSiteName; // Existing account if (radSignIn.Checked) { // Authenticate user UserInfo ui = AuthenticationHelper.AuthenticateUser(txtUsername.Text.Trim(), txtPsswd1.Text, SiteContext.CurrentSiteName, false); if (ui == null) { lblError.Text = GetString("ShoppingCartCheckRegistration.LoginFailed"); lblError.Visible = true; return(false); } // Sign in customer with existing account AuthenticationHelper.AuthenticateUser(ui.UserName, false); // Registered user has already started shopping as anonymous user -> Drop his stored shopping cart ShoppingCartInfoProvider.DeleteShoppingCartInfo(ui.UserID, siteName); // Assign current user to the current shopping cart ShoppingCart.User = ui; // Save changes to database if (!ShoppingCartControl.IsInternalOrder) { ShoppingCartInfoProvider.SetShoppingCartInfo(ShoppingCart); } // Log "login" activity MembershipActivityLogger.LogLogin(ui.UserName, DocumentContext.CurrentDocument); LoadStep(true); // Return false to get to Edit customer page return(false); } // New registration else if (radNewReg.Checked) { txtEmail2.Text = txtEmail2.Text.Trim(); pnlCompanyAccount1.Visible = chkCorporateBody.Checked; string[] siteList = { siteName }; // If AssignToSites field set if (!String.IsNullOrEmpty(ShoppingCartControl.AssignToSites)) { siteList = ShoppingCartControl.AssignToSites.Split(';'); } // Check if user exists UserInfo ui = UserInfoProvider.GetUserInfo(txtEmail2.Text); if (ui != null) { lblError.Visible = true; lblError.Text = GetString("ShoppingCartUserRegistration.ErrorUserExists"); return(false); } // Check all sites where user will be assigned if (!UserInfoProvider.IsEmailUnique(txtEmail2.Text.Trim(), siteList, 0)) { lblError.Visible = true; lblError.Text = GetString("UserInfo.EmailAlreadyExist"); return(false); } // Create new customer and user account and sign in // User ui = new UserInfo(); ui.UserName = txtEmail2.Text.Trim(); ui.Email = txtEmail2.Text.Trim(); ui.FirstName = txtFirstName1.Text.Trim(); ui.LastName = txtLastName1.Text.Trim(); ui.FullName = ui.FirstName + " " + ui.LastName; ui.Enabled = true; ui.SiteIndependentPrivilegeLevel = UserPrivilegeLevelEnum.None; ui.UserURLReferrer = CookieHelper.GetValue(CookieName.UrlReferrer); ui.UserCampaign = Service <ICampaignService> .Entry().CampaignCode; ui.UserSettings.UserRegistrationInfo.IPAddress = RequestContext.UserHostAddress; ui.UserSettings.UserRegistrationInfo.Agent = HttpContext.Current.Request.UserAgent; try { UserInfoProvider.SetPassword(ui, passStrength.Text); foreach (string site in siteList) { UserInfoProvider.AddUserToSite(ui.UserName, site); // Add user to roles if (ShoppingCartControl.AssignToRoles != "") { AssignUserToRoles(ui.UserName, ShoppingCartControl.AssignToRoles, site); } } // Log registered user AnalyticsHelper.LogRegisteredUser(siteName, ui); MembershipActivityLogger.LogRegistration(ui.UserName, DocumentContext.CurrentDocument); } catch (Exception ex) { lblError.Visible = true; lblError.Text = ex.Message; return(false); } // Customer CustomerInfo ci = new CustomerInfo(); ci.CustomerFirstName = txtFirstName1.Text.Trim(); ci.CustomerLastName = txtLastName1.Text.Trim(); ci.CustomerEmail = txtEmail2.Text.Trim(); ci.CustomerCompany = ""; ci.CustomerOrganizationID = ""; ci.CustomerTaxRegistrationID = ""; if (chkCorporateBody.Checked) { ci.CustomerCompany = txtCompany1.Text.Trim(); if (mShowOrganizationIDField) { ci.CustomerOrganizationID = txtOrganizationID.Text.Trim(); } if (mShowTaxRegistrationIDField) { ci.CustomerTaxRegistrationID = txtTaxRegistrationID.Text.Trim(); } } ci.CustomerUserID = ui.UserID; ci.CustomerSiteID = 0; ci.CustomerCreated = DateTime.Now; CustomerInfoProvider.SetCustomerInfo(ci); // Track successful registration conversion string name = ShoppingCartControl.RegistrationTrackConversionName; ECommerceHelper.TrackRegistrationConversion(ShoppingCart.SiteName, name); CreateContactRelation(ci); // Sign in if (ui.Enabled) { AuthenticationHelper.AuthenticateUser(ui.UserName, false); ShoppingCart.User = ui; MembershipActivityLogger.LogLogin(ui.UserName, DocumentContext.CurrentDocument); } ShoppingCart.ShoppingCartCustomerID = ci.CustomerID; // Send new registration notification email if (ShoppingCartControl.SendNewRegistrationNotificationToAddress != "") { SendRegistrationNotification(ui); } } // Anonymous customer else if (radAnonymous.Checked) { CustomerInfo ci = null; if (ShoppingCart.ShoppingCartCustomerID > 0) { // Update existing customer account ci = CustomerInfoProvider.GetCustomerInfo(ShoppingCart.ShoppingCartCustomerID); } if (ci == null) { // Create new customer account ci = new CustomerInfo(); } ci.CustomerFirstName = txtFirstName2.Text.Trim(); ci.CustomerLastName = txtLastName2.Text.Trim(); ci.CustomerEmail = txtEmail3.Text.Trim(); ci.CustomerCompany = ""; ci.CustomerOrganizationID = ""; ci.CustomerTaxRegistrationID = ""; if (chkCorporateBody2.Checked) { ci.CustomerCompany = txtCompany2.Text.Trim(); if (mShowOrganizationIDField) { ci.CustomerOrganizationID = txtOrganizationID2.Text.Trim(); } if (mShowTaxRegistrationIDField) { ci.CustomerTaxRegistrationID = txtTaxRegistrationID2.Text.Trim(); } } ci.CustomerCreated = DateTime.Now; ci.CustomerSiteID = SiteContext.CurrentSiteID; CustomerInfoProvider.SetCustomerInfo(ci); CreateContactRelation(ci); // Assign customer to shoppingcart ShoppingCart.ShoppingCartCustomerID = ci.CustomerID; } else { return(false); } } else { // Save the customer data bool newCustomer = false; CustomerInfo ci = CustomerInfoProvider.GetCustomerInfoByUserID(ShoppingCartControl.UserInfo.UserID); if (ci == null) { ci = new CustomerInfo(); ci.CustomerUserID = ShoppingCartControl.UserInfo.UserID; ci.CustomerSiteID = 0; newCustomer = true; } // Old email address string oldEmail = ci.CustomerEmail.ToLowerCSafe(); ci.CustomerFirstName = txtEditFirst.Text.Trim(); ci.CustomerLastName = txtEditLast.Text.Trim(); ci.CustomerEmail = txtEditEmail.Text.Trim(); pnlCompanyAccount2.Visible = chkEditCorpBody.Checked; ci.CustomerCompany = ""; ci.CustomerOrganizationID = ""; ci.CustomerTaxRegistrationID = ""; if (chkEditCorpBody.Checked) { ci.CustomerCompany = txtEditCompany.Text.Trim(); if (mShowOrganizationIDField) { ci.CustomerOrganizationID = txtEditOrgID.Text.Trim(); } if (mShowTaxRegistrationIDField) { ci.CustomerTaxRegistrationID = txtEditTaxRegID.Text.Trim(); } } // Update customer data CustomerInfoProvider.SetCustomerInfo(ci); // Update corresponding user email when required if (oldEmail != ci.CustomerEmail.ToLowerCSafe()) { UserInfo user = UserInfoProvider.GetUserInfo(ci.CustomerUserID); if (user != null) { user.Email = ci.CustomerEmail; UserInfoProvider.SetUserInfo(user); } } if (newCustomer) { CreateContactRelation(ci); } // Set the shopping cart customer ID ShoppingCart.ShoppingCartCustomerID = ci.CustomerID; } try { if (!ShoppingCartControl.IsInternalOrder) { ShoppingCartInfoProvider.SetShoppingCartInfo(ShoppingCart); } ShoppingCart.InvalidateCalculations(); return(true); } catch { return(false); } }
/// <summary> /// This method will do order processing /// </summary> /// <param name="openCampaignID"></param> /// <param name="campaignClosingUserID"></param> /// <returns></returns> private string GenerateOrder(int openCampaignID, int campaignClosingUserID) { try { var shoppingCartInfo = DIContainer.Resolve <IShoppingCartProvider>(); var addrerss = DIContainer.Resolve <IAddressBookService>(); var userInfo = DIContainer.Resolve <IKenticoUserProvider>(); var kenticoResourceService = DIContainer.Resolve <IKenticoResourceService>(); var usersWithShoppingCartItems = shoppingCartInfo.GetUserIDsWithShoppingCart(openCampaignID, Convert.ToInt32(ProductsType.PreBuy)); var orderTemplateSettingKey = kenticoResourceService.GetSettingsKey("KDA_OrderReservationEmailTemplate"); var failedOrderTemplateSettingKey = kenticoResourceService.GetSettingsKey("KDA_FailedOrdersEmailTemplate"); var failedOrdersUrl = kenticoResourceService.GetSettingsKey("KDA_FailedOrdersPageUrl"); var unprocessedDistributorIDs = new List <Tuple <int, string> >(); usersWithShoppingCartItems.ForEach(shoppingCartUser => { var salesPerson = userInfo.GetUserByUserId(shoppingCartUser); var loggedInUserCartIDs = ShoppingCartHelper.GetCartsByUserID(shoppingCartUser, ProductType.PreBuy, openCampaignID); loggedInUserCartIDs.ForEach(cart => { var shippingCost = default(decimal); Cart = ShoppingCartInfoProvider.GetShoppingCartInfo(cart); OrderDTO ordersDTO = ShoppingCartHelper.CreateOrdersDTO(Cart, Cart.ShoppingCartUserID, OrderType.prebuy, shippingCost); var response = ShoppingCartHelper.ProcessOrder(Cart, Cart.ShoppingCartUserID, OrderType.prebuy, ordersDTO, shippingCost); if (response != null && response.Success) { ordersDTO.OrderID = response.Payload; ProductEmailNotifications.SendMail(salesPerson, ordersDTO, orderTemplateSettingKey); InBoundFormHelper.InsertIBFForm(ordersDTO); ShoppingCartInfoProvider.DeleteShoppingCartInfo(Cart); ShoppingCartHelper.UpdateRemainingBudget(ordersDTO, salesPerson.UserId); DIContainer.Resolve <IIBTFService>().InsertIBTFAdjustmentRecord(ordersDTO); } else { unprocessedDistributorIDs.Add(new Tuple <int, string>(Cart.GetIntegerValue("ShoppingCartDistributorID", default(int)), response.ErrorMessages)); } }); }); var distributors = addrerss.GetAddressesByAddressIds(unprocessedDistributorIDs.Select(x => x.Item1).ToList()).Select(x => { return(new { AddressID = x?.Id, AddressPersonalName = x?.AddressPersonalName }); }).ToList(); var listofFailedOrders = unprocessedDistributorIDs.Select(x => { var distributor = distributors.Where(y => y.AddressID == x.Item1).FirstOrDefault(); return(new { Name = distributor.AddressPersonalName, Reason = x.Item2 }); }).ToList(); var user = userInfo.GetUserByUserId(campaignClosingUserID); if (user?.Email != null && listofFailedOrders.Count > 0) { Dictionary <string, object> failedOrderData = new Dictionary <string, object>(); failedOrderData.Add("failedorderurl", URLHelper.AddHTTPToUrl($"{SiteContext.CurrentSite.DomainName}{failedOrdersUrl}?campid={openCampaignID}")); failedOrderData.Add("failedordercount", listofFailedOrders.Count); failedOrderData.Add("failedorders", listofFailedOrders); ProductEmailNotifications.SendEmailNotification(failedOrderTemplateSettingKey, user.Email, listofFailedOrders, "failedOrders", failedOrderData); UpdatetFailedOrders(openCampaignID, true); } return(ResHelper.GetString("KDA.OrderSchedular.TaskSuccessfulMessage")); } catch (Exception ex) { EventLogProvider.LogException("GeneratePrebuyOrderTask", "GenerateOrder", ex, SiteContext.CurrentSiteID, ex.Message); return(ex.Message); } }
/// <summary> /// Process valid values of this step. /// </summary> public override bool ProcessStep() { if (plcAccount.Visible) { string siteName = CMSContext.CurrentSiteName; // Existing account if (radSignIn.Checked) { // Authenticate user UserInfo ui = AuthenticationHelper.AuthenticateUser(txtUsername.Text.Trim(), txtPsswd1.Text, CMSContext.CurrentSiteName, false); if (ui == null) { lblError.Text = GetString("ShoppingCartCheckRegistration.LoginFailed"); lblError.Visible = true; return(false); } // Sign in customer with existing account CMSContext.AuthenticateUser(ui.UserName, false); // Registered user has already started shopping as anonymous user -> Drop his stored shopping cart ShoppingCartInfoProvider.DeleteShoppingCartInfo(ui.UserID, siteName); // Assign current user to the current shopping cart ShoppingCart.User = ui; // Save changes to database if (!ShoppingCartControl.IsInternalOrder) { ShoppingCartInfoProvider.SetShoppingCartInfo(ShoppingCart); } // Log "login" activity ContactID = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui); Activity activity = new ActivityUserLogin(ContactID, ui, CMSContext.CurrentDocument, CMSContext.ActivityEnvironmentVariables); activity.Log(); LoadStep(true); // Return false to get to Edit customer page return(false); } // New registration else if (radNewReg.Checked) { txtEmail2.Text = txtEmail2.Text.Trim(); pnlCompanyAccount1.Visible = chkCorporateBody.Checked; // Check if user exists UserInfo ui = UserInfoProvider.GetUserInfo(txtEmail2.Text); if (ui != null) { lblError.Visible = true; lblError.Text = GetString("ShoppingCartUserRegistration.ErrorUserExists"); return(false); } // Check all sites where user will be assigned string checkSites = (String.IsNullOrEmpty(ShoppingCartControl.AssignToSites)) ? CMSContext.CurrentSiteName : ShoppingCartControl.AssignToSites; if (!UserInfoProvider.IsEmailUnique(txtEmail2.Text.Trim(), checkSites, 0)) { lblError.Visible = true; lblError.Text = GetString("UserInfo.EmailAlreadyExist"); return(false); } // Create new customer and user account and sign in // User ui = new UserInfo(); ui.UserName = txtEmail2.Text.Trim(); ui.Email = txtEmail2.Text.Trim(); ui.FirstName = txtFirstName1.Text.Trim(); ui.LastName = txtLastName1.Text.Trim(); ui.FullName = ui.FirstName + " " + ui.LastName; ui.Enabled = true; ui.UserIsGlobalAdministrator = false; ui.UserURLReferrer = CMSContext.CurrentUser.URLReferrer; ui.UserCampaign = CMSContext.Campaign; ui.UserSettings.UserRegistrationInfo.IPAddress = HTTPHelper.UserHostAddress; ui.UserSettings.UserRegistrationInfo.Agent = HttpContext.Current.Request.UserAgent; try { UserInfoProvider.SetPassword(ui, passStrength.Text); string[] siteList; // If AssignToSites field set if (!String.IsNullOrEmpty(ShoppingCartControl.AssignToSites)) { siteList = ShoppingCartControl.AssignToSites.Split(';'); } else // If not set user current site { siteList = new string[] { siteName }; } foreach (string site in siteList) { UserInfoProvider.AddUserToSite(ui.UserName, site); // Add user to roles if (ShoppingCartControl.AssignToRoles != "") { AssignUserToRoles(ui.UserName, ShoppingCartControl.AssignToRoles, site); } } // Log registered user AnalyticsHelper.LogRegisteredUser(siteName, ui); Activity activity = new ActivityRegistration(ui, CMSContext.CurrentDocument, CMSContext.ActivityEnvironmentVariables); if (activity.Data != null) { activity.Data.ContactID = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui); activity.Log(); } } catch (Exception ex) { lblError.Visible = true; lblError.Text = ex.Message; return(false); } // Customer CustomerInfo ci = new CustomerInfo(); ci.CustomerFirstName = txtFirstName1.Text.Trim(); ci.CustomerLastName = txtLastName1.Text.Trim(); ci.CustomerEmail = txtEmail2.Text.Trim(); ci.CustomerCompany = ""; ci.CustomerOrganizationID = ""; ci.CustomerTaxRegistrationID = ""; if (chkCorporateBody.Checked) { ci.CustomerCompany = txtCompany1.Text.Trim(); if (mShowOrganizationIDField) { ci.CustomerOrganizationID = txtOrganizationID.Text.Trim(); } if (mShowTaxRegistrationIDField) { ci.CustomerTaxRegistrationID = txtTaxRegistrationID.Text.Trim(); } } ci.CustomerUserID = ui.UserID; ci.CustomerSiteID = 0; ci.CustomerEnabled = true; ci.CustomerCreated = DateTime.Now; CustomerInfoProvider.SetCustomerInfo(ci); // Track successful registration conversion string name = ShoppingCartControl.RegistrationTrackConversionName; ECommerceHelper.TrackRegistrationConversion(ShoppingCart.SiteName, name); // Log "customer registration" activity and update profile var activityCustomerRegistration = new ActivityCustomerRegistration(ci, CMSContext.CurrentUser, CMSContext.ActivityEnvironmentVariables); if (activityCustomerRegistration.Data != null) { if (ContactID <= 0) { activityCustomerRegistration.Data.ContactID = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui); } activityCustomerRegistration.Log(); } // Sign in if (ui.UserEnabled) { CMSContext.AuthenticateUser(ui.UserName, false); ShoppingCart.User = ui; ContactID = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui); Activity activity = new ActivityUserLogin(ContactID, ui, CMSContext.CurrentDocument, CMSContext.ActivityEnvironmentVariables); activity.Log(); } ShoppingCart.ShoppingCartCustomerID = ci.CustomerID; // Send new registration notification email if (ShoppingCartControl.SendNewRegistrationNotificationToAddress != "") { SendRegistrationNotification(ui); } } // Anonymous customer else if (radAnonymous.Checked) { CustomerInfo ci = null; if (ShoppingCart.ShoppingCartCustomerID > 0) { // Update existing customer account ci = CustomerInfoProvider.GetCustomerInfo(ShoppingCart.ShoppingCartCustomerID); } if (ci == null) { // Create new customer account ci = new CustomerInfo(); } ci.CustomerFirstName = txtFirstName2.Text.Trim(); ci.CustomerLastName = txtLastName2.Text.Trim(); ci.CustomerEmail = txtEmail3.Text.Trim(); ci.CustomerCompany = ""; ci.CustomerOrganizationID = ""; ci.CustomerTaxRegistrationID = ""; if (chkCorporateBody2.Checked) { ci.CustomerCompany = txtCompany2.Text.Trim(); if (mShowOrganizationIDField) { ci.CustomerOrganizationID = txtOrganizationID2.Text.Trim(); } if (mShowTaxRegistrationIDField) { ci.CustomerTaxRegistrationID = txtTaxRegistrationID2.Text.Trim(); } } ci.CustomerEnabled = true; ci.CustomerCreated = DateTime.Now; ci.CustomerSiteID = CMSContext.CurrentSiteID; CustomerInfoProvider.SetCustomerInfo(ci); // Log "customer registration" activity var activity = new ActivityCustomerRegistration(ci, CMSContext.CurrentUser, CMSContext.ActivityEnvironmentVariables); if (activity.Data != null) { ContactID = ModuleCommands.OnlineMarketingGetCurrentContactID(); activity.Data.ContactID = ContactID; activity.Log(); } // Assign customer to shoppingcart ShoppingCart.ShoppingCartCustomerID = ci.CustomerID; } else { return(false); } } else { // Save the customer data bool newCustomer = false; CustomerInfo ci = CustomerInfoProvider.GetCustomerInfoByUserID(ShoppingCartControl.UserInfo.UserID); if (ci == null) { ci = new CustomerInfo(); ci.CustomerUserID = ShoppingCartControl.UserInfo.UserID; ci.CustomerSiteID = 0; ci.CustomerEnabled = true; newCustomer = true; } // Old email address string oldEmail = ci.CustomerEmail.ToLowerCSafe(); ci.CustomerFirstName = txtEditFirst.Text.Trim(); ci.CustomerLastName = txtEditLast.Text.Trim(); ci.CustomerEmail = txtEditEmail.Text.Trim(); pnlCompanyAccount2.Visible = chkEditCorpBody.Checked; ci.CustomerCompany = ""; ci.CustomerOrganizationID = ""; ci.CustomerTaxRegistrationID = ""; if (chkEditCorpBody.Checked) { ci.CustomerCompany = txtEditCompany.Text.Trim(); if (mShowOrganizationIDField) { ci.CustomerOrganizationID = txtEditOrgID.Text.Trim(); } if (mShowTaxRegistrationIDField) { ci.CustomerTaxRegistrationID = txtEditTaxRegID.Text.Trim(); } } // Update customer data CustomerInfoProvider.SetCustomerInfo(ci); // Update corresponding user email when required if (oldEmail != ci.CustomerEmail.ToLowerCSafe()) { UserInfo user = UserInfoProvider.GetUserInfo(ci.CustomerUserID); if (user != null) { user.Email = ci.CustomerEmail; UserInfoProvider.SetUserInfo(user); } } // Log "customer registration" activity and update contact profile if (newCustomer) { var activity = new ActivityCustomerRegistration(ci, CMSContext.CurrentUser, CMSContext.ActivityEnvironmentVariables); activity.Log(); } // Set the shopping cart customer ID ShoppingCart.ShoppingCartCustomerID = ci.CustomerID; } try { if (!ShoppingCartControl.IsInternalOrder) { ShoppingCartInfoProvider.SetShoppingCartInfo(ShoppingCart); } return(true); } catch { return(false); } }
/// <summary> /// Deletes a shopping cart from the database. /// </summary> /// <param name="cart">Shopping cart (<see cref="ShoppingCart"/>) that is deleted.</param> public virtual void DeleteShoppingCart(ShoppingCart cart) { ShoppingCartInfoProvider.DeleteShoppingCartInfo(cart.OriginalCart); }
public void ClearCart(int shoppingCartId = 0) { var shoppingCart = GetShoppingCart(shoppingCartId); ShoppingCartInfoProvider.DeleteShoppingCartInfo(shoppingCart); }
/// <summary> /// Chekcou click event for order processing /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void lnkCheckout_Click(object sender, EventArgs e) { try { if (!DIContainer.Resolve <IShoppingCartProvider>().ValidateAllCarts(userID: CurrentUser.UserID)) { Response.Cookies["status"].Value = QueryStringStatus.InvalidCartItems; Response.Cookies["status"].HttpOnly = false; return; } var loggedInUserCartIDs = GetCartsByUserID(CurrentUser.UserID, ProductType.GeneralInventory, OpenCampaign?.CampaignID); settingKeys = DIContainer.Resolve <IKenticoResourceService>(); var orderTemplateSettingKey = settingKeys.GetSettingsKey("KDA_OrderReservationEmailTemplateGI"); var unprocessedDistributorIDs = new List <Tuple <int, string> >(); var userInfo = DIContainer.Resolve <IKenticoUserProvider>(); var salesPerson = userInfo.GetUserByUserId(CurrentUser.UserID); loggedInUserCartIDs.ForEach(distributorCart => { Cart = ShoppingCartInfoProvider.GetShoppingCartInfo(distributorCart); decimal shippingCost = default(decimal); if (Cart.ShippingOption != null && Cart.ShippingOption.ShippingOptionName.ToLower() != ShippingOption.Ground) { var shippingResponse = GetOrderShippingTotal(Cart); if (shippingResponse != null && shippingResponse.Success) { shippingCost = ValidationHelper.GetDecimal(shippingResponse?.Payload?.Cost, default(decimal)); } else { unprocessedDistributorIDs.Add(new Tuple <int, string>(Cart.GetIntegerValue("ShoppingCartDistributorID", default(int)), shippingResponse.ErrorMessages)); return; } } OrderDTO ordersDTO = CreateOrdersDTO(Cart, Cart.ShoppingCartUserID, OrderType.generalInventory, shippingCost); var response = ProcessOrder(Cart, CurrentUser.UserID, OrderType.generalInventory, ordersDTO, shippingCost); if (response != null && response.Success) { UpdateAvailableSKUQuantity(Cart); UpdateAllocatedProductQuantity(Cart, salesPerson.UserId); ProductEmailNotifications.SendMail(salesPerson, ordersDTO, orderTemplateSettingKey); ShoppingCartInfoProvider.DeleteShoppingCartInfo(Cart); ShoppingCartHelper.UpdateRemainingBudget(ordersDTO, CurrentUser.UserID); } else { unprocessedDistributorIDs.Add(new Tuple <int, string>(Cart.GetIntegerValue("ShoppingCartDistributorID", default(int)), response.ErrorMessages)); } }); if (unprocessedDistributorIDs.Count == 0) { Response.Cookies["status"].Value = QueryStringStatus.OrderSuccess; Response.Cookies["status"].HttpOnly = false; URLHelper.Redirect(Request.RawUrl); } else { if (loggedInUserCartIDs.Count > unprocessedDistributorIDs.Count) { Response.Cookies["status"].Value = QueryStringStatus.OrderSuccess; Response.Cookies["status"].HttpOnly = false; } Response.Cookies["error"].Value = QueryStringStatus.OrderFail; Response.Cookies["error"].HttpOnly = false; ShowOrderErrorList(unprocessedDistributorIDs); divErrorDailogue.Attributes.Add("class", "dialog active"); } } catch (Exception ex) { EventLogProvider.LogInformation("Kadena_CMSWebParts_Kadena_Cart_CartCheckout", "lnkCheckout_Click", ex.Message); } }