public Guid GetUser()
 {
     Guid userId;
     using (WebStoreServices webStoreServices = new WebStoreServices(this._service.GetConfiguration()))
     {
         IProfileService service = webStoreServices.CreateWebStoreChannel<IProfileService>();
         if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
         {
             Magelia.WebStore.Services.Contract.Data.User user = service.GetUser(
                 new GetUserParameters
                 {
                     LoginType = LoginType.UserName,
                     UserKey = System.Web.HttpContext.Current.User.Identity.Name
                 }
             );
             if (user != null)
             {
                 userId = user.UserId;
             }
             else
             {
                 user = service.CreateUser(
                     new CreateUserParameters
                     {
                         Email = Membership.GetUser().Email,
                         FirstName = string.Empty,
                         LastName = string.Empty,
                         MerchantId = this._service.GetConfiguration().MerchantId.Value,
                         Newsletter = false,
                         Password = K_AnonymousDefaultPassword,
                         UserName = System.Web.HttpContext.Current.User.Identity.Name,
                         UserType = Magelia.WebStore.Services.Contract.Data.UserType.Normal
                     }
                 );
                 userId = user.UserId;
             }
         }
         else
         {
             string username = "******" + Guid.NewGuid();
             Magelia.WebStore.Services.Contract.Data.User user = service.CreateUser(
                 new CreateUserParameters
                 {
                     Email = String.Format(K_AnonymousEmailTemplate, username),
                     FirstName = string.Empty,
                     LastName = string.Empty,
                     MerchantId = this._service.GetConfiguration().MerchantId.Value,
                     Newsletter = false,
                     Password = K_AnonymousDefaultPassword,
                     UserName = username,
                     UserType = Magelia.WebStore.Services.Contract.Data.UserType.Anonymous,
                     TitleId = Magelia.WebStore.Services.Contract.Data.UserTitleEnum.Unknown
                 }
             );
             userId = user.UserId;
         }
     }
     return userId;
 }
 public ActionResult Add(Guid productId, Guid catalogId)
 {
     AddProductToBasketParameters parameters = new AddProductToBasketParameters
     {
         ProductId = productId,
         CatalogId = catalogId,
         Quantity = 1,
         Culture = Thread.CurrentThread.CurrentUICulture.Name,
         CountryId = "US   ",
         UserId = this._webStoreProfileServices.GetUser()
     };
     if (this._basketServices.GetBasketId().HasValue)
     {
         parameters.BasketId = this._basketServices.GetBasketId().Value;
     }
     using (WebStoreServices webStoreServices = new WebStoreServices(this._webStoreConfigurationServices.GetConfiguration()))
     {
         this._basketServices.SetBasketId(webStoreServices.CreateWebStoreChannel<IOrderService>().AddProductToBasket(parameters).BasketId);
     }
     return this.Redirect(this.Request.UrlReferrer.PathAndQuery);
 }
        public ViewResult ProceedToCheckout()
        {
            Basket basket = this._basketServices.GetBasket();
            WebStoreConfigurationPart configuration = this._webStoreConfigurationServices.GetConfiguration();
            using (WebStoreServices webStoreServices = new WebStoreServices(configuration))
            {
                IOrderService service = webStoreServices.CreateWebStoreChannel<IOrderService>();
                string orderNumber = service.SaveAsOrder(
                    new SaveAsOrderParameters
                    {
                        BasketId = basket.BasketId,
                        UserId = this._webStoreProfileServices.GetUser()
                    }
                );

                String url = String.Concat(this.Request.Url.GetLeftPart(UriPartial.Authority), VirtualPathUtility.ToAbsolute("~/"));

                Models.Paypal.IndexViewModel viewModel = new Models.Paypal.IndexViewModel { Business = configuration.PaypalAccount, CurrencyCode = basket.CurrencyCode, OrderNumber = orderNumber, Price = basket.Total.ToString(".00"), ReturnUrl = url, Target = K_PAYPAL_PAYMENT_URL };

                return View(viewModel);
            }
        }
 public Basket GetBasket()
 {
     GetBasketParameters parameters = new GetBasketParameters() { CultureName = Thread.CurrentThread.CurrentUICulture.Name };
     Magelia.WebStore.Services.Contract.Data.Basket basket;
     using (WebStoreServices webStoreServices = new WebStoreServices(this._webStoreConfigurationServices.GetConfiguration()))
     {
         IOrderService service = webStoreServices.CreateWebStoreChannel<IOrderService>();
         if (this.BasketId.HasValue)
         {
             parameters.BasketId = this.BasketId.Value;
         }
         else
         {
             parameters.UserId = this._webStoreProfileServices.GetUser();
         }
         basket = service.GetBasket(parameters);
         if (basket != null)
         {
             this.BasketId = basket.BasketId;
         }
     }
     return basket;
 }
        public ActionResult Address(AddressViewModel viewModel)
        {
            IEnumerable<Country> availableCountries = this.GetAvailableCountries();
            if (this.ModelState.IsValid)
            {
                if (viewModel.AddressType == AddressViewModel.AddressTypes.Billing)
                {
                    this.BillingAddress = viewModel;
                }
                else
                {
                    this.ShippingAddress = viewModel;
                }

                if (viewModel.ShippingAddressIsDifferent)
                {
                    this.ModelState.Clear();
                    viewModel = (this.ShippingAddress == default(AddressViewModel)) ? new AddressViewModel { AddressType = AddressViewModel.AddressTypes.Shipping } : this.ShippingAddress;
                }
                else
                {
                    using (WebStoreServices webStoreServices = new WebStoreServices(this._webStoreConfigurationServices.GetConfiguration()))
                    {
                        IProfileService profileService = webStoreServices.CreateWebStoreChannel<IProfileService>();
                        IOrderService orderServices = webStoreServices.CreateWebStoreChannel<IOrderService>();
                        Guid userId = this._webstoreProfileServices.GetUser();
                        UpdateBasketParameters updatBasketParameters = new UpdateBasketParameters { BasketId = this._basketServices.GetBasketId().Value, CountryId = this.BillingAddress.Country, UserId = userId, CultureName = Thread.CurrentThread.CurrentUICulture.Name };
                        this.BillingAddress.AddressId = profileService.SetAddress(this.BillingAddress.GetAddressParameters(userId)).AddressId;
                        updatBasketParameters.BillingAddressId = this.BillingAddress.AddressId;
                        if (this.BillingAddress.ShippingAddressIsDifferent)
                        {
                            this.ShippingAddress.AddressId = profileService.SetAddress(this.ShippingAddress.GetAddressParameters(userId)).AddressId;
                            updatBasketParameters.ShippingAddressId = this.ShippingAddress.AddressId;
                            updatBasketParameters.CountryId = this.ShippingAddress.Country;
                        }
                        orderServices.UpdateBasket(updatBasketParameters);
                    }
                    return this.ShippingMethods();
                }
            }
            viewModel.AvailableCountries = availableCountries;
            return this.View(viewModel);
        }
 private IEnumerable<Country> GetAvailableCountries()
 {
     WebStoreConfigurationPart configuration = this._webStoreConfigurationServices.GetConfiguration();
     WebStoreServices webStoreServices = new WebStoreServices(configuration);
     IEnumerable<Country> availableCountries = webStoreServices.CreateWebStoreChannel<IProfileService>().GetCountries(new GetCountriesParameters { MerchantId = configuration.MerchantId.Value, CultureName = Thread.CurrentThread.CurrentUICulture.Name }).OrderBy(c => c.DisplayName);
     webStoreServices.Dispose();
     return availableCountries;
 }
 public ActionResult ShippingMethods()
 {
     WebStoreConfigurationPart configuration = this._webStoreConfigurationServices.GetConfiguration();
     WebStoreServices webStoreServices = new WebStoreServices(configuration);
     Basket basket = this._basketServices.GetBasket();
     ShippingMethodsViewModel viewModel = new ShippingMethodsViewModel { AvailableShippingMethods = webStoreServices.CreateWebStoreChannel<IOrderService>().GetShippingMethods(new GetShippingMethodsParameters { BasketId = this._basketServices.GetBasketId().Value, CultureName = Thread.CurrentThread.CurrentUICulture.Name, MerchantId = configuration.MerchantId.Value, UserId = this._webstoreProfileServices.GetUser() }), Currency = basket.Currency, ShippingMethod = basket.OrderFormHeaders.First().LineItems.First().ShippingMethodId.ToString() };
     webStoreServices.Dispose();
     this.Response.Cache.SetCacheability(HttpCacheability.NoCache);
     return this.View("~/Modules/WebStore/Views/Order/ShippingMethods.cshtml", viewModel);
 }
 public ActionResult ShippingMethods(ShippingMethodsViewModel viewModel)
 {
     WebStoreServices webStoreServices = new WebStoreServices(this._webStoreConfigurationServices.GetConfiguration());
     if (this.ModelState.IsValid)
     {
         IOrderService orderServices = webStoreServices.CreateWebStoreChannel<IOrderService>();
         orderServices.UpdateBasket(
             new UpdateBasketParameters
             {
                 BasketId = this._basketServices.GetBasketId().Value,
                 UserId = this._webstoreProfileServices.GetUser(),
                 ShippingMethodId = Guid.Parse(viewModel.ShippingMethod),
                 CultureName = Thread.CurrentThread.CurrentUICulture.Name,
                 CountryId = this.BillingAddress.ShippingAddressIsDifferent ? this.ShippingAddress.Country : this.BillingAddress.Country
             }
         );
         webStoreServices.Dispose();
         Basket b = this._basketServices.GetBasket();
         return this.View("~/Modules/WebStore/Views/Order/Pay.cshtml", new PayViewModel { Total = b.Total, ShippingCost = b.ShippingTotal, SubTotal = b.SubTotal, Currency = b.Currency });
     }
     else
     {
         viewModel.AvailableShippingMethods = webStoreServices.CreateWebStoreChannel<IOrderService>().GetShippingMethods(new GetShippingMethodsParameters { BasketId = this._basketServices.GetBasketId().Value, CultureName = Thread.CurrentThread.CurrentUICulture.Name, MerchantId = this._webStoreConfigurationServices.GetConfiguration().MerchantId.Value, UserId = this._webstoreProfileServices.GetUser() });
         webStoreServices.Dispose();
     }
     return this.View(viewModel);
 }
 private IEnumerable<Merchant> GetMerchantSettings(String servicesPath)
 {
     WebStoreServices webstoreServices = new WebStoreServices(servicesPath);
     IEnumerable<Merchant> merchants = webstoreServices.CreateWebStoreChannel<IProfileService>().GetMerchants().OrderBy(m => m.Name);
     webstoreServices.Dispose();
     return merchants;
 }
 private IEnumerable<Catalog> GetCatalogsSettings(String servicesPath, Guid merchantId)
 {
     WebStoreServices webstoreServices = new WebStoreServices(servicesPath);
     IEnumerable<Catalog> catalogs = webstoreServices.CreateWebStoreChannel<ICatalogService>().GetCatalogs(new GetCatalogsParameters { CultureName = "en-US", MerchantId = merchantId }).Where(c => c.IsActive).OrderBy(c => c.Name);
     webstoreServices.Dispose();
     return catalogs;
 }
        public ActionResult Synchronize()
        {
            WebStoreConfigurationPart configuration = this._configurationService.GetConfiguration();
            if (configuration != default(WebStoreConfigurationPart) && configuration.IsComplete)
            {
                using (WebStoreServices webStoreServices = new WebStoreServices(configuration))
                {
                    ICatalogService catalogService = webStoreServices.CreateWebStoreChannel<ICatalogService>();
                    Category root = catalogService.GetCategory(new GetCategoryParameters { CatalogId = configuration.CatalogId.Value, LoadSubCategories = true, CultureName = Thread.CurrentThread.CurrentUICulture.Name, Depth = int.MaxValue });
                    IList<Category> categories = root == default(Category) ? new List<Category>() : root.ChildCategories.Where(cat => cat.IsActive).ToList();
                    IEnumerable<CategoryPart> categoriesLocal = this._contentManager.List<CategoryPart>("WebStore Category").ToList();
                    IEnumerable<Category> categoriesToAdd = categories.Where(cat => !categoriesLocal.Select(c => c.CategoryGuid).Contains(cat.CategoryId));
                    IEnumerable<CategoryPart> categoriesToRemove = categoriesLocal.Where(cat => !categories.Select(c => c.CategoryId).Contains(cat.CategoryGuid));

                    // Categories from service which are not in Orchard
                    foreach (Category category in categoriesToAdd)
                    {
                        String categoryName = String.IsNullOrEmpty(category.Name) ? category.Code : category.Name;
                        CategoryPart categoryPart = this._contentManager.Create<CategoryPart>("WebStore Category");
                        categoryPart.CategoryGuid = category.CategoryId;
                        categoryPart.Code = category.Code;
                        categoryPart.SynchronizationDate = DateTime.Now;

                        RoutePart categoryRoutePart = categoryPart.ContentItem.As<RoutePart>();
                        categoryRoutePart.Slug = "WebStore/Catalog/Category/" + categoryPart.Code;
                        categoryRoutePart.Title =  categoryPart.Code;
                        categoryRoutePart.Path = "WebStore/Catalog/Category/" + categoryPart.Code;

                    }

                    //Categories in orchard which are not in the service
                    foreach (CategoryPart categoryPart in categoriesToRemove)
                    {
                        this._contentManager.Remove(categoryPart.ContentItem);
                    }

                    List<Product> products = new List<Product>();
                    IEnumerable<ProductPart> productsLocal = _contentManager.List<ProductPart>("WebStore Product").ToList();

                    foreach (Category category in categories)
                    {
                        products.AddRange(catalogService.GetProducts(new GetProductsParameters { CatalogId = configuration.CatalogId.Value, CategoryId = category.CategoryId, CultureName = Thread.CurrentThread.CurrentUICulture.Name }));
                    }

                    IEnumerable<Product> productsToAdd = products.Where(p => !productsLocal.Select(pl => pl.ProductGuid).Contains(p.ProductId));
                    IEnumerable<ProductPart> productsToRemove = productsLocal.Where(pl => !products.Select(p => p.ProductId).Contains(pl.ProductGuid));

                    //product from service which are not in orchard
                    foreach (Product product in productsToAdd)
                    {
                        ProductPart productPart = this._contentManager.Create<ProductPart>("WebStore Product");
                        productPart.ProductGuid = product.ProductId;
                        productPart.SynchronizationDate = DateTime.Now;
                        productPart.SKU = product.Sku;

                        CategoryPart category = _contentManager.List<CategoryPart>("WebStore Category").Single(c => c.CategoryGuid == product.VirtualCategoriesIds.First());

                        RoutePart categoryRoutePart = productPart.ContentItem.As<RoutePart>();
                        categoryRoutePart.Slug = "Product/" + productPart.SKU;
                        categoryRoutePart.Title = productPart.SKU;
                        categoryRoutePart.Path = "WebStore/Catalog/Category/" + categories.First(c => c.CategoryId == product.VirtualCategoriesIds.First()).Code +  "/Product/" + productPart.SKU;

                        ICommonPart productContainablePart = productPart.ContentItem.As<ICommonPart>();
                        productContainablePart.Container = category;

                    }
                    foreach (ProductPart productPart in productsToRemove)
                    {
                        this._contentManager.Remove(productPart.ContentItem);
                    }
                    this._notifier.Information(
                        new LocalizedString(String.Format(
                                this.T("Synchronization successfully completed : {0} categorie(s) added, {1} categorie(s) removed, {2} product(s) added and {3} product(s) removed").ToString(),
                                categoriesToAdd.Count(),
                                categoriesToRemove.Count(),
                                productsToAdd.Count(),
                                productsToRemove.Count()
                            )
                        )
                    );
                }
            }
            else
            {
                this._notifier.Warning(this.T("WebStore configuration is missing or is not complete"));
            }
            return this.RedirectToAction("Synchronization", "Admin", new { area = "WebStore" });
        }
 public ActionResult Remove(Guid productId, Guid catalogId)
 {
     if (this._basketServices.GetBasketId().HasValue)
     {
         using (WebStoreServices webstoreServices = new WebStoreServices(this._webStoreConfigurationServices.GetConfiguration()))
         {
             webstoreServices.CreateWebStoreChannel<IOrderService>().UpdateBasket(
                 new UpdateBasketParameters
                 {
                     BasketId = this._basketServices.GetBasketId().Value,
                     UserId = this._webStoreProfileServices.GetUser(),
                     ProductId = productId,
                     Quantity = 0,
                     CountryId = "US   ",
                     CultureName = Thread.CurrentThread.CurrentUICulture.Name,
                     CatalogId = catalogId
                 }
             );
         }
     }
     return new RedirectResult(this.Request.UrlReferrer.PathAndQuery);
 }
Beispiel #13
0
        public IEnumerable<Country> getCountries()
        {
            IEnumerable<Country> countries;
            using (WebStoreServices webStoreServices = new WebStoreServices(this._webStoreConfigurationServices.GetConfiguration()))
            {
                IProfileService service = webStoreServices.CreateWebStoreChannel<IProfileService>();
                countries = service.GetCountries(new GetCountriesParameters() { CultureName = Thread.CurrentThread.CurrentUICulture.Name, MerchantId = this._webStoreConfigurationServices.GetConfiguration().MerchantId.Value });

            }

            return countries;
        }