public StockStatusCalculatorResult Populate(StockStatusCalculatorArgs calculatorArgs, StockStatusCalculatorItemArgs calculatorItemArgs, StockStatusCalculatorResult result)
        {
            var key = (calculatorItemArgs.Quantity == 0 ? result.InStockQuantity > 0 : result.InStockQuantity >= calculatorItemArgs.Quantity) ? "stock.instockwithoutquantity" : "stock.outofstockwithoutquantity";

            var channel = _routeRequestLookupInfoAccessor.RouteRequestLookupInfo?.Channel;

            if (channel?.WebsiteSystemId != null)
            {
                var website = _websiteService.Get(channel.WebsiteSystemId.Value);
                var value   = website.Texts.GetValue(key, CultureInfo.CurrentUICulture);
                if (value != null)
                {
                    result.Description = string.Format(value, result.InStockQuantity);
                }
            }

            if (result.Description == null)
            {
                string value = _stringLocalizer.GetString(key);
                if (value != null)
                {
                    result.Description = string.Format(value, result.InStockQuantity);
                }
            }

            if (result.Description == null)
            {
                result.Description = result.InStockQuantity.ToString();
            }

            return(result);
        }
Beispiel #2
0
    /// <summary>
    /// Init campaign drop down
    /// </summary>
    /// <param name="currencyID">CurrencyID</param>
    private void InitWebSiteDropDown(Guid currencyID)
    {
        // Add web sites
        c_webSite.Items.Clear();
        if (ModuleCMS.ExistsInstance)
        {
            var countries  = _countryService.GetAll().Where(x => x.CurrencySystemId == currencyID).Select(c => c.SystemId).ToList();
            var websiteIds = _channelService.GetAll().Where(c => c.WebsiteSystemId != null && c.CountryLinks.Any(x => countries.Contains(x.CountrySystemId))).Select(y => y.WebsiteSystemId.GetValueOrDefault()).Distinct();
            foreach (Website webSite in websiteIds.Select(x => _websiteService.Get(x)))
            {
                ListItem item = new ListItem(webSite.Localizations.CurrentUICulture.Name, webSite.SystemId.ToString());
                c_webSite.Items.Add(item);
            }
        }
        ListItem itemAll = new ListItem(CurrentModule.Strings.GetValue(ModuleStringConstants.ALL_WEB_SITES, FoundationContext.LanguageID, true), Guid.Empty.ToString());

        c_webSite.Items.Insert(0, itemAll);
        c_webSite.SelectedIndex = -1;
        c_webSite.DataBind();
    }
        public override string GetOrderConfirmationPageUrl(OrderCarrier orderCarrier)
        {
            var website     = _websiteService.Get(orderCarrier.WebSiteID);
            var pointerPage = website.Fields.GetValue <PointerPageItem>(AcceleratorWebsiteFieldNameConstants.OrderConfirmationPage);

            if (pointerPage == null)
            {
                throw new CheckoutException("Order is created, order confirmation page is missing.");
            }

            var channelSystemId = pointerPage.ChannelSystemId != Guid.Empty ? pointerPage.ChannelSystemId : orderCarrier.ChannelID;
            var url             = _urlService.GetUrl(_pageService.Get(pointerPage.EntitySystemId), new PageUrlArgs(channelSystemId));

            if (string.IsNullOrEmpty(url))
            {
                throw new CheckoutException("Order is created, order confirmation page is missing.");
            }

            return($"{url}?orderId={orderCarrier.ID}");
        }
        public ActionResult ExportPackage(DeploymentViewModel.ExportViewModel exportForm)
        {
            var model = _deploymentViewModelBuilder.Build(ShowExport());

            if (!Guid.TryParse(exportForm.ChannelSystemId, out var channelSystemId) ||
                !Guid.TryParse(exportForm.FolderSystemId, out var folderSystemId))
            {
                return(View(nameof(Index), model));
            }

            var channel = _channelService.Get(channelSystemId);

            _package.Type = channel.Localizations.CurrentCulture.Name.Replace(" ", "");
            var website = _websiteService.Get(channel.WebsiteSystemId.GetValueOrDefault());

            var assortment = GetAssortment(channel);

            if (assortment == null)
            {
                return(View(nameof(Index), model));
            }

            var deliveryMethodCarriers = ModuleECommerce.Instance.DeliveryMethods.GetAll().Select(x => x.GetAsCarrier()).ToList();
            var paymentMethodCarriers  = ModuleECommerce.Instance.PaymentMethods.GetAll().Select(paymentMethod => paymentMethod.GetAsCarrier()).ToList();

            var structureInfo = _packageService.Export(new PackageInfo
            {
                Assortment      = assortment,
                Folder          = _folderService.Get(folderSystemId),
                Channel         = channel,
                Website         = website,
                DeliveryMethods = deliveryMethodCarriers,
                PaymentMethods  = paymentMethodCarriers,
            });

            _package.PersistStructureInfo(structureInfo);

            model.ExportMessage = "accelerator.deployment.export.success".AsAngularResourceString();

            return(View(nameof(Index), model));
        }
Beispiel #5
0
        public void UpdatePropertyReferences(StructureInfo structureInfo, PackageInfo packageInfo)
        {
            var website = _websiteService.Get(structureInfo.Id(packageInfo.Website.SystemId)).MakeWritableClone();

            AddProperties <WebsiteArea>(structureInfo, structureInfo.Website.Website.Fields, website.Fields, false);
            _websiteService.Update(website);

            var channel = _channelService.Get(packageInfo.Channel.SystemId).MakeWritableClone();

            channel.CountryLinks = structureInfo.Website.Channel.CountryLinks.Select(x => new ChannelToCountryLink(structureInfo.Id(x.CountrySystemId))
            {
                DeliveryMethodSystemIds = x.DeliveryMethodSystemIds.Select(z => ModuleECommerce.Instance.DeliveryMethods.Get(packageInfo.DeliveryMethods.Find(zz => zz.ID == z)?.Name ?? string.Empty, ModuleECommerce.Instance.AdminToken)?.ID ?? Guid.Empty).Where(z => z != Guid.Empty).ToList(),
                PaymentMethodSystemIds  = x.PaymentMethodSystemIds.Select(z =>
                {
                    var payment = packageInfo.PaymentMethods.Find(zz => zz.ID == z);
                    if (payment == null)
                    {
                        return(Guid.Empty);
                    }
                    return(ModuleECommerce.Instance.PaymentMethods.Get(payment.Name, payment.PaymentProviderName, ModuleECommerce.Instance.AdminToken)?.ID ?? Guid.Empty);
                }).Where(z => z != Guid.Empty).ToList(),
            }).ToList();
            AddProperties <GlobalizationArea>(structureInfo, structureInfo.Website.Channel.Fields, channel.Fields, false, new List <string> {
                SystemFieldDefinitionConstants.Name
            });
            _channelService.Update(channel);

            var inventory = _inventoryService.Get(packageInfo.Inventory.SystemId).MakeWritableClone();

            inventory.CountryLinks = structureInfo.ProductCatalog.Inventory.CountryLinks.Select(x => new InventoryToCountryLink(structureInfo.Id(x.CountrySystemId))).ToList();
            _inventoryService.Update(inventory);

            var priceList = _priceListService.Get(packageInfo.PriceList.SystemId).MakeWritableClone();

            priceList.CountryLinks = structureInfo.ProductCatalog.PriceList.CountryLinks.Select(x => new PriceListToCountryLink(structureInfo.Id(x.CountrySystemId))).ToList();
            _priceListService.Update(priceList);
        }
        public WebsiteType(WebsiteService websiteService,
                           RouteInfoService routeInfoService,
                           CategoryService categoryService,
                           UrlService urlService,
                           PageService pageService)
        {
            Name = "Website";
            Field(p => p.LogoUrl);
            Field(p => p.SystemId, type: typeof(IdGraphType));

            Field <FooterType>(nameof(WebsiteModel.Footer), "The website footer",
                               arguments: new QueryArguments(
                                   new QueryArgument <GlobalInputType> {
                Name = "global"
            }
                                   ),
                               resolve: context =>
            {
                var website = websiteService.Get(context.Source.SystemId);
                var footer  = website.Fields.GetValue <IList <MultiFieldItem> >(AcceleratorWebsiteFieldNameConstants.Footer);
                if (footer != null)
                {
                    var globalModel       = context.GetArgument <GlobalModel>("global");
                    var culture           = CultureInfo.GetCultureInfo(globalModel.CurrentUICulture);
                    var startPageSystemId = pageService.GetChildPages(Guid.Empty, globalModel.WebsiteSystemId).FirstOrDefault()?.SystemId;
                    routeInfoService.Setup(globalModel, startPageSystemId);
                    return(new FooterModel()
                    {
                        SectionList = footer.Select(c => new SectionModel()
                        {
                            SectionTitle = c.Fields.GetValue <string>(AcceleratorWebsiteFieldNameConstants.FooterHeader, culture) ?? string.Empty,
                            SectionLinkList = c.Fields.GetValue <IList <PointerItem> >(AcceleratorWebsiteFieldNameConstants.FooterLinkList)
                                              .OfType <PointerPageItem>().ToList()
                                              .Select(x => x.MapTo <Web.Models.LinkModel>()).Where(c => c != null).Select(l => new Models.LinkModel()
                            {
                                Href = l.Href,
                                Text = l.Text
                            }).ToList() ?? new List <Models.LinkModel>(),
                            SectionText = c.Fields.GetValue <string>(AcceleratorWebsiteFieldNameConstants.FooterText, culture) ?? string.Empty
                        }).ToList()
                    });
                }
                return(null);
            });

            Field <HeaderType>(nameof(WebsiteModel.Header), "The website header",
                               arguments: new QueryArguments(
                                   new QueryArgument <GlobalInputType> {
                Name = "global"
            }
                                   ),
                               resolve: context =>
            {
                var globalModel = context.GetArgument <GlobalModel>("global");
                var items       = categoryService.GetChildCategories(Guid.Empty, globalModel.AssortmentSystemId);
                var culture     = CultureInfo.GetCultureInfo(globalModel.CurrentCulture);
                return(new HeaderModel()
                {
                    SectionList = items.Select(c => new SectionModel()
                    {
                        SectionText = c.GetEntityName(culture),
                        SectionTitle = c.GetEntityName(culture),
                        Href = urlService.GetUrl(c, new CategoryUrlArgs(globalModel.ChannelSystemId)),
                        SectionLinkList = categoryService.GetChildCategories(c.SystemId).Select(subCategory => new LinkModel()
                        {
                            Href = urlService.GetUrl(subCategory, new CategoryUrlArgs(globalModel.ChannelSystemId)),
                            Text = subCategory.GetEntityName(culture)
                        }).ToList()
                    }).ToList()
                });
            });
        }
Beispiel #7
0
        public LitiumQuery(BaseProductService baseProductService,
                           VariantService variantService,
                           ChannelService channelService,
                           MarketService marketService,
                           CountryService countryService,
                           LanguageService languageService,
                           RoutingHelperService routingHelperService,
                           CategoryService categoryService,
                           PageService pageService,
                           WebsiteService websiteService,
                           RouteInfoService routeInfoService,
                           DataService dataService)
        {
            Name = "LitiumQuery";

            Field <WebsiteType>(
                "website",
                arguments: new QueryArguments(
                    new QueryArgument <IdGraphType> {
                Name = "systemId"
            }
                    ),
                resolve: (context) =>
            {
                var systemId = context.GetArgument <Guid>("systemId");
                var logoUrl  = websiteService.Get(systemId).Fields
                               .GetValue <Guid?>(AcceleratorWebsiteFieldNameConstants.LogotypeMain).Value
                               .MapTo <Web.Models.ImageModel>().GetUrlToImage(System.Drawing.Size.Empty, new System.Drawing.Size(-1, 50)).Url;
                return(new WebsiteModel()
                {
                    LogoUrl = logoUrl,
                    SystemId = systemId
                });
            }
                );

            Field <GlobalType>(
                "global",
                resolve: (context) =>
            {
                var channel   = channelService.GetAll().First();
                var market    = marketService.Get(channel.MarketSystemId.Value);
                var country   = countryService.Get(channel.CountryLinks.First().CountrySystemId);
                var culture   = languageService.Get(channel.WebsiteLanguageSystemId.Value);
                var uiCulture = languageService.Get(channel.ProductLanguageSystemId.Value);

                return(new GlobalModel()
                {
                    ChannelSystemId = channel.SystemId,
                    WebsiteSystemId = channel.WebsiteSystemId.Value,
                    AssortmentSystemId = market.AssortmentSystemId.Value,
                    CountrySystemId = country.SystemId,
                    CurrencySystemId = country.CurrencySystemId,
                    CurrentCulture = culture.Id,
                    CurrentUICulture = uiCulture.Id,
                });
            }
                );

            Field <CategoryType>(
                "category",
                arguments: new QueryArguments(
                    new QueryArgument <IdGraphType> {
                Name = "systemId", Description = "id of the category, will be override if slug has value"
            },
                    new QueryArgument <GlobalInputType> {
                Name = "global"
            },
                    new QueryArgument <ListGraphType <StringGraphType> > {
                Name = "slug", Description = "category slug urls"
            }
                    ),
                resolve: context =>
            {
                var categoryId = context.GetArgument <Guid>("systemId");
                var slug       = context.GetArgument <string[]>("slug");
                if (slug != null && slug.Any())
                {
                    var globalModel = context.GetArgument <GlobalModel>("global");
                    return(GetCategoryFromSlug(slug, globalModel, routingHelperService, categoryService));
                }
                return(categoryService.Get(categoryId).MapTo <CategoryModel>());
            }
                );

            FieldAsync <PageInfoCategoryType>(
                "searchCategory",
                arguments: new QueryArguments(
                    new QueryArgument <IntGraphType> {
                Name = "offset"
            },
                    new QueryArgument <IntGraphType> {
                Name = "take"
            },
                    new QueryArgument <GlobalInputType> {
                Name = "global", Description = "The global object"
            },
                    new QueryArgument <StringGraphType> {
                Name = "query", Description = "The search query"
            }
                    ),
                resolve: async context =>
            {
                return(await CategoryQuery.SearchAsync(
                           context.GetArgument <GlobalModel>("global"),
                           routeInfoService,
                           context.GetArgument <string>("query") ?? string.Empty,
                           context.GetArgument("take", 8),
                           context.GetArgument("offset", 0),
                           context.RequestServices
                           ));
            }
                );

            Field <ProductType>(
                "product",
                arguments: new QueryArguments(
                    new QueryArgument <IdGraphType> {
                Name = "systemId", Description = "id of the product"
            },
                    new QueryArgument <StringGraphType> {
                Name = "slug", Description = "Product's slug url"
            },
                    new QueryArgument <GlobalInputType> {
                Name = "global"
            }
                    ),
                resolve: context =>
            {
                var systemId    = context.GetArgument <Guid>("systemId");
                var slug        = context.GetArgument <string>("slug");
                var globalModel = context.GetArgument <GlobalModel>("global");
                if (!string.IsNullOrEmpty(slug))
                {
                    systemId = GetProductSystemIdFromSlug(slug, globalModel, routingHelperService);
                }
                // Special treatment for scoped services https://graphql-dotnet.github.io/docs/getting-started/dependency-injection/#scoped-services-with-a-singleton-schema-lifetime
                // and make sure it is thread safe https://graphql-dotnet.github.io/docs/getting-started/dependency-injection/#thread-safety-with-scoped-services
                using var scope = context.RequestServices.CreateScope();
                return(GetProduct(systemId, scope, baseProductService, variantService, globalModel));
            }
                );

            FieldAsync <PageInfoProductType>(
                "products",
                arguments: new QueryArguments(
                    new QueryArgument <IntGraphType> {
                Name = "offset"
            },
                    new QueryArgument <IntGraphType> {
                Name = "take"
            },
                    new QueryArgument <IdGraphType> {
                Name = "parentCategorySystemId", Description = "The optional parent category system id"
            },
                    new QueryArgument <GlobalInputType> {
                Name = "global", Description = "The global object"
            },
                    new QueryArgument <StringGraphType> {
                Name = "query", Description = "The search query"
            }
                    ),
                resolve: async context =>
            {
                return(await ProductQuery.SearchAsync(
                           context.GetArgument <GlobalModel>("global"),
                           context.GetArgument <Guid?>("parentCategorySystemId"),
                           routeInfoService,
                           context.GetArgument <string>("query") ?? string.Empty,
                           context.GetArgument("take", 8),
                           context.GetArgument("offset", 0),
                           context.RequestServices
                           ));
            }
                );

            Field <PageType>(
                "page",
                arguments: new QueryArguments(
                    new QueryArgument <IdGraphType> {
                Name = "systemId", Description = "Id of the page. Can be empty GUID, the website's homepage will be returned in that case, where WebsiteSystemId should have value."
            },
                    new QueryArgument <ListGraphType <StringGraphType> > {
                Name = "slug", Description = "Page's slugs, will override systemId if available"
            },
                    new QueryArgument <GlobalInputType> {
                Name = "global", Description = "Global context, which is needed to get page from slug"
            }
                    ),
                resolve: context =>
            {
                var slug        = context.GetArgument <string[]>("slug");
                var globalModel = context.GetArgument <GlobalModel>("global");
                routeInfoService.Setup(globalModel, null);
                if (slug != null && slug.Any())
                {
                    return(GetPageFromSlug(slug, globalModel, pageService, routingHelperService));
                }

                var systemId = context.GetArgument <Guid?>("systemId");
                if (systemId.HasValue && systemId.Value != Guid.Empty)
                {
                    return(pageService.Get(systemId.Value)?.MapTo <PageModel>());
                }
                return(pageService.GetChildPages(Guid.Empty, globalModel.WebsiteSystemId).FirstOrDefault()?.MapTo <PageModel>());
            }
                );

            FieldAsync <PageInfoPageType>(
                "searchPage",
                arguments: new QueryArguments(
                    new QueryArgument <IntGraphType> {
                Name = "offset"
            },
                    new QueryArgument <IntGraphType> {
                Name = "take"
            },
                    new QueryArgument <GlobalInputType> {
                Name = "global", Description = "The global object"
            },
                    new QueryArgument <StringGraphType> {
                Name = "query", Description = "The search query"
            }
                    ),
                resolve: async context =>
            {
                return(await PageQuery.SearchAsync(
                           context.GetArgument <GlobalModel>("global"),
                           routeInfoService,
                           context.GetArgument <string>("query") ?? string.Empty,
                           context.GetArgument("take", 8),
                           context.GetArgument("offset", 0),
                           context.RequestServices
                           ));
            }
                );

            Field <ContentType>(
                "content",
                arguments: new QueryArguments(
                    new QueryArgument <GlobalInputType> {
                Name = "global", Description = "The global object"
            },
                    new QueryArgument <ListGraphType <StringGraphType> > {
                Name = "slug", Description = "The slug array"
            }
                    ),
                resolve: context =>
            {
                var slug        = context.GetArgument <string[]>("slug");
                var globalModel = context.GetArgument <GlobalModel>("global");
                routeInfoService.Setup(globalModel, null);

                var systemId = GetProductSystemIdFromSlug(slug[slug.Length - 1], globalModel, routingHelperService);
                if (systemId != Guid.Empty)
                {
                    // Special treatment for scoped services https://graphql-dotnet.github.io/docs/getting-started/dependency-injection/#scoped-services-with-a-singleton-schema-lifetime
                    // and make sure it is thread safe https://graphql-dotnet.github.io/docs/getting-started/dependency-injection/#thread-safety-with-scoped-services
                    using var scope = context.RequestServices.CreateScope();
                    return(GetProduct(systemId, scope, baseProductService, variantService, globalModel));
                }

                var category = GetCategoryFromSlug(slug, globalModel, routingHelperService, categoryService);
                if (category != null)
                {
                    return(category);
                }
                return(GetPageFromSlug(slug, globalModel, pageService, routingHelperService));
            }
                );
        }
 public ActionResult <List <Website> > Get() =>
 _websiteService.Get();