Пример #1
0
        public async Task <Mozu.Api.Contracts.ProductAdmin.Product> GetProduct(int tenantId, int?siteId,
                                                                               int?masterCatalogId, string productCode)
        {
            _apiContext = new ApiContext(tenantId, siteId, masterCatalogId);

            var productResource = new ProductResource(_apiContext);
            var product         = await productResource.GetProductAsync(productCode, null);

            return(product);
        }
        protected async Task ExportProductAsync(IApiContext apiContext, Event eventPayLoad)
        {
            var productHandler = new ProductExportHandler(_appSetting);
            var product        = await productHandler.GetProduct(apiContext, eventPayLoad.EntityId);



            var productStoreResource = new ProductResource(apiContext);
            var sfProd = await productStoreResource.GetProductAsync(product.ProductCode, responseFields : "Content(ProductImages)");

            if (sfProd != null)
            {
                //Get images form storefront product
                var images        = sfProd.Content.ProductImages;
                var productImages = new List <ProductLocalizedImage>();
                if (images != null)
                {
                    var documentResource = new DocumentResource(apiContext);
                    foreach (var image in images)
                    {
                        var imageUrl = image.ImageUrl ??
                                       String.Format("//cdn-sb.mozu.com/{0}-m1/cms/files/{1}", apiContext.TenantId,
                                                     image.CmsId);

                        var document = await documentResource.GetDocumentAsync("files@mozu", image.CmsId);

                        productImages.Add(new ProductLocalizedImage
                        {
                            CmsId      = image.CmsId,
                            ImageLabel = document.Name,
                            //ImageUrl = image.ImageUrl.Replace(image.CmsId, document.Name)
                            ImageUrl = imageUrl.Replace(image.CmsId, document.Name)
                        });
                    }
                    product.Content.ProductImages = productImages;
                }

                await productHandler.ExportFileuploadAsync(productImages);
            }

            //Get Locations for Product
            var locations = await GetProductLocations(apiContext, product.ProductCode);


            await productHandler.ExportInventoryAsync(apiContext, product, locations);

            await productHandler.ExportProductAsync(apiContext, product);
        }