private IDictionary <Guid, IList <ProductDocument.PriceItem> > BuildPriceData(Context context) { var countries = _countryService.GetAll().ToDictionary(x => x.SystemId, x => x.TaxClassLinks?.FirstOrDefault(x => x.TaxClassSystemId == context.BaseProduct.TaxClassSystemId)?.VatRate ?? x.StandardVatRate); return(context.UsedVariants.ToDictionary(x => x.SystemId, x => (IList <ProductDocument.PriceItem>)GetVariantPrices(x).ToList())); IEnumerable <ProductDocument.PriceItem> GetVariantPrices(Variant variant) { foreach (var price in _priceListItemService.GetByVariant(variant.SystemId).Where(z => z.MinimumQuantity == 0)) { var priceList = _priceListService.Get <ProductPriceList>(price.PriceListSystemId); if (priceList == null) { continue; } foreach (var country in countries) { var vatRate = country.Value; yield return(new ProductDocument.PriceItem { IsCampaignPrice = false, SystemId = priceList.SystemId, Price = priceList.IncludeVat ? price.Price : price.Price * (1 + vatRate), CountrySystemId = country.Key }); } } } }
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); }
private PriceList CreatePriceList(Website webSite, StructureInfo structureInfo) { var priceList = _priceListService.Get(webSite.Id.Replace(" ", "")); if (priceList != null) { return(priceList); } var currency = _currencyService.Get(structureInfo.ProductCatalog.CurrencyId) ?? _currencyService.GetBaseCurrency(); priceList = new PriceList(structureInfo.Id(currency.SystemId)) { Id = webSite.Id.Replace(" ", ""), Active = structureInfo.ProductCatalog.PriceList?.Active ?? true, AccessControlList = structureInfo.ProductCatalog.PriceList.AccessControlList.MakeWritable() }; if (structureInfo.ProductCatalog.PriceList?.WebSiteLinks.Any(x => structureInfo.Id(x.WebSiteSystemId) == structureInfo.Website.Website.SystemId) ?? false) { priceList.WebSiteLinks.Add(new PriceListToWebSiteLink(webSite.SystemId)); } foreach (var language in Solution.Instance.Languages) { priceList.Localizations[language.Culture].Name = webSite.Localizations[language.Culture].Name; } _priceListService.Create(priceList); if (structureInfo.ProductCatalog.PriceList != null) { structureInfo.Mappings.Add(structureInfo.ProductCatalog.PriceList.SystemId, priceList.SystemId); } return(priceList); }
private ODataProductModel MapVariant(BaseProduct baseProduct, Variant variant) { var prices = priceListItemService.GetByVariant(variant.SystemId).ToDictionary(p => priceListService.Get(p.PriceListSystemId).Id, r => r.Price); return(new ODataProductModel(baseProduct, variant, prices)); }