/// <summary> /// Allows for overriding the creation of <see cref="StoreAddItemModel"/> from <see cref="IProductContent"/>. /// </summary> /// <param name="addItem"> /// The <see cref="StoreAddItemModel"/>. /// </param> /// <param name="productContent"> /// The <see cref="IProductContent"/>. /// </param> /// <returns> /// The modified <see cref="StoreAddItemModel"/>. /// </returns> protected override StoreAddItemModel OnCreate(StoreAddItemModel addItem, IProductContent productContent) { // Set the success URL to the product page addItem.SuccessRedirectUrl = productContent.Url; return(base.OnCreate(addItem, productContent)); }
/// <summary> /// Safely adds a recently viewed key to the CustomerContext. /// </summary> /// <param name="context"> /// The context. /// </param> /// <param name="product"> /// The product. /// </param> internal static void AddRecentKey(this ICustomerContext context, IProductContent product) { var recent = context.DeserializeRecentlyViewed(); recent.AddKey(product.Key); recent.Store(context); }
/// <summary> /// Returns static collections containing the product. /// </summary> /// <param name="product"> /// The <see cref="IProductContent"/>. /// </param> /// <returns> /// The <see cref="IEnumerable{EntityCollectionDisplay}"/>. /// </returns> public static IEnumerable <EntityCollectionDisplay> GetCollectionsContaining(this IProductContent product) { if (!MerchelloContext.HasCurrent) { return(Enumerable.Empty <EntityCollectionDisplay>()); } return (((EntityCollectionService)MerchelloContext.Current.Services.EntityCollectionService) .GetEntityCollectionsByProductKey(product.Key).Select(x => x.ToEntityCollectionDisplay())); }
/// <summary> /// Returns a collection of ProductCollection for a given product. /// </summary> /// <param name="product"> /// The product. /// </param> /// <param name="merchelloContext"> /// The merchello context. /// </param> /// <returns> /// The <see cref="IEnumerable{ProductCollection}"/>. /// </returns> internal static IEnumerable <ProductCollection> Collections(this IProductContent product, IMerchelloContext merchelloContext) { var collections = GetProductEntityCollections( MerchelloContext.Current, product.Key, ((EntityCollectionService)merchelloContext.Services.EntityCollectionService).GetEntityCollectionsByProductKey); //((EntityCollectionService)merchelloContext.Services.EntityCollectionService).GetEntityCollectionsByProductKey(product.Key); return(collections.Select(col => new ProductCollection(col))); }
/// <summary> /// Builds a <see cref="AddItemModel"/> from <see cref="IProductContent"/>. /// </summary> /// <param name="product"> /// The product. /// </param> /// <param name="currency"> /// The currency. /// </param> /// <param name="showWishList"> /// The show wish list. /// </param> /// <returns> /// The <see cref="AddItemModel"/>. /// </returns> public static AddItemModel BuildAddItemModel(this IProductContent product, ICurrency currency, bool showWishList) { return(new AddItemModel() { Product = product.AsProductDisplay(), ContentId = 0, BasketPageId = BazaarContentHelper.GetBasketContent().Id, ShowWishList = showWishList, WishListPageId = BazaarContentHelper.GetWishListContent().Id, Currency = currency }); }
/// <summary> /// Gets the <see cref="ProductVariantDisplay"/> with matching with attributes from the product. /// </summary> /// <param name="product"> /// The product. /// </param> /// <param name="optionChoices"> /// The option choices. /// </param> /// <returns> /// The <see cref="ProductVariantDisplay"/>. /// </returns> public static IProductVariantContent GetProductVariantDisplayWithAttributes(this IProductContent product, Guid[] optionChoices) { var variant = product.ProductVariants.FirstOrDefault( x => x.Attributes.Count() == optionChoices.Count() && optionChoices.All(key => x.Attributes.FirstOrDefault(att => att.Key == key) != null)); if (variant == null) { MultiLogHelper.Debug(typeof(ProductContentExtensions), "Could not find IProductVariantContent with keys matching choices in optionChoices array."); } return(variant); }
/// <summary> /// Creates a <see cref="IProductDataTable{TRow}"/> from <see cref="IProductContent"/>. /// </summary> /// <param name="productContent"> /// The <see cref="IProductContent"/>. /// </param> /// <returns> /// The <see cref="TTable"/>. /// </returns> public TTable Create(IProductContent productContent) { var table = new TTable { ProductKey = productContent.Key }; var rows = new List <TRow> { this.Create(productContent, false) }; rows.AddRange(productContent.ProductVariants.Select(variant => this.Create(variant))); // Associate the table rows table.Rows = rows; return(this.OnCreate(table, productContent)); }
/// <summary> /// Gets a <see cref="ProductBoxModel"/> from <see cref="IProductContent"/>. /// </summary> /// <param name="product"> /// The product. /// </param> /// <returns> /// The <see cref="ProductBoxModel"/>. /// </returns> public static ProductBoxModel GetProductBoxModel(IProductContent product) { return(new ProductBoxModel { ProductKey = product.Key, Url = product.Url, Name = product.Name, Image = product.GetCropUrl(propertyAlias: "image", height: 350, cacheBuster: false), FormattedPrice = product.FormattedPrice(), FormattedSalePrice = product.FormattedSalePrice(), SalePrice = product.SalePrice, OnSale = product.OnSale, Price = product.Price }); }
/// <summary> /// Maps <see cref="IProductContent"/> to <see cref="ProductListItem"/>. /// </summary> /// <param name="product"> /// The product. /// </param> /// <returns> /// The <see cref="ProductListItem"/>. /// </returns> public static ProductListItem AsProductListItem(this IProductContent product) { return(new ProductListItem { Key = product.Key, Name = product.Name, Url = product.Url, FormattedPrice = StoreHelper.FormatCurrency(product.Price), FormattedSalePrice = StoreHelper.FormatCurrency(product.SalePrice), OnSale = product.OnSale, IsNew = product.WillWork("isNew") && product.GetPropertyValue <bool>("isNew"), ImageUrl = product.WillWork("images") ? product.GetPropertyValue <IEnumerable <IPublishedContent> >("images") .First() .GetCropUrl(255, 255) : string.Empty, Price = product.OnSale ? product.SalePrice : product.Price }); }
/// <summary> /// Gets the default <see cref="IProductAttributeContent"/> based on default option choices. /// </summary> /// <param name="product"> /// The product. /// </param> /// <returns> /// The <see cref="IProductVariantContent"/>. /// </returns> public static IProductVariantContent GetDefaultProductVariant(this IProductContent product) { if (!product.Options.Any()) { return(null); } var attKeys = new List <Guid>(); foreach (var opt in product.Options) { var defaultChoice = opt.Choices.FirstOrDefault(x => x.IsDefaultChoice); if (defaultChoice == null) { defaultChoice = opt.Choices.First(); MultiLogHelper.Debug(typeof(ProductCollectionExtensions), "Could not find default option choice. Using first choice as default."); } attKeys.Add(defaultChoice.Key); } return(product.GetProductVariantDisplayWithAttributes(attKeys.ToArray())); }
/// <summary> /// The build product payment details item type. /// </summary> /// <param name="item"> /// The item. /// </param> /// <param name="factory"> /// The <see cref="PayPalBasicAmountTypeFactory"/>. /// </param> /// <returns> /// The <see cref="PaymentDetailsItemType"/>. /// </returns> protected virtual PaymentDetailsItemType BuildProductPaymentDetailsItemType(ILineItem item, PayPalBasicAmountTypeFactory factory) { IProductContent product = null; if (_settings.UsesProductContent) { var productKey = item.ExtendedData.GetProductKey(); product = _merchello.TypedProductContent(productKey); } var detailsItemType = new PaymentDetailsItemType { Name = item.Name, ItemURL = product != null? string.Format("{0}{1}", _settings.WebsiteUrl, product.Url) : null, Amount = factory.Build(item.Price), Quantity = item.Quantity }; return(detailsItemType); }
public virtual ActionResult AddProductToBasketForm(IProductContent model, int quantity = 1, string view = "AddToBasketForm") { var addItem = this._addItemFactory.Create(model, quantity); return(this.AddToBasketForm(addItem, view)); }
/// <summary> /// Gets a <see cref="ProductBoxModel"/> from <see cref="IProductContent"/>. /// </summary> /// <param name="product"> /// The product. /// </param> /// <returns> /// The <see cref="ProductBoxModel"/>. /// </returns> public static ProductBoxModel AsProductBoxModel(this IProductContent product) { return(BazaarContentHelper.GetProductBoxModel(product)); }
/// <summary> /// Gets a <see cref="ProductBoxModel"/> from <see cref="IProductContent"/>. /// </summary> /// <param name="product"> /// The product. /// </param> /// <returns> /// The <see cref="ProductBoxModel"/>. /// </returns> public static ProductBoxModel GetProductBoxModel(IProductContent product) { return new ProductBoxModel { ProductKey = product.Key, Url = product.Url, Name = product.Name, Image = product.GetCropUrl(propertyAlias: "image", height: 350, cacheBuster: false), FormattedPrice = product.FormattedPrice(), FormattedSalePrice = product.FormattedSalePrice(), SalePrice = product.SalePrice, OnSale = product.OnSale, Price = product.Price }; }
/// <summary> /// Gets a collection of <see cref="ProductCollection"/> that contain the product. /// </summary> /// <param name="product"> /// The product. /// </param> /// <returns> /// The <see cref="IEnumerable{ProductCollection}"/>. /// </returns> public static IEnumerable <ProductCollection> Collections(this IProductContent product) { return(product.Collections(MerchelloContext.Current)); }
/// <summary> /// Creates <see cref="IAddItemModel"/> from <see cref="IProductContent"/>. /// </summary> /// <param name="productContent"> /// The <see cref="IProductContent"/>. /// </param> /// <param name="quantity"> /// The quantity. /// </param> /// <returns> /// The <see cref="IAddItemModel"/>. /// </returns> public TAddItemModel Create(IProductContent productContent, int quantity = 1) { var addItem = this.Create(productContent.AsProductDisplay(), quantity); return(this.OnCreate(addItem, productContent)); }
/// <summary> /// Gets the <see cref="ProductDisplay"/> from <see cref="IProductContent"/>. /// </summary> /// <param name="content"> /// The content. /// </param> /// <returns> /// The <see cref="ProductDisplay"/>. /// </returns> public static ProductDisplay AsProductDisplay(this IProductContent content) { return(((ProductContent)content).ProductDisplay); }
/// <summary> /// Gets a collection of <see cref="ProductCollection"/> that contain the product. /// </summary> /// <param name="product"> /// The product. /// </param> /// <returns> /// The <see cref="IEnumerable{ProductCollection}"/>. /// </returns> public static IEnumerable <IProductCollection> Collections(this IProductContent product) { return(Query().GetCollectionsContainingProduct(product.Key)); }
/// <summary> /// Formats the product on sale price with store configured pricing format. /// </summary> /// <param name="product"> /// The product. /// </param> /// <returns> /// The formatted sale price. /// </returns> public static string FormattedSalePrice(this IProductContent product) { return(string.Format(StoreCurrencyFormat.Format, _storeCurrency.Symbol, product.SalePrice)); }
/// <summary> /// Allows for overriding the creation of <see cref="IAddItemModel"/> from <see cref="IProductContent"/>. /// </summary> /// <param name="addItem"> /// The <see cref="IAddItemModel"/>. /// </param> /// <param name="productContent"> /// The <see cref="IProductContent"/>. /// </param> /// <returns> /// The modified <see cref="IAddItemModel"/>. /// </returns> protected virtual TAddItemModel OnCreate(TAddItemModel addItem, IProductContent productContent) { return(addItem); }
/// <summary> /// Specifies the model culture setting. /// </summary> /// <param name="content"> /// The content. /// </param> /// <param name="culture"> /// The culture. /// </param> public static void SpecifyCulture(this IProductContent content, CultureInfo culture) { content.SpecifyCulture(culture.Name); }
/// <summary> /// Allows for overriding the creation of <see cref="TTable"/> from <see cref="IProductContent"/>. /// </summary> /// <param name="table"> /// The <see cref="TTable"/>. /// </param> /// <param name="productContent"> /// The product content. /// </param> /// <returns> /// The modified <see cref="TTable"/>. /// </returns> public TTable OnCreate(TTable table, IProductContent productContent) { return(table); }
/// <summary> /// Adds a recent product. /// </summary> /// <param name="product"> /// The product. /// </param> internal void AddRecentProduct(IProductContent product) { this.AddKey(product.Key); this.Store(); }