/// <summary> /// Adds to shopping cart. /// </summary> /// <param name="productCode">The product code.</param> /// <param name="quantity">The quantity.</param> public virtual void AddProduct(string productCode, uint quantity) { Assert.ArgumentNotNullOrEmpty(productCode, "productCode"); if (quantity == 0) { return; } DomainModel.Carts.ShoppingCartLine existingShoppingCartLine = this.shoppingCart.ShoppingCartLines.FirstOrDefault(p => p.Product.Code.Equals(productCode)); if (existingShoppingCartLine != null) { existingShoppingCartLine.Quantity += quantity; existingShoppingCartLine.Totals = this.productPriceManager.GetProductTotals <Totals, ProductBaseData, Currency>(existingShoppingCartLine.Product, this.shoppingCart.Currency, existingShoppingCartLine.Quantity); } else { existingShoppingCartLine = Context.Entity.Resolve <DomainModel.Carts.ShoppingCartLine>(); ProductBaseData product = this.productRepository.Get <ProductBaseData>(productCode); Assert.IsNotNull(product, "Unable to add product \"{0}\" to the shopping cart. The product is not found.", productCode); existingShoppingCartLine.Product = product; existingShoppingCartLine.Quantity = quantity; existingShoppingCartLine.Totals = this.productPriceManager.GetProductTotals <Totals, ProductBaseData, Currency>(product, this.shoppingCart.Currency, existingShoppingCartLine.Quantity); this.shoppingCart.ShoppingCartLines.Add(existingShoppingCartLine); } Context.Entity.SetInstance(this.shoppingCart); }
/// <summary> /// Inserts the specified parent item. /// </summary> /// <typeparam name="T">The type of the product repository item.</typeparam> /// <param name="parentItem">The parent item.</param> /// <param name="item">The needed item.</param> /// <exception cref="ArgumentException">Product repository item title is invalid.</exception> protected virtual void Insert <T>(Item parentItem, T item) where T : IProductRepositoryItem { Assert.ArgumentNotNull(parentItem, "parentItem"); Assert.ArgumentNotNull(item, "item"); this.CheckDuplicatedCode(item.Code); Item newItem; ID templateId = null; ITemplatedEntity templatedEntity = item as ITemplatedEntity; if (templatedEntity != null && !string.IsNullOrEmpty(templatedEntity.Template)) { Item templateItem = this.Database.GetItem(templatedEntity.Template); templateId = templateItem.ID; } try { if (ID.IsNullOrEmpty(templateId)) { templateId = this.GetRepositoryItemTemplateId(typeof(T)); } newItem = parentItem.Add(item.Name, new TemplateID(templateId)); } catch (InvalidItemNameException exception) { Log.Error("Product title is invalid.", exception, this); throw new ArgumentException("Product repository item title is invalid.", exception); } catch (Exception exception) { Log.Error("Failed to create product item", exception, this); throw; } Assert.IsNotNull(newItem, "Failed to create product item."); Assert.IsNotNull(this.DataMapper, "DataMapper cannot be null."); this.DataMapper.SaveEntity(item, newItem); ProductBaseData product = item as ProductBaseData; if (product == null) { return; } using (new EditContext(newItem)) { foreach (KeyValuePair <string, object> specification in product.Specifications) { newItem[specification.Key] = specification.Value.ToString(); } } }
public virtual double?GetAverageRating(ProductBaseData product) { var reviews = ProductReviewRepository.GetByProduct(product.Code).Where(x => x.Approved && !x.Hidden); if (reviews.Any()) { return(reviews.Average(x => x.Rating)); } return(null); }
protected override object ComputeFieldValue(ProductBaseData product, IIndexable indexable) { var pricing = product.GetDisplayTotals(); if (pricing == null) { return(null); } return(pricing.MinPrice); }
public override ProductSpecification ConvertFrom([NotNull] Item storage) { Assert.ArgumentNotNull(storage, "storage"); ProductBaseData product = this.productFactory.Create(storage.TemplateID.ToString()); ProductSpecification specification = product.Specifications; foreach (string key in specification.Keys.ToArray()) { specification[key] = storage[key]; } return(specification); }
protected override object ComputeFieldValue(ProductBaseData product, IIndexable indexable) { var fullProduct = product as Product; if (fullProduct == null) { return(null); } var image = fullProduct.Image; if (image == null) { return(null); } return(image.GetUri(166, 166)); }
private ProductLineModel GetProductLineModel([NotNull] ProductBaseData productBaseData) { Assert.ArgumentNotNull(productBaseData, "productBaseData"); long stock = this.ProductStockManager.GetStock(new ProductStockInfo { ProductCode = productBaseData.Code }).Stock; var price = this.PriceService.GetPrice(productBaseData, this.currencyCode); return(new ProductLineModel { Code = productBaseData.Code, Name = productBaseData.Name, Stock = stock, Price = price }); }
/// <summary> /// Gets the general price. /// </summary> /// <param name="ni">The ni.</param> /// <returns>The general price.</returns> private Totals GetProductTotals(XPathNodeIterator ni) { Item item = this.GetItem(ni); Assert.ArgumentNotNull(item, "item"); IProductRepository productProvider = Context.Entity.Resolve <IProductRepository>(); ProductBaseData product = productProvider.Get <ProductBaseData>(item["Product Code"]); if (product != null) { ShoppingCart shoppingCart = Context.Entity.GetInstance <ShoppingCart>(); IProductPriceManager productPriceManager = Context.Entity.Resolve <IProductPriceManager>(); Totals productPricesList = productPriceManager.GetProductTotals <Totals, ProductBaseData, Currency>(product, shoppingCart.Currency); return(productPricesList); } return(default(Totals)); }
public override ProductBaseData Create([NotNull] string template) { Assert.ArgumentNotNull(template, "template"); Collection <string> spec = new Collection <string>(); Assert.IsNotNull(this.ShopContext, "Unable to create a product. Context shop cannot be null."); Assert.IsNotNull(this.ShopContext.Database, "Unable to create a product. Context shop database cannot be null."); TemplateItem templateItem = this.ShopContext.Database.GetItem(template); Assert.IsNotNull(templateItem, "Product template is not found."); this.FillSpecificationKeys(templateItem, ref spec); ProductBaseData product = Context.Entity.SmartResolve <ProductBaseData>(template); product.Specifications = new ProductSpecification(spec); ((ITemplatedEntity)product).Template = template; return(product); }
public virtual decimal?GetPrice([NotNull] ProductBaseData product, [NotNull] string priceCode) { Assert.ArgumentNotNull(product, "product"); Assert.ArgumentNotNull(priceCode, "priceCode"); var currency = this.CurrencyProvider.Get(priceCode); decimal?price = null; if (currency != null) { try { Totals totals = this.ProductPriceManager.GetProductTotals <Totals, ProductBaseData, Currency>(product, currency); price = Math.Round(totals.PriceExVat, 2, MidpointRounding.AwayFromZero); } catch (CurrencyConversionException) { price = null; } } return(price); }
protected virtual double GetRating(ProductBaseData product) { var average = product.GetAverageRating(); return(average ?? double.MinValue); }
public static double?GetAverageRating(this ProductBaseData product) { return(Instance.GetAverageRating(product)); }
protected abstract object ComputeFieldValue(ProductBaseData product, Sitecore.ContentSearch.IIndexable indexable);