Esempio n. 1
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);
        }