Exemple #1
0
 public AccountManager(CustomerServiceProvider customerServiceProvider, ContactFactory contactFactory, MailManager mailManager, StorefrontContext storefrontContext)
 {
     CustomerServiceProvider = customerServiceProvider;
     ContactFactory          = contactFactory;
     MailManager             = mailManager;
     StorefrontContext       = storefrontContext;
 }
 public RegisterCommerceCustomer(ICartManager cartManager, IConnectServiceProvider connectServiceProvider, IStorefrontContext storefrontContext, IVisitorContext visitorContext)
 {
     _cartManager             = cartManager;
     _storefrontContext       = storefrontContext;
     _customerServiceProvider = connectServiceProvider.GetCustomerServiceProvider();
     _visitorContext          = visitorContext;
 }
        public AccountManager(IConnectServiceProvider connectServiceProvider, ILogService <CommonLog> logService)
            : base(logService)
        {
            Assert.ArgumentNotNull(connectServiceProvider, nameof(connectServiceProvider));

            this.customerServiceProvider = connectServiceProvider.GetCustomerServiceProvider();
        }
Exemple #4
0
        public ManagerResponse <CreateUserResult, CommerceUser> RegisterUserCustomer(IStorefrontContext storefrontContext, string userName, string password,
                                                                                     string email, string secondaryEmail)
        {
            Assert.ArgumentNotNull(storefrontContext, nameof(storefrontContext));
            Assert.ArgumentNotNullOrEmpty(userName, nameof(userName));
            Assert.ArgumentNotNullOrEmpty(password, nameof(password));
            CreateUserResult createUserResult1;

            try
            {
                var createUserRequest = new CreateUserRequest(userName, password, email, storefrontContext.CurrentStorefront.ShopName);
                createUserRequest.Properties.Add("SecondEmail", secondaryEmail);
                createUserResult1 = CustomerServiceProvider.CreateUser(createUserRequest);
                //createUserResult1 = CustomerServiceProvider.CreateUser(new CreateUserRequest(userName, password, email, storefrontContext.CurrentStorefront.ShopName));
                if (!createUserResult1.Success)
                {
                    Helpers.LogSystemMessages(createUserResult1.SystemMessages, createUserResult1);
                }
                else if (createUserResult1.Success)
                {
                    if (createUserResult1.CommerceUser == null)
                    {
                        if (createUserResult1.SystemMessages.Count == 0)
                        {
                            createUserResult1.Success = false;
                            createUserResult1.SystemMessages.Add(new SystemMessage()
                            {
                                Message = storefrontContext.GetSystemMessage("User Already Exists")
                            });
                        }
                    }
                }
            }
            catch (MembershipCreateUserException ex)
            {
                CreateUserResult createUserResult2 = new CreateUserResult {
                    Success = false
                };
                createUserResult1 = createUserResult2;
                createUserResult1.SystemMessages.Add(new SystemMessage()
                {
                    Message = ErrorCodeToString(storefrontContext, ex.StatusCode)
                });
            }
            catch (Exception ex)
            {
                CreateUserResult createUserResult2 = new CreateUserResult {
                    Success = false
                };
                createUserResult1 = createUserResult2;
                createUserResult1.SystemMessages.Add(new SystemMessage()
                {
                    Message = storefrontContext.GetSystemMessage("Unknown Membership Provider Error")
                });
            }
            CreateUserResult serviceProviderResult = createUserResult1;

            return(new ManagerResponse <CreateUserResult, CommerceUser>(serviceProviderResult, serviceProviderResult.CommerceUser));
        }
        public AccountManager(IConnectServiceProvider connectServiceProvider, ICartManager cartManager)
        {
            Assert.ArgumentNotNull(connectServiceProvider, nameof(connectServiceProvider));
            Assert.ArgumentNotNull(cartManager, nameof(cartManager));

            this.customerServiceProvider = connectServiceProvider.GetCustomerServiceProvider();
            this.cartManager             = cartManager;
        }
Exemple #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AccountManager" /> class.
        /// </summary>
        /// <param name="cartManager">The cart manager.</param>
        /// <param name="customerServiceProvider">The customer service provider.</param>
        /// <param name="contactFactory">The contact factory.</param>
        public AccountManager(CartManager cartManager, [NotNull] CustomerServiceProvider customerServiceProvider, [NotNull] ContactFactory contactFactory)
        {
            Assert.ArgumentNotNull(customerServiceProvider, "customerServiceProvider");
            Assert.ArgumentNotNull(contactFactory, "contactFactory");

            this.CartManager             = cartManager;
            this.CustomerServiceProvider = customerServiceProvider;
            this.ContactFactory          = contactFactory;
        }
Exemple #7
0
        public ActionResult CreateUser()
        {
            var customerService = new CustomerServiceProvider();

            var request = new CreateUserRequest("CommerceUsers\\[email protected]", "password", "*****@*****.**", "CommerceEngineDefaultStorefront");

            var result = customerService.CreateUser(request);

            return(View(result));
        }
Exemple #8
0
        public ManagerResponse <GetPartiesResult, IEnumerable <IParty> > GetParties(CommerceCustomer customer)
        {
            Assert.ArgumentNotNull(customer, nameof(customer));

            var request   = new GetPartiesRequest(customer);
            var result    = CustomerServiceProvider.GetParties(request);
            var partyList = result.Success && result.Parties != null?result.Parties.Select(p => p.ToEntity()) : new List <IParty>();

            result.WriteToSitecoreLog();
            return(new ManagerResponse <GetPartiesResult, IEnumerable <IParty> >(result, partyList));
        }
Exemple #9
0
        public ManagerResponse <CustomerResult, bool> RemoveParties(CommerceCustomer user, List <CommerceParty> parties)
        {
            Assert.ArgumentNotNull(user, nameof(user));
            Assert.ArgumentNotNull(parties, nameof(parties));

            var request = new RemovePartiesRequest(user, parties.Cast <Party>().ToList());
            var result  = CustomerServiceProvider.RemoveParties(request);

            result.WriteToSitecoreLog();
            return(new ManagerResponse <CustomerResult, bool>(result, result.Success));
        }
Exemple #10
0
        public AccountManagerTests()
        {
            var connectServiceProvider = Substitute.For <IConnectServiceProvider>();
            var logService             = Substitute.For <ILogService <CommonLog> >();

            this.customerServiceProvider = Substitute.For <CustomerServiceProvider>();
            connectServiceProvider.GetCustomerServiceProvider().Returns(this.customerServiceProvider);

            this.accountManager = Substitute.For <AccountManager>(connectServiceProvider, logService);

            this.fixture = new Fixture();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CartService" /> class.
        /// </summary>
        /// <param name="cartServiceProvider">The service provider.</param>
        /// <param name="wishListServiceProvider">The wish list service provider.</param>
        /// <param name="pricingServiceProvider">The pricing service provider.</param>
        /// <param name="shopName">Name of the shop.</param>
        /// <param name="contactFactory">The visitor factory.</param>
        /// <param name="inventoryServiceProvider">The inventory service provider.</param>
        /// <param name="customerServiceProvider">The customer service provider.</param>
        public CartService([NotNull] CartServiceProvider cartServiceProvider, [NotNull] WishListServiceProvider wishListServiceProvider, [NotNull] PricingServiceProvider pricingServiceProvider, [NotNull] string shopName, ContactFactory contactFactory, [NotNull] InventoryServiceProvider inventoryServiceProvider, [NotNull] CustomerServiceProvider customerServiceProvider)
        {
            Assert.ArgumentNotNull(cartServiceProvider, "cartServiceProvider");
            Assert.ArgumentNotNull(wishListServiceProvider, "wishListServiceProvider");
            Assert.ArgumentNotNull(pricingServiceProvider, "pricingServiceProvider");
            Assert.ArgumentNotNull(customerServiceProvider, "customerServiceProvider");
            Assert.ArgumentNotNullOrEmpty(shopName, "shopName");

            this._cartServiceProvider    = cartServiceProvider;
            this._pricingServiceProvider = pricingServiceProvider;
            this.shopName                  = shopName;
            this.contactFactory            = contactFactory;
            this._inventoryServiceProvider = inventoryServiceProvider;
            this._customerServiceProvider  = customerServiceProvider;
            this._wishListServiceProvider  = wishListServiceProvider;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CartsServiceTest"/> class.
        /// </summary>
        public CartsServiceTest()
        {
            this.cart = new Cart();
            this.cartFromAnonymous = new Cart();

            this.result = new CartResult {
                Cart = this.cart
            };
            this.resultFromAnonymous = new CartResult {
                Cart = this.cartFromAnonymous
            };

            this.cartServiceProvider = Substitute.For <CartServiceProvider>();
            this.cartServiceProvider.CreateOrResumeCart(Arg.Is <CreateOrResumeCartRequest>(r => r.UserId == "John Carter")).Returns(this.result);

            var pricesResult = new GetProductPricesResult();

            pricesResult.Prices.Add("List", new Price(0, "USD"));
            this.pricingService = Substitute.For <PricingServiceProvider>();
            this.pricingService.GetProductPrices(Arg.Any <GetProductPricesRequest>()).Returns(pricesResult);

            this.contactId = Guid.NewGuid();
            this.cartServiceProvider.CreateOrResumeCart(Arg.Is <CreateOrResumeCartRequest>(r => r.UserId == ID.Parse(this.contactId).ToString())).Returns(this.resultFromAnonymous);

            this.cartServiceProvider.GetCarts(Arg.Any <GetCartsRequest>()).Returns(new GetCartsResult {
                Carts = Enumerable.Empty <CartBase>()
            });
            this.contactFactory = Substitute.For <ContactFactory>();
            this.contactFactory.GetContact().Returns("John Carter");

            var inventoryResult = new GetStockInformationResult();

            inventoryResult.StockInformation.ToList().Add(new StockInformation {
                Product = new InventoryProduct {
                    ProductId = "1001"
                }, Status = StockStatus.InStock
            });
            this._inventoryService = Substitute.For <InventoryServiceProvider>();
            this._inventoryService.GetStockInformation(Arg.Any <GetStockInformationRequest>()).Returns(inventoryResult);

            this._customerService = Substitute.For <CustomerServiceProvider>();

            this._wishListServiceProvider = Substitute.For <WishListServiceProvider>();

            this.service = new CartService(this.cartServiceProvider, this._wishListServiceProvider, this.pricingService, "autohaus", this.contactFactory, this._inventoryService, this._customerService);
        }
Exemple #13
0
        public ManagerResponse <UpdateUserResult, CommerceUser> UpdateUser(string userName, ProfileModel inputModel)
        {
            Assert.ArgumentNotNull(inputModel, nameof(inputModel));

            UpdateUserResult result;

            var commerceUser = GetUser(userName).Result;

            if (commerceUser != null)
            {
                commerceUser.FirstName = inputModel.FirstName;
                commerceUser.LastName  = inputModel.LastName;
                commerceUser.Email     = inputModel.Email;
                commerceUser.SetPropertyValue("Phone", inputModel.TelephoneNumber);

                try
                {
                    var request = new UpdateUserRequest(commerceUser);
                    result = CustomerServiceProvider.UpdateUser(request);
                }
                catch (Exception ex)
                {
                    result = new UpdateUserResult {
                        Success = false
                    };
                    result.SystemMessages.Add(new SystemMessage {
                        Message = ex.Message + "/" + ex.StackTrace
                    });
                }
            }
            else
            {
                // user is authenticated, but not in the CommerceUsers domain - probably here because we are in edit or preview mode
                var message = DictionaryPhraseRepository.Current.Get("/System Messages/Account Manager/Update User Profile Error", "Cannot update profile details for user {0}.");
                message = string.Format(message, Context.User.LocalName);
                result  = new UpdateUserResult {
                    Success = false
                };
                result.SystemMessages.Add(new SystemMessage {
                    Message = message
                });
            }

            result.WriteToSitecoreLog();
            return(new ManagerResponse <UpdateUserResult, CommerceUser>(result, result.CommerceUser));
        }
Exemple #14
0
        public ManagerResponse <GetUserResult, CommerceUser> GetUser(string userName)
        {
            Assert.ArgumentNotNullOrEmpty(userName, nameof(userName));

            var request = new GetUserRequest(userName);
            var result  = CustomerServiceProvider.GetUser(request);

            if (!result.Success || result.CommerceUser == null)
            {
                var message = DictionaryPhraseRepository.Current.Get("/System Messages/Account Manager/User Not Found Error", "The email address does not exists");
                result.SystemMessages.Add(new SystemMessage {
                    Message = message
                });
            }

            result.WriteToSitecoreLog();
            return(new ManagerResponse <GetUserResult, CommerceUser>(result, result.CommerceUser));
        }
Exemple #15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CheckoutService"/> class.
        /// </summary>
        /// <param name="shippingServiceProvider">The shipping service provider.</param>
        /// <param name="paymentServiceProvider">The payment service provider.</param>
        /// <param name="customerServiceProvider">The customer service provider.</param>
        /// <param name="cartService">The cart service.</param>
        /// <param name="shopName">The shop name.</param>
        public CheckoutService(
            [NotNull] ShippingServiceProvider shippingServiceProvider,
            [NotNull] PaymentServiceProvider paymentServiceProvider,
            [NotNull] CustomerServiceProvider customerServiceProvider,
            [NotNull] ICartService cartService,
            [NotNull] string shopName)
        {
            Assert.ArgumentNotNull(shippingServiceProvider, "shippingServiceProvider");
            Assert.ArgumentNotNull(paymentServiceProvider, "paymentServiceProvider");
            Assert.ArgumentNotNull(customerServiceProvider, "customerServiceProvider");
            Assert.ArgumentNotNull(cartService, "cartService");
            Assert.ArgumentNotNullOrEmpty(shopName, "shopName");

            this._shippingServiceProvider = shippingServiceProvider;
            this._paymentServiceProvider  = paymentServiceProvider;
            this._customerServiceProvider = customerServiceProvider;
            this._cartService             = cartService;
            this.shopName = shopName;
        }
        public PipelineExecutionResult Execute(IPipelineArgs <CreateCustomerRequest, CreateCustomerResponse> subject)
        {
            if (subject.Response.Customer == null)
            {
                throw new ArgumentException();
            }

            var commerceCustomer = _customerToCustomer.Map(subject.Response.Customer);

            var customerService = new CustomerServiceProvider();

            var createCustomerRequest = new global::Sitecore.Commerce.Services.Customers.CreateCustomerRequest(commerceCustomer);

            createCustomerRequest.Properties["FromUCommerce"] = true;

            customerService.CreateCustomer(createCustomerRequest);

            return(PipelineExecutionResult.Success);
        }
Exemple #17
0
        public ManagerResponse <CreateUserResult, CommerceUser> RegisterUser(RegisterUserInputModel inputModel)
        {
            Assert.ArgumentNotNull(inputModel, nameof(inputModel));
            Assert.ArgumentNotNullOrEmpty(inputModel.UserName, nameof(inputModel.UserName));
            Assert.ArgumentNotNullOrEmpty(inputModel.Password, nameof(inputModel.Password));
            if (StorefrontContext.Current == null)
            {
                throw new InvalidOperationException("Cannot be called without a valid storefront context.");
            }

            CreateUserResult result;

            // Attempt to register the user
            try
            {
                var request = new CreateUserRequest(inputModel.UserName, inputModel.Password, inputModel.UserName, StorefrontContext.Current.ShopName);
                result = CustomerServiceProvider.CreateUser(request);
                result.WriteToSitecoreLog();

                if (result.Success && result.CommerceUser == null && !result.SystemMessages.Any())
                {
                    // Connect bug:  This is a work around to a Connect bug.  When the user already exists,connect simply aborts the pipeline but
                    // does not set the success flag nor does it return an error message.
                    result.Success = false;
                    result.SystemMessages.Add(new SystemMessage
                    {
                        Message = DictionaryPhraseRepository.Current.Get("/System Messages/Accounts/User Already Exists", "User name already exists. Please enter a different user name.")
                    });
                }
            }
            catch (MembershipCreateUserException e)
            {
                result = new CreateUserResult {
                    Success = false
                };
                result.SystemMessages.Add(new SystemMessage {
                    Message = ErrorCodeToString(e.StatusCode)
                });
            }

            return(new ManagerResponse <CreateUserResult, CommerceUser>(result, result.CommerceUser));
        }
Exemple #18
0
        public ManagerResponse <UpdatePasswordResult, bool> UpdateUserPassword(string userName, ChangePasswordInputModel inputModel)
        {
            Assert.ArgumentNotNull(inputModel, nameof(inputModel));
            Assert.ArgumentNotNullOrEmpty(inputModel.OldPassword, nameof(inputModel.OldPassword));
            Assert.ArgumentNotNullOrEmpty(inputModel.NewPassword, nameof(inputModel.NewPassword));

            var request = new UpdatePasswordRequest(userName, inputModel.OldPassword, inputModel.NewPassword);
            var result  = CustomerServiceProvider.UpdatePassword(request);

            if (!result.Success && !result.SystemMessages.Any())
            {
                var message = DictionaryPhraseRepository.Current.Get("/System Messages/Accounts/Password Could Not Be Reset", "Your password could not be reset. Please verify the data you entered");
                result.SystemMessages.Add(new SystemMessage {
                    Message = message
                });
            }

            result.WriteToSitecoreLog();
            return(new ManagerResponse <UpdatePasswordResult, bool>(result, result.Success));
        }
Exemple #19
0
        public ManagerResponse <DeleteUserResult, bool> DeleteUser(string userName)
        {
            var commerceUser = GetUser(userName).Result;

            if (commerceUser == null)
            {
                return(new ManagerResponse <DeleteUserResult, bool>(new DeleteUserResult {
                    Success = false
                }, false));
            }

            // NOTE: we do not need to call DeleteCustomer because this will delete the commerce server user under the covers
            var request = new DeleteUserRequest(new CommerceUser {
                UserName = userName
            });
            var result = CustomerServiceProvider.DeleteUser(request);

            result.WriteToSitecoreLog();
            return(new ManagerResponse <DeleteUserResult, bool>(result, result.Success));
        }
Exemple #20
0
        public ManagerResponse <AddPartiesResult, bool> AddParties(string userName, List <IParty> parties)
        {
            Assert.ArgumentNotNull(userName, nameof(userName));
            Assert.ArgumentNotNull(parties, nameof(parties));

            var getUserResponse = GetUser(userName);

            if (getUserResponse.Result == null)
            {
                throw new ArgumentException("User not found, invalid userName", nameof(userName));
            }
            var customer = new CommerceCustomer {
                ExternalId = getUserResponse.Result.ExternalId
            };
            var request = new AddPartiesRequest(customer, parties.Select(a => a.ToCommerceParty()).ToList());
            var result  = CustomerServiceProvider.AddParties(request);

            result.WriteToSitecoreLog();

            return(new ManagerResponse <AddPartiesResult, bool>(result, result.Success));
        }
        public PipelineExecutionResult Execute(IPipelineArgs <CreateMemberRequest, CreateMemberResponse> subject)
        {
            if (subject.Request.Properties.ContainsKey("FromUCommerce"))
            {
                if (!(bool)subject.Request.Properties["FromUCommerce"])
                {
                    return(PipelineExecutionResult.Success);
                }
            }

            var customerService = new CustomerServiceProvider();

            var createUserRequest = new CreateUserRequest(
                subject.Response.Member.LoginName,
                subject.Response.Member.Password,
                subject.Response.Member.Email,
                Context.GetSiteName());

            createUserRequest.Properties["FromUCommerce"] = true;

            customerService.CreateUser(createUserRequest);

            return(PipelineExecutionResult.Success);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="AccountService" /> class.
 /// </summary>
 /// <param name="cartService">The cart service.</param>
 /// <param name="customerServiceProvider">The customer provider.</param>
 public AccountService(ICartService cartService, CustomerServiceProvider customerServiceProvider)
 {
     this.cartService             = cartService;
     this.customerServiceProvider = customerServiceProvider;
 }
 public MockAccountManager(ICartManager cartManager, IContactFactory contactFactory, CustomerServiceProvider customerServiceProvider)
 {
     _customerServiceProvider = customerServiceProvider;
     _cartManager             = cartManager;
     ContactFactory           = contactFactory;
 }
Exemple #24
0
 public CustomersController(ILoginRepository loginRepository, IRegistrationRepository registrationRepository, IForgotPasswordRepository forgotPasswordRepository, IChangePasswordRepository changePasswordRepository, IAccountManager accountManager, IStorefrontContext storefrontContext, IModelProvider modelProvider, IContext sitecoreContext, IRegisterUserRepository registerUserRepository, ILoginUserRepository loginUserRepository, IConnectServiceProvider connectServiceProvider)
     : base(loginRepository, registrationRepository, forgotPasswordRepository, changePasswordRepository, accountManager, storefrontContext, modelProvider, sitecoreContext, registerUserRepository, loginUserRepository)
 {
     _customerServiceProvider = connectServiceProvider.GetCustomerServiceProvider();
 }
 public BaseCartStringOperatorCondition()
 {
     this.CartService     = (CartServiceProvider)Factory.CreateObject("cartServiceProvider", true);
     this.CustomerService = (CustomerServiceProvider)Factory.CreateObject("customerServiceProvider", true);
 }