internal static BillingShippingUserInfo LoadDataFromSitefinityProfile() { User user = SecurityManager.GetUser(SecurityManager.GetCurrentUserId()); if (user != null) { var sitefinityProfile = UserProfileHelper.GetSitefinityProfileOfUser(user); if (sitefinityProfile != null) { var billingShippingUserInfo = new BillingShippingUserInfo(); billingShippingUserInfo.BillingFirstName = sitefinityProfile.FirstName; billingShippingUserInfo.BillingLastName = sitefinityProfile.LastName; billingShippingUserInfo.ShippingFirstName = sitefinityProfile.FirstName; billingShippingUserInfo.ShippingLastName = sitefinityProfile.LastName; billingShippingUserInfo.BillingEmail = sitefinityProfile.User.Email; billingShippingUserInfo.ShippingEmail = sitefinityProfile.User.Email; return(billingShippingUserInfo); } } return(null); }
internal static void SaveCustomerAddressOfCurrentUser(CheckoutState checkoutState, Customer customer) { checkoutState.SaveCustomerAddress(UserProfileHelper.GetCurrentlyLoggedInUser(), customer); }
internal static IPaymentResponse PlaceOrder(OrdersManager ordersManager, CatalogManager catalogManager, UserManager userManager, RoleManager roleManager, UserProfileManager userProfileManager, CheckoutState checkoutState, Guid cartOrderId) { CartOrder cartOrder = ordersManager.GetCartOrder(cartOrderId); cartOrder.Addresses.Clear(); cartOrder.Payments.Clear(); //set the default currency of the order string defaultCurrency = Config.Get <EcommerceConfig>().DefaultCurrency; cartOrder.Currency = defaultCurrency; // set the shipping address CartAddress shippingAddress = CartHelper.GetShippingAddressFromCheckoutState(ordersManager, checkoutState); cartOrder.Addresses.Add(shippingAddress); // set the billing address CartAddress billingAddress = CartHelper.GetBillingAddressFromCheckoutState(ordersManager, checkoutState); cartOrder.Addresses.Add(billingAddress); //Get the first payment method in the shop // set the payment CartPayment payment = CartHelper.GetCartPaymentFromCheckoutState(ordersManager, checkoutState); cartOrder.Payments.Add(payment); ordersManager.SaveChanges(); // Get current customer or create new one Customer customer = UserProfileHelper.GetCustomerInfoOrCreateOneIfDoesntExsist(userProfileManager, ordersManager, checkoutState); // Save the customer address CustomerAddressHelper.SaveCustomerAddressOfCurrentUser(checkoutState, customer); //Use the API to checkout IPaymentResponse paymentResponse = ordersManager.Checkout(cartOrderId, checkoutState, customer); // record the "success" state of the checkout checkoutState.IsPaymentSuccessful = paymentResponse.IsSuccess; Order order = ordersManager.GetOrder(cartOrderId); //Increment the order IncrementOrderNumber(ordersManager, order); // add the order to customer customer.Orders.Add(order); // Update the order order.Customer = customer; ordersManager.SaveChanges(); if (order.OrderStatus == OrderStatus.Paid) { UserProfileHelper.AssignCustomerToRoles(userManager, roleManager, catalogManager, SecurityManager.GetCurrentUserId(), order); EmailHelper.SendOrderPlacedEmailToClientAndMerchant(cartOrder, checkoutState, order.OrderNumber); } return(paymentResponse); }