public void NewFindMethods(VariationContent variationContent)
        {
            #region FindStuff - need to check this


            var p = GetProductsForVariation(variationContent.ContentLink); // okay
            // ?? var v1 = GetAssociations("Accessories",variationContent.Code); // fick inget

            // new style, custom Find-q
            GetAssociations("Accessories", variationContent.Code); // fortfarande Json-knas

            // This should give hits on the blue shirt, but it didn't
            //var v2 = GetAssociations("CrossSell"); // fick inget
            //var v3 = GetAssociations("NiceToHave"); // fick inget ... trots att det är den "TypeId" som finns


            //var v4 = GetAssociations("Cool"); // fanns i index, men paj på json Conr-ref
            // GetAssociations("Cool",variationContent.Code); //... trying

            GetVariationReferencesWithInventories();                        // seems ok now after some plumbing
            #endregion
            var p1 = GetVariationReferencesWithUnitPrice(MarketId.Default); // error
            //var a = GetAncestors(variationContent); // eget

            //var p0 = GetVariationReferencesWithPrices();
            // nope, get this ... again... Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type
            //'EPiServer.Find.Cms.IndexableContentReference' because the type requires a JSON string value to deserialize correctly.

            //TestSomeStuff(variationContent);
        }
 // not checked... fishy
 private object GetAncestors(VariationContent variationContent)
 {
     return(SearchClient.Instance.Search <ShirtVariation>()
            //.For(x=>x.Ancestors)
            //.Filter(An)
            .GetContentResult());
 }
        Injected <PricingLoader> rwPriceLoader;         // just to show
                                                        //Injected<ICurrentMarket> currentMarketService;
                                                        //Injected<ReferenceConverter> _refConv;


        // Fund: Pricing Extensions
        private void CheckPrices(VariationContent currentContent)
        {
            // Don't want to see the below lines
            //StoreHelper.GetBasePrice(currentContent.LoadEntry());
            // StoreHelper.GetSalePrice(currentContent.LoadEntry(), 11, theMarket, new Currency("USD")); // Get currency from market or thread... or something

            IMarket theMarket = _currentMarket.GetCurrentMarket();

            var priceRef           = currentContent.PriceReference;    // a ContentReference
            var gotPrices          = currentContent.GetPrices();       // Gets all, recieve "Specialized" Price/ItemCollection
            var defaultPrice       = currentContent.GetDefaultPrice(); // All Cust + qty 0 ... market sensitive
            var custSpecificPrices = currentContent.GetCustomerPrices();

            var PriceCheck = (IPricing)currentContent; // null if not a SKU

            var p1 = roPriceLoader.Service.GetPrices(
                currentContent.ContentLink
                , MarketId.Default
                , new CustomerPricing(CustomerPricing.PriceType.PriceGroup, "VIP"));
            // arbitrary Price-Group, could read
            // ...CustomerContext.Current.CurrentContact.EffectiveCustomerGroup;

            var p2 = roPriceLoader.Service.GetCustomerPrices(
                currentContent.ContentLink
                , theMarket.DefaultCurrency // ...or something
                , 8M
                , true);                    // bool - return customer pricing

            // Loader examples "Infrastructure/PriceCalculator"
        }
Пример #4
0
        public IEnumerable <CartItem> GetCartItems()
        {
            if (_cardhelper.IsEmpty)
            {
                return(Enumerable.Empty <CartItem>());
            }

            var cartItems = new List <CartItem>();
            var lineItems = _cardhelper.Cart.GetAllLineItems();

            //// In order to show the images for the items in the cart, we need to load the variants
            var variants = _contentLoader.GetItems(lineItems.Select(x => _referenceConverter.GetContentLink(x.Code)),
                                                   _preferredCulture).OfType <VariationContent>();

            foreach (var lineItem in lineItems)
            {
                VariationContent variant = variants.FirstOrDefault(x => x.Code == lineItem.Code);
                ProductContent   product = _contentLoader.Get <ProductContent>(variant.GetParentProducts().FirstOrDefault());
                CartItem         item    = new CartItem
                {
                    Code        = lineItem.Code,
                    DisplayName = lineItem.DisplayName,
                    ImageUrl    = variant.GetAssets <IContentImage>(_contentLoader, _urlResolver).FirstOrDefault() ?? "",
                    Quantity    = lineItem.Quantity,
                    Url         = lineItem.GetUrl(),
                    Variant     = variant,
                    Price       = variant.GetPrices().FirstOrDefault().UnitPrice
                };
                cartItems.Add(item);
            }

            return(cartItems);
        }
Пример #5
0
        public void DeleteSingleVariantProduct(VariationContent variant)
        {
            _log.Information("DeleteSingleVariantProduct: " + variant.Code);

            if (!_configuration.ProductsImportUrl.IsValidProductsImportUrl())
            {
                _log.Information("Skipped single variant product delete because url is not valid: " +
                                 _configuration.ProductsImportUrl);
                return;
            }

            // Bail if not published
            if (!_publishedStateAssessor.IsPublished(variant))
            {
                _log.Information("Skipped single variant product delete because it's not yet published");
                return;
            }

            var ids = new List <string>();

            ids.Add(variant.Code.SanitizeKey());

            // Call the external endpoint asynchronously and return immediately.
            Task.Factory.StartNew(() =>
                                  APIFacade.DeleteAsync(
                                      ids,
                                      _configuration.ProductsImportUrl)
                                  .ConfigureAwait(false));
        }
        public static List <PriceAndMarket> GetPricesWithMarket(this VariationContent content, IMarket market)
        {
            List <PriceAndMarket>  priceAndMarkets = new List <PriceAndMarket>();
            ItemCollection <Price> itemCollection  = null;

            try
            {
                itemCollection = content.GetPrices();
            }
            catch (Exception ex)
            {
                Log.Error("GetPrices returned an error at product with id " + content.Code, ex);
            }
            if (itemCollection != null)
            {
                foreach (var price in itemCollection)
                {
                    priceAndMarkets.Add(new PriceAndMarket()
                    {
                        MarkedId       = price.MarketId.Value,
                        PriceTypeId    = price.CustomerPricing.PriceTypeId.ToString(),
                        PriceCode      = price.CustomerPricing.PriceCode,
                        Price          = GetPriceString(price),
                        CurrencyCode   = price.UnitPrice.Currency.CurrencyCode,
                        CurrencySymbol = price.UnitPrice.Currency.Format.CurrencySymbol//Pricecode??
                    });
                }
            }
            return(priceAndMarkets);
        }
Пример #7
0
 public ProductVariantViewModel(VariationContent variationContent)
 {
     this._variationContent = variationContent;
     _isAvailable           = _variationContent.IsPendingPublish == false &&
                              _variationContent.IsDeleted == false &&
                              _variationContent.IsAvailableInCurrentMarket();
 }
Пример #8
0
        private IPromotionResult PromotionResult(IOrderGroup orderGroup, BuyXFromCategoryGetProductForFree promotion,
                                                 FulfillmentStatus fulfillment)
        {
            BuyXFromCategoryGetProductForFreeResult result = null;

            switch (fulfillment)
            {
            case FulfillmentStatus.NotFulfilled:
                result = new BuyXFromCategoryGetProductForFreeResult(fulfillment,
                                                                     "The promotion is not fulfilled.");
                break;

            case FulfillmentStatus.PartiallyFulfilled:
                result = new BuyXFromCategoryGetProductForFreeResult(fulfillment,
                                                                     "The promotion is somewhat fulfilled.");
                break;

            case FulfillmentStatus.Fulfilled:
            {
                VariationContent content = _contentLoader.Get <VariationContent>(promotion.FreeProduct);
                result = new BuyXFromCategoryGetProductForFreeResult(fulfillment,
                                                                     string.Format("The promotion is fulfilled and it has been applied to item {0}", content.Name),
                                                                     content, orderGroup as OrderGroup);
                break;
            }
            }
            return(result);
        }
        public ActionResult UpdateInventory(VariationContent currentContent)
        {
            InventoryChange theChange = new InventoryChange()
            {
                CatalogEntryCode        = currentContent.Code,
                WarehouseCode           = "Nashua",
                PurchaseAvailableChange = 4,
            };

            _inventoryService.Adjust(theChange);

            /*===*/

            _inventoryService.Update(new[]
            {
                new InventoryRecord
                {
                    CatalogEntryCode          = currentContent.Code,
                    PurchaseAvailableQuantity = 199,
                    PurchaseAvailableUtc      = DateTime.UtcNow,
                    WarehouseCode             = "Nashua"
                }
            });

            return(RedirectToAction("Index", "Variation"));
        }
        protected void PopulatePrices(VariationContent content, IMarket currentMarket)
        {
            var priceModel = content.GetPriceModel(currentMarket);

            if (priceModel == null)
            {
                return;
            }

            if (priceModel.DefaultPrice == null)
            {
                return;
            }

            PriceString = priceModel.DefaultPrice.UnitPrice.ToString();
            PriceAmount = priceModel.DefaultPrice.UnitPrice.Amount;

            DiscountPriceAmount = priceModel.HasDiscount() ? priceModel.DiscountPrice.Price.Amount : 0;
            DiscountPriceString = priceModel.HasDiscount() ? priceModel.DiscountPrice.Price.ToString() : "";

            DiscountPriceAvailable = DiscountPriceAmount > 0;

            CustomerClubMemberPriceAmount = priceModel.CustomerClubPrice.GetPriceAmountSafe();
            CustomerClubMemberPriceString = priceModel.CustomerClubPrice.GetPriceAmountStringSafe();

            CustomerPriceAvailable = CustomerClubMemberPriceAmount > 0;
        }
 public BuyXFromCategoryGetProductForFreeResult(FulfillmentStatus status, string description, VariationContent variation, OrderGroup group)
 {
     this.Status      = status;
     this.Description = description;
     this._variation  = variation;
     this._orderGroup = group;
 }
Пример #12
0
        /// <summary>
        /// Sets discount price for the first variation with a price
        /// </summary>
        /// <param name="findProduct"></param>
        /// <param name="content"></param>
        /// <param name="market"></param>
        public static void SetPriceData(this FindProduct findProduct, List <VariationContent> content, IMarket market)
        {
            VariationContent variation = null;

            if (content.Any())
            {
                foreach (var item in content)
                {
                    var price = item.GetPrice(market);
                    if (price != null)
                    {
                        variation = item;
                        break;
                    }
                }
            }

            if (variation == null)
            {
                return;
            }

            PriceModel priceModel = variation.GetPriceModel(market);

            findProduct.DefaultPrice       = priceModel.DefaultPrice.UnitPrice.ToString();
            findProduct.DefaultPriceAmount = content.GetDefaultPriceAmountWholeNumber(market);

            DiscountPrice discountPrice = priceModel.DiscountPrice;

            findProduct.DiscountedPriceAmount = (double)discountPrice.GetDiscountPriceWithCheck();
            findProduct.DiscountedPrice       = discountPrice.GetDiscountDisplayPriceWithCheck();

            findProduct.CustomerClubPriceAmount = (double)priceModel.CustomerClubPrice.GetPriceAmountSafe();
            findProduct.CustomerClubPrice       = priceModel.CustomerClubPrice.GetPriceAmountStringSafe();
        }
Пример #13
0
        public override ActionResult Index(RecommendedProductsBlock currentBlock)
        {
            List <ProductListViewModel> models = new List <ProductListViewModel>();

            RecommendedResult recommendedResult = new RecommendedResult();
            var currentCustomer = CustomerContext.Current.CurrentContact;

            var recommendedProducts = GetRecommendedProducts(currentBlock);

            foreach (var content in recommendedProducts.Products)
            {
                ProductListViewModel model     = null;
                VariationContent     variation = content as VariationContent;
                if (variation != null)
                {
                    model = new ProductListViewModel(variation, _currentMarket.GetCurrentMarket(),
                                                     currentCustomer);
                }
                else
                {
                    ProductContent product = content as ProductContent;
                    if (product != null)
                    {
                        model = _productService.GetProductListViewModel(product as IProductListViewModelInitializer);
                        if (model == null)
                        {
                            model = new ProductListViewModel(product, _currentMarket.GetCurrentMarket(),
                                                             currentCustomer);
                        }
                    }
                }

                if (model != null)
                {
                    model.TrackingName = recommendedProducts.RecommenderName;

                    models.Add(model);

                    // Track
                    ControllerContext.HttpContext.AddRecommendationExposure(new TrackedRecommendation()
                    {
                        ProductCode = model.Code, RecommenderName = recommendedProducts.RecommenderName
                    });
                    GoogleAnalyticsTracking tracker = new GoogleAnalyticsTracking(ControllerContext.HttpContext);
                    tracker.ProductImpression(
                        model.Code,
                        model.DisplayName,
                        null,
                        model.BrandName,
                        null,
                        currentBlock.Heading);
                }
            }

            recommendedResult.TrackingName = recommendedProducts.RecommenderName;
            recommendedResult.Heading      = currentBlock.Heading;
            recommendedResult.Products     = models;

            return(View("_recommendedProductsBlock", recommendedResult));
        }
 public ProductVariantViewModel(VariationContent variationContent)
 {
     this._variationContent = variationContent;
     _isAvailable = _variationContent.IsPendingPublish == false &&
                 _variationContent.IsDeleted == false &&
                 _variationContent.IsAvailableInCurrentMarket();
 }
        public static decimal GetStock(this VariationContent content)
        {
            if (content == null)
            {
                return(0);
            }

            if (content.TrackInventory == false)
            {
                return(int.MaxValue);
            }

            var inventoryService = ServiceLocator.Current.GetInstance <IDefaultInventoryService>();
            var inventory        = inventoryService.GetForDefaultWarehouse(content.Code);

            if (inventory != null)
            {
                if (inventory.IsTracked == false)
                {
                    return(int.MaxValue);
                }

                return(inventory.PurchaseAvailableQuantity);
            }
            return(0);
        }
        // new method for the...
        // \Infrastructure\Promotions\CustomPromotionEngineContentLoader.cs
        internal static IPriceValue GetSalePrice(ContentReference entryLink)
        {
            // Need the pricing context... have a look here
            List <CustomerPricing> customerPricing = GetCustomerPricingList();
            IMarket theMarket = _currentMarket.Service.GetCurrentMarket();
            IEnumerable <Currency> currencies = theMarket.Currencies;

            PriceFilter filter = new PriceFilter()
            {
                Quantity              = 1M, // can be improved, simple for now
                Currencies            = currencies,
                CustomerPricing       = customerPricing,
                ReturnCustomerPricing = false
            };

            VariationContent theEntry   = _contentLoader.Service.Get <VariationContent>(entryLink);
            CatalogKey       catalogKey = new CatalogKey(theEntry.Code); // 3 overloads


            //_pricingLoader.Service.GetPrices(entryLink,theMarket.MarketId.Value)
            IEnumerable <IPriceValue> prices = _priceService.Service.GetPrices(
                theMarket.MarketId.Value, FrameworkContext.Current.CurrentDateTime, catalogKey, filter);

            //_roPriceLoader.Service.GetCustomerPrices(contentReference,) // may use this one

            // Don't want the "BasePrice" ... this is the "SalePrice"
            return(prices.Where(x =>
                                x.CustomerPricing.PriceTypeId != (CustomerPricing.PriceType) 3)
                   .OrderBy(pv => pv.UnitPrice).FirstOrDefault()); // Lowest price

            //return prices.OrderByDescending(p => p.UnitPrice.Amount).Last();
        }
 public BuyXFromCategoryGetProductForFreeResult(FulfillmentStatus status, string description, VariationContent variation, OrderGroup group)
 {
     this.Status = status;
     this.Description = description;
     this._variation = variation;
     this._orderGroup = group;
 }
Пример #18
0
        private void SetupContent()
        {
            _variation1 = new VariationContent
            {
                Code        = "code1",
                ContentLink = new ContentReference(1),
                Categories  = new Categories {
                    ContentLink = new ContentReference(11)
                }
            };

            _variation2 = new VariationContent
            {
                Code        = "code2",
                ContentLink = new ContentReference(2),
                Categories  = new Categories {
                    ContentLink = new ContentReference(11)
                }
            };

            _variations = new List <VariationContent>
            {
                _variation1, _variation2
            };

            _contentLoaderMock = new Mock <IContentLoader>();
            _contentLoaderMock.Setup(x => x.Get <EntryContentBase>(It.IsAny <ContentReference>()))
            .Returns((ContentReference contentReference) => _variations.SingleOrDefault(x => x.ContentLink == contentReference));
        }
Пример #19
0
        protected bool HasPrice(VariationContent variationContent)
        {
            var price = variationContent.GetPrices(PricingLoader).FirstOrDefault(x => x.MarketId == CurrentMarket.GetCurrentMarket().MarketId);

            return(price != null &&
                   price.UnitPrice != null);
        }
Пример #20
0
        public void RightMenu_WhenContentIsNotNull_ShouldUseItAsCurrentContentLink()
        {
            var variationContent = new VariationContent() { ContentLink = new ContentReference(456) };
            
            var result = (PartialViewResult)_subject.RightMenu(variationContent);

            Assert.AreEqual<ContentReference>(variationContent.ContentLink, ((HeaderViewModel)result.Model).CurrentContentLink);
        }
        /// <summary>
        /// Renders the OpenGraph header tags for <see cref="VariationContent"/>
        /// </summary>
        /// <param name="htmlHelper">The HTML helper.</param>
        /// <param name="content">The content.</param>
        /// <returns>The <see cref="IHtmlString"/>.</returns>
        /// <exception cref="T:System.Web.HttpException">The Web application is running under IIS 7 in Integrated mode.</exception>
        /// <exception cref="T:System.ArgumentException">The specified <see cref="UriPartial.Authority"/> is not valid.</exception>
        /// <exception cref="T:System.InvalidOperationException">The current <see cref="T:System.Uri" /> instance is not an absolute instance.</exception>
        /// <exception cref="T:System.NotSupportedException">The query collection is read-only.</exception>
        /// <exception cref="T:System.ArgumentNullException">Parent products are <see langword="null" />.</exception>
        /// <exception cref="T:System.MemberAccessException">The <see cref="T:System.Lazy`1" /> instance is initialized to use the default constructor of the type that is being lazily initialized, and permissions to access the constructor are missing.</exception>
        /// <exception cref="T:System.MissingMemberException">The <see cref="T:System.Lazy`1" /> instance is initialized to use the default constructor of the type that is being lazily initialized, and that type does not have a public, parameterless constructor.</exception>
        public static IHtmlString OpenGraphProductItem(this HtmlHelper htmlHelper, VariationContent content)
        {
            OpenGraphProductItem openGraphContent = content.ToOpenGraphProductItem();

            return(openGraphContent == null
                       ? MvcHtmlString.Empty
                       : htmlHelper.OpenGraph(openGraphMetadata: openGraphContent));
        }
        public void GetUrl_WhenVariationHasCode_ShouldReturnUrlWithQuery()
        {
            var variant = new VariationContent {Code = "code"};

            var result = ContentExtensions.GetUrl(variant, _linkRepositoryMock.Object, _urlResolverMock.Object);

            Assert.Equal<string>(_url + "?variationCode=" + variant.Code, result);
        }
        public void GetUrl_WhenVariationHasNoCode_ShouldReturnBaseUrl()
        {
            var variant = new VariationContent();

            var result = ContentExtensions.GetUrl(variant, _linkRepositoryMock.Object, _urlResolverMock.Object);

            Assert.Equal<string>(_url, result);
        }
        public void GetUrl_WhenVariationHasNoCode_ShouldReturnBaseUrl()
        {
            var variant = new VariationContent();

            var result = variant.GetUrl(_relationRepositoryMock.Object, _urlResolverMock.Object);

            Assert.Equal <string>(_url, result);
        }
        protected bool IsSellable(VariationContent variationContent)
        {
            var inventory = InventoryService.GetForDefaultWarehouse(variationContent.Code);

            return(HasPrice(variationContent) &&
                   inventory != null &&
                   inventory.PurchaseAvailableQuantity > 0);
        }
Пример #26
0
 /// <summary>
 /// Gets the default price.
 /// </summary>
 /// <param name="variationContent">Content of the variation.</param>
 /// <returns>The default price value.</returns>
 /// <exception cref="T:System.MemberAccessException">The <see cref="T:System.Lazy`1" /> instance is initialized to use the default constructor of the type that is being lazily initialized, and permissions to access the constructor are missing.</exception>
 /// <exception cref="T:System.MissingMemberException">The <see cref="T:System.Lazy`1" /> instance is initialized to use the default constructor of the type that is being lazily initialized, and that type does not have a public, parameterless constructor.</exception>
 internal static IPriceValue GetDefaultPrice(this VariationContent variationContent)
 {
     return(PriceService.Value.GetDefaultPrice(
                market: CurrentMarket.Value.GetCurrentMarket().MarketId,
                validOn: DateTime.Now,
                new CatalogKey(catalogEntryCode: variationContent.Code),
                currency: CurrentMarket.Value.GetCurrentMarket().DefaultCurrency));
 }
Пример #27
0
        public void GetUrl_WhenVariationHasNoCode_ShouldReturnBaseUrl()
        {
            var variant = new VariationContent();

            var result = ContentExtensions.GetUrl(variant, _linkRepositoryMock.Object, _urlResolverMock.Object);

            Assert.AreEqual <string>(_url, result);
        }
 /// <summary>
 /// Gets the <see cref="Boilerplate.Web.Mvc.OpenGraph.OpenGraphCurrency"/> list for the <param name="variationContent"></param>.
 /// </summary>
 /// <param name="variationContent">Content of the variation.</param>
 /// <returns>The <see cref="Boilerplate.Web.Mvc.OpenGraph.OpenGraphCurrency"/> list for the <param name="variationContent"></param>.</returns>
 private static IEnumerable <OpenGraphCurrency> GetOpenGraphCurrencies(this VariationContent variationContent)
 {
     return(PriceService.Value.GetPrices(
                market: CurrentMarket.Value.GetCurrentMarket().MarketId,
                validOn: DateTime.Now,
                new CatalogKey(catalogEntryCode: variationContent.Code),
                new PriceFilter()).GetOpenGraphCurrencies());
 }
Пример #29
0
        protected bool IsSellable(VariationContent variationContent)
        {
            var inventory = InventoryService.GetTotal(new CatalogKey(AppContext.Current.ApplicationId, variationContent.Code));

            return(HasPrice(variationContent) &&
                   inventory != null &&
                   inventory.InStockQuantity - inventory.ReservedQuantity > 0);
        }
Пример #30
0
        public static PriceModel GetPriceModel(this VariationContent currentContent)
        {
            PriceModel priceModel = new PriceModel();

            priceModel.Price = GetPrice(currentContent);
            priceModel.DiscountDisplayPrice     = currentContent.GetDiscountDisplayPrice(currentContent.GetDefaultPrice());
            priceModel.CustomerClubDisplayPrice = currentContent.GetCustomerClubDisplayPrice();
            return(priceModel);
        }
Пример #31
0
 /// <summary>
 /// Gets the discount price, if no discount is set, returns string.Empty
 /// </summary>
 /// <param name="variations">All variants for a product</param>
 /// <param name="defaultPrice">The price to compare against</param>
 /// <param name="market">The market.</param>
 /// <returns></returns>
 public static string GetDiscountDisplayPrice(this List <VariationContent> variations, Price defaultPrice, IMarket market = null)
 {
     if (variations.Any())
     {
         VariationContent variationContent = variations.FirstOrDefault(x => x.GetPricesWithMarket(market) != null);
         return(variationContent.GetDiscountDisplayPrice(defaultPrice, market));
     }
     return(string.Empty);
 }
Пример #32
0
 public static PriceAndMarket GetDiscountPrice(this List <VariationContent> variations, IMarket market = null)
 {
     if (variations.Any())
     {
         VariationContent variationContent = variations.FirstOrDefault(x => x.GetPricesWithMarket(market) != null);
         return(variationContent.GetDiscountPrice(market));
     }
     return(null);
 }
Пример #33
0
        public static PriceModel GetPriceModel(this VariationContent currentContent, IMarket market)
        {
            PriceModel priceModel = new PriceModel();

            priceModel.DefaultPrice      = currentContent.GetPrice(market);
            priceModel.DiscountPrice     = currentContent.GetDiscountPrice(market);
            priceModel.CustomerClubPrice = currentContent.GetCustomerClubPrice(market);
            return(priceModel);
        }
Пример #34
0
        protected virtual PriceModel GetPriceModel(VariationContent currentContent)
        {
            PriceModel priceModel = new PriceModel();

            priceModel.Price = GetPrice(currentContent);
            priceModel.DiscountDisplayPrice     = currentContent.GetDiscountDisplayPrice(currentContent.GetDefaultPrice());
            priceModel.CustomerClubDisplayPrice = currentContent.GetCustomerClubDisplayPrice();
            return(priceModel);
        }
        public void GetUrl_WhenNoRelationExists_ShouldReturnEmptyString()
        {
            _linkRepositoryMock
                .Setup(x => x.GetRelationsByTarget<ProductVariation>(It.IsAny<ContentReference>()))
                .Returns(Enumerable.Empty<ProductVariation>());

            var variant = new VariationContent();

            var result = ContentExtensions.GetUrl(variant, _linkRepositoryMock.Object, _urlResolverMock.Object);

            Assert.Equal<string>(string.Empty, result);
        }
        public ProductListViewModel(VariationContent content, 
            IMarket currentMarket, 
            CustomerContact currentContact)
            : this()
        {
            ImageUrl = content.GetDefaultImage();
            AllImageUrls = content.AssetUrls();
            IsVariation = true;

            PopulateCommonData(content, currentMarket, currentContact);

            PopulatePrices(content, currentMarket);
        }
Пример #37
0
        // ReSharper restore UnassignedField.Compiler
        public CartItemModel(VariationContent entry)
        {
            Code = entry.Code;
            Name = GetCleanString(entry.DisplayName);
            Entry = entry;
            var parent = entry.GetParent();
            var media = entry.GetCommerceMedia();
            if (entry is FashionItemContent)
            {
                FashionItemContent fashionItemContent = (FashionItemContent) entry;
                Size = fashionItemContent.Facet_Size;
            }
            //TODO: Make this generic, move proerty to base?
            else if(entry.Property["Size"] != null)
            {
                Size = (string)entry.Property["Size"].Value;
            }

            if (media != null)
            {
                ImageUrl = _urlResolver.Service.GetUrl(media.AssetContentLink(_permanentLinkMapper.Service));
            }
            else if (parent != null)
            {
                //If variant does not have images, we get image from product
                media = parent.GetCommerceMedia();
                if(media != null)
                    ImageUrl = _urlResolver.Service.GetUrl(media.AssetContentLink(_permanentLinkMapper.Service));
            }

            if (parent != null)
            {
                ColorImageUrl = parent.AssetSwatchUrl();
                if (parent is FashionProductContent)
                {
                    var fashionProductContent = (FashionProductContent)parent;
                    Color = fashionProductContent.FacetColor;
                    ArticleNumber = fashionProductContent.Code;
                    if (fashionProductContent.SizeAndFit != null &&
                        fashionProductContent.SizeAndFit.ToHtmlString() != null)
                    {
                        Description = fashionProductContent.SizeAndFit.ToHtmlString().StripHtml().StripPreviewText(255);
                    }
                    else
                    {
                        Description = "";
                    }
                }
            }
        }
        public virtual CartItemViewModel CreateCartItemViewModel(ICart cart, ILineItem lineItem, VariationContent variant)
        {
            var productLink = variant.GetParentProducts(_relationRepository).FirstOrDefault();
            var product = _contentLoader.Get<ProductContent>(productLink) as FashionProduct;

            return new CartItemViewModel
            {
                Code = lineItem.Code,
                DisplayName = variant.DisplayName,
                ImageUrl = variant.GetAssets<IContentImage>(_contentLoader, _urlResolver).FirstOrDefault() ?? "",
                DiscountedPrice = GetDiscountedPrice(cart, lineItem),
                PlacedPrice = new Money(lineItem.PlacedPrice, _currencyService.GetCurrentCurrency()),
                Quantity = lineItem.Quantity,
                Url = lineItem.GetUrl(),
                Variant = variant,
                IsAvailable = _pricingService.GetCurrentPrice(variant.Code).HasValue,
                Brand = GetBrand(product),
                AvailableSizes = GetAvailableSizes(product, variant),
                DiscountedUnitPrice = GetDiscountedUnitPrice(cart, lineItem),
                IsGift = lineItem.IsGift
            };
        }
Пример #39
0
 public virtual ProductViewModel GetProductViewModel(VariationContent variation)
 {
     return CreateProductViewModel(null, variation);
 }
        protected void PopulatePrices(VariationContent content, IMarket currentMarket)
        {
            PriceString = content.GetDisplayPrice(currentMarket);
            PriceAmount = content.GetDefaultPriceAmount(currentMarket);

            var discountPriceAmount = content.GetDiscountPrice();
            DiscountPriceAmount = GetPriceWithCheck(discountPriceAmount);
            DiscountPriceString = GetDisplayPriceWithCheck(discountPriceAmount);

            DiscountPriceAvailable = DiscountPriceAmount > 0;

            var customerClubPriceAmount = content.GetCustomerClubPrice();
            CustomerClubMemberPriceAmount = GetPriceWithCheck(customerClubPriceAmount);
            CustomerClubMemberPriceString = GetDisplayPriceWithCheck(customerClubPriceAmount);

            CustomerPriceAvailable = CustomerClubMemberPriceAmount > 0;
        }
 private IEnumerable<string> GetAvailableSizes(FashionProduct product, VariationContent variant)
 {
     return product != null ?
         _productService.GetVariations(product).Where(x => x.Color.Equals(((FashionVariant)variant).Color, StringComparison.OrdinalIgnoreCase)).Select(x => x.Size)
         : Enumerable.Empty<string>();
 }
Пример #42
0
        private Money GetDiscountPrice(VariationContent variation, IMarket market, Currency currency, Money originalPrice)
        {
            var discountedPrice = _promotionService.GetDiscountPrice(new CatalogKey(_appContext.ApplicationId, variation.Code), market.MarketId, currency);
            if (discountedPrice != null)
            {
                return discountedPrice.UnitPrice;
            }

            return originalPrice;
        }
Пример #43
0
        private void SetupContent()
        {
            _variation1 = new VariationContent
            {
                Code = "code1",
                ContentLink = new ContentReference(1),
                Categories = new Categories {ContentLink = new ContentReference(11)}
            };

            _variation2 = new VariationContent
            {
                Code = "code2",
                ContentLink = new ContentReference(2),
                Categories = new Categories { ContentLink = new ContentReference(11) }
            };

            _variations = new List<VariationContent>
            {
                _variation1, _variation2
            };

            _contentLoaderMock = new Mock<IContentLoader>();
            _contentLoaderMock.Setup(x => x.Get<EntryContentBase>(It.IsAny<ContentReference>()))
                .Returns((ContentReference contentReference) => _variations.SingleOrDefault(x => x.ContentLink == contentReference));
        }
Пример #44
0
        private ProductViewModel CreateProductViewModel(ProductContent product, VariationContent variation)
        {
            if (variation == null)
            {
                return null;
            }

            ContentReference productContentReference;
            if (product != null)
            {
                productContentReference = product.ContentLink;
            }
            else
            {
                productContentReference = variation.GetParentProducts(_relationRepository).FirstOrDefault();
                if (ContentReference.IsNullOrEmpty(productContentReference))
                {
                    return null;
                }
            }
            var market = _currentMarket.GetCurrentMarket();
            var currency = _currencyService.GetCurrentCurrency();

            var originalPrice = _pricingService.GetCurrentPrice(variation.Code);
            var discountedPrice = originalPrice.HasValue ? GetDiscountPrice(variation, market, currency, originalPrice.Value) : (Money?)null;

            var image = variation.GetAssets<IContentImage>(_contentLoader, _urlResolver).FirstOrDefault() ?? "";
            var brand = product is FashionProduct ? ((FashionProduct)product).Brand : string.Empty;

            return new ProductViewModel
            {
                DisplayName = product != null ? product.DisplayName : variation.DisplayName,
                PlacedPrice = originalPrice.HasValue ? originalPrice.Value : new Money(0, currency),
                DiscountedPrice = discountedPrice,
                ImageUrl = image,
                Url = variation.GetUrl(),
                Brand = brand,
                IsAvailable = originalPrice.HasValue
            };
        }
Пример #45
0
        protected void ConfigureVariationDefaults(VariationContent variationContent)
        {
            if (variationContent == null)
                return;

            _log.Debug("Configuring variation details - MinQuantity: {0}, MaxQuantity: {1}, TrackInventory: {2}",
                Defaults.variationMinQuantity, Defaults.variationMaxQuantity, Defaults.variationEnableTracking);

            if (Defaults.variationMinQuantity > 0)
            {
                variationContent.MinQuantity = Defaults.variationMinQuantity;
            }

            if (Defaults.variationMaxQuantity > 0)
            {
                variationContent.MaxQuantity = Defaults.variationMaxQuantity;
            }

            variationContent.TrackInventory = Defaults.variationEnableTracking;
        }