コード例 #1
0
        public virtual FashionProductViewModel Create(FashionProduct currentContent, string variationCode)
        {
            var variants = _catalogContentService.GetVariants <FashionVariant>(currentContent).ToList();

            FashionVariant variant;

            if (!TryGetFashionVariant(variants, variationCode, out variant))
            {
                return(new FashionProductViewModel
                {
                    Product = currentContent,
                    Images = currentContent.GetAssets <IContentImage>(_contentLoader, _urlResolver)
                });
            }

            variationCode = variant.Code;
            var defaultPrice    = _pricingService.GetDefaultPrice(variationCode);
            var discountedPrice = defaultPrice != null?_pricingService.GetDiscountPrice(variationCode).UnitPrice : (Money?)null;

            return(new FashionProductViewModel
            {
                Product = currentContent,
                Variant = variant,
                ListingPrice = defaultPrice?.UnitPrice ?? _pricingService.GetMoney(0),
                DiscountedPrice = discountedPrice,
                Colors = variants
                         .Where(x => x.Size != null)
                         .GroupBy(x => x.Color)
                         .Select(g => new SelectListItem
                {
                    Selected = false,
                    Text = g.Key,
                    Value = g.Key
                })
                         .ToList(),
                Sizes = variants
                        .Where(x => x.Color != null && x.Color.Equals(variant.Color, StringComparison.OrdinalIgnoreCase))
                        .Select(x => new SelectListItem
                {
                    Selected = false,
                    Text = x.Size,
                    Value = x.Size
                })
                        .ToList(),
                Color = variant.Color,
                Size = variant.Size,
                Images = variant.GetAssets <IContentImage>(_contentLoader, _urlResolver),
                IsAvailable = defaultPrice != null
            });
        }
コード例 #2
0
        protected override Entry GenerateEntry(CatalogContentBase catalogContent)
        {
            var variationContent = catalogContent as FashionVariant;

            if (variationContent == null)
            {
                return(null);
            }

            var product      = _contentLoader.Get <CatalogContentBase>(variationContent.GetParentProducts().FirstOrDefault()) as FashionProduct;
            var variantCode  = variationContent.Code;
            var defaultPrice = _pricingService.GetDefaultPrice(variantCode);

            var entry = new Entry
            {
                Id                    = variantCode,
                Title                 = variationContent.DisplayName,
                Description           = product?.Description.ToHtmlString(),
                Link                  = variationContent.GetUrl(),
                Condition             = "new",
                Availability          = "in stock",
                Brand                 = product?.Brand,
                MPN                   = string.Empty,
                GTIN                  = "725272730706",
                GoogleProductCategory = string.Empty,
                Shipping              = new List <Shipping>
                {
                    new Shipping
                    {
                        Price   = "1 USD",
                        Country = "US",
                        Service = "Standard"
                    }
                }
            };

            var image = variationContent.GetDefaultAsset <IContentImage>();

            if (!string.IsNullOrEmpty(image))
            {
                entry.ImageLink = Uri.TryCreate(new Uri(_siteUrl), image, out var imageUri) ? imageUri.ToString() : image;
            }

            if (defaultPrice != null)
            {
                var discountPrice = _pricingService.GetDiscountPrice(variantCode);

                entry.Price     = defaultPrice.UnitPrice.FormatPrice();
                entry.SalePrice = discountPrice != null?discountPrice.UnitPrice.FormatPrice() : string.Empty;

                entry.SalePriceEffectiveDate = $"{DateTime.UtcNow:yyyy-MM-ddThh:mm:ss}/{DateTime.UtcNow.AddDays(7):yyyy-MM-ddThh:mm:ss}";
            }

            return(entry);
        }
コード例 #3
0
        public override List <Feed> Build()
        {
            var generatedFeeds = new List <Feed>();
            var siteUrl        = _siteDefinitionRepository.List().FirstOrDefault()?.SiteUrl.ToString();

            var feed = new Feed
            {
                Updated = DateTime.UtcNow,
                Title   = "My products",
                Link    = siteUrl
            };

            var entries           = new List <Entry>();
            var catalogReferences = _contentLoader.GetDescendents(_referenceConverter.GetRootLink());

            foreach (var catalogReference in catalogReferences)
            {
                var catalogContent   = _contentLoader.Get <CatalogContentBase>(catalogReference);
                var variationContent = catalogContent as FashionVariant;
                if (variationContent != null)
                {
                    var product      = _contentLoader.Get <CatalogContentBase>(variationContent.GetParentProducts().FirstOrDefault()) as FashionProduct;
                    var variantCode  = variationContent.Code;
                    var defaultPrice = _pricingService.GetDefaultPrice(variantCode);

                    var entry = new Entry
                    {
                        Id                    = variantCode,
                        Title                 = variationContent.DisplayName,
                        Description           = product?.Description.ToHtmlString(),
                        Link                  = variationContent.GetUrl(),
                        Condition             = "new",
                        Availability          = "in stock",
                        Brand                 = product?.Brand,
                        MPN                   = string.Empty,
                        GTIN                  = "725272730706",
                        GoogleProductCategory = string.Empty,
                        Shipping              = new List <Shipping>
                        {
                            new Shipping
                            {
                                Price   = "1 USD",
                                Country = "US",
                                Service = "Standard"
                            }
                        }
                    };

                    var image = variationContent.GetDefaultAsset <IContentImage>();
                    if (!string.IsNullOrEmpty(image))
                    {
                        entry.ImageLink = Uri.TryCreate(new Uri(siteUrl), image, out var imageUri) ? imageUri.ToString() : image;
                    }

                    if (defaultPrice != null)
                    {
                        var discountPrice = _pricingService.GetDiscountPrice(variantCode);

                        entry.Price     = defaultPrice.UnitPrice.FormatPrice();
                        entry.SalePrice = discountPrice != null?discountPrice.UnitPrice.FormatPrice() : string.Empty;

                        entry.SalePriceEffectiveDate = $"{DateTime.UtcNow:yyyy-MM-ddThh:mm:ss}/{DateTime.UtcNow.AddDays(7):yyyy-MM-ddThh:mm:ss}";
                    }

                    entries.Add(entry);
                }
            }

            feed.Entries = entries;
            generatedFeeds.Add(feed);

            return(generatedFeeds);
        }