/// <summary> /// Adds a <see cref="ProductVariantDisplay"/> to the item cache /// </summary> /// <param name="productVariant"> /// The product variant to be added /// </param> /// <param name="name"> /// The name. /// </param> /// <param name="quantity"> /// The quantity to be represented /// </param> /// <param name="extendedData"> /// The extended Data. /// </param> public void AddItem(ProductVariantDisplay productVariant, string name, int quantity, ExtendedDataCollection extendedData) { if (EnableDataModifiers) { var attempt = _productDataModifier.Value.Modify(productVariant); if (attempt.Success) { var modified = attempt.Result as ProductVariantDisplay; if (modified != null) { extendedData.MergeDataModifierLogs(modified); if (!extendedData.DefinesProductVariant()) { extendedData.AddProductVariantValues(modified); } productVariant = modified; } } } else { extendedData.MergeDataModifierLogs(productVariant); if (!extendedData.DefinesProductVariant()) { extendedData.AddProductVariantValues(productVariant); } } var price = productVariant.OnSale ? extendedData.GetSalePriceValue() : extendedData.GetPriceValue(); AddItem(string.IsNullOrEmpty(name) ? productVariant.Name : name, productVariant.Sku, quantity, price, extendedData); }
public void Init() { _extendedData = new ExtendedDataCollection(); var product = MockProductDataMaker.MockProductComplete(Guid.NewGuid()); _extendedData.AddProductVariantValues(((Product)product).MasterVariant); }
/// <summary> /// Adds a line item to the basket /// </summary> /// <param name="productVariant"> /// The product Variant. /// </param> /// <param name="name"> /// The name. /// </param> /// <param name="quantity"> /// The quantity. /// </param> /// <param name="extendedData"> /// The extended Data. /// </param> public void AddItem(IProductVariant productVariant, string name, int quantity, ExtendedDataCollection extendedData) { if (!extendedData.DefinesProductVariant()) { extendedData.AddProductVariantValues(productVariant); } var onSale = productVariant.OnSale ? extendedData.GetSalePriceValue() : extendedData.GetPriceValue(); AddItem(string.IsNullOrEmpty(name) ? productVariant.Name : name, productVariant.Sku, quantity, onSale, extendedData); }
/// <summary> /// Adds a line item to the basket /// </summary> public void AddItem(IProductVariant productVariant, string name, int quantity, ExtendedDataCollection extendedData) { if (!extendedData.DefinesProductVariant()) { extendedData.AddProductVariantValues(productVariant); } AddItem( string.IsNullOrEmpty(name) ? productVariant.Name : name, productVariant.Sku, quantity, productVariant.OnSale ? extendedData.GetSalePriceValue() : extendedData.GetPriceValue(), extendedData); // get the price information from extended data in case it has been overriden //productVariant.SalePrice.Value : productVariant.Price }
public void Can_Convert_A_LineItem_Of_Type_ItemCacheLineItem_To_A_InvoiceLineItem() { //// Arrange var product = MockProductDataMaker.MockProductForInserting(); var extendedData = new ExtendedDataCollection(); extendedData.AddProductVariantValues(((Product)product).MasterVariant); var itemCacheLineItem = new ItemCacheLineItem(LineItemType.Product, product.Name, product.Sku, 2, 2*product.Price, extendedData); //// Act var invoiceLineItem = itemCacheLineItem.AsLineItemOf<InvoiceLineItem>(); //// Assert Assert.NotNull(invoiceLineItem); Assert.AreEqual(Guid.Empty, invoiceLineItem.ContainerKey); Assert.AreEqual(typeof(InvoiceLineItem), invoiceLineItem.GetType()); }
public void Can_Convert_A_LineItem_Of_Type_ItemCacheLineItem_To_A_InvoiceLineItem() { //// Arrange var product = MockProductDataMaker.MockProductForInserting(); var extendedData = new ExtendedDataCollection(); extendedData.AddProductVariantValues(((Product)product).MasterVariant); var itemCacheLineItem = new ItemCacheLineItem(LineItemType.Product, product.Name, product.Sku, 2, 2 * product.Price, extendedData); //// Act var invoiceLineItem = itemCacheLineItem.AsLineItemOf <InvoiceLineItem>(); //// Assert Assert.NotNull(invoiceLineItem); Assert.AreEqual(Guid.Empty, invoiceLineItem.ContainerKey); Assert.AreEqual(typeof(InvoiceLineItem), invoiceLineItem.GetType()); }
/// <summary> /// Turns a product variant into an InvoiceLineItem /// </summary> /// <param name="productVariant"></param> /// <param name="qty"></param> /// <param name="taxIncludedInProductPrice"></param> /// <returns></returns> internal static InvoiceLineItem ToInvoiceLineItem(this ProductVariantDisplay productVariant, int qty = 1, bool taxIncludedInProductPrice = false) { var extendedData = new ExtendedDataCollection(); extendedData.AddProductVariantValues(productVariant); if (taxIncludedInProductPrice) { extendedData.TryAdd(Constants.ExtendedDataKeys.TaxIncludedInProductPrice, true.ToString()); } // See if this variant is on sale var price = productVariant.OnSale ? productVariant.SalePrice : productVariant.Price; // TODO - Can we remove this extra step to turn into a line item var itemCacheLineItem = new ItemCacheLineItem(LineItemType.Product, productVariant.Name, productVariant.Sku, qty, price, extendedData); return(itemCacheLineItem.AsLineItemOf <InvoiceLineItem>()); }
/// <summary> /// Adds a line item to the wish list /// </summary> /// <param name="productVariant"> /// The product Variant. /// </param> /// <param name="name"> /// The name. /// </param> /// <param name="quantity"> /// The quantity. /// </param> /// <param name="extendedData"> /// The extended Data. /// </param> public void AddItem(IProductVariant productVariant, string name, int quantity, ExtendedDataCollection extendedData) { if (!extendedData.DefinesProductVariant()) extendedData.AddProductVariantValues(productVariant); var onSale = productVariant.OnSale ? extendedData.GetSalePriceValue() : extendedData.GetPriceValue(); AddItem(string.IsNullOrEmpty(name) ? productVariant.Name : name, productVariant.Sku, quantity, onSale, extendedData); }
/// <summary> /// Adds a <see cref="ProductVariantDisplay"/> to the item cache /// </summary> /// <param name="productVariant"> /// The product variant to be added /// </param> /// <param name="name"> /// The name. /// </param> /// <param name="quantity"> /// The quantity to be represented /// </param> /// <param name="extendedData"> /// The extended Data. /// </param> public void AddItem(ProductVariantDisplay productVariant, string name, int quantity, ExtendedDataCollection extendedData) { if (EnableDataModifiers) { var attempt = _productDataModifier.Value.Modify(productVariant); if (attempt.Success) { var modified = attempt.Result as ProductVariantDisplay; if (modified != null) { extendedData.MergeDataModifierLogs(modified); if (!extendedData.DefinesProductVariant()) extendedData.AddProductVariantValues(modified); productVariant = modified; } } } else { extendedData.MergeDataModifierLogs(productVariant); if (!extendedData.DefinesProductVariant()) extendedData.AddProductVariantValues(productVariant); } var price = productVariant.OnSale ? extendedData.GetSalePriceValue() : extendedData.GetPriceValue(); AddItem(string.IsNullOrEmpty(name) ? productVariant.Name : name, productVariant.Sku, quantity, price, extendedData); }
/// <summary> /// Adds a <see cref="IProductVariant"/> line item to the collection /// </summary> /// <param name="container"> /// The container. /// </param> /// <param name="productVariant"> /// The product Variant. /// </param> /// <param name="quantity"> /// The quantity. /// </param> /// <param name="extendedData"> /// The extended Data. /// </param> public static void AddItem(this ILineItemContainer container, IProductVariant productVariant, int quantity, ExtendedDataCollection extendedData) { extendedData.AddProductVariantValues(productVariant); container.AddItem(LineItemType.Product, productVariant.Name, productVariant.Sku, quantity, productVariant.Price, extendedData); }
/// <summary> /// Adds a line item to the basket /// </summary> public void AddItem(IProductVariant productVariant, string name, int quantity, ExtendedDataCollection extendedData) { if(!extendedData.DefinesProductVariant()) extendedData.AddProductVariantValues(productVariant); AddItem( string.IsNullOrEmpty(name) ? productVariant.Name : name, productVariant.Sku, quantity, productVariant.OnSale ? extendedData.GetSalePriceValue() : extendedData.GetPriceValue(), extendedData); // get the price information from extended data in case it has been overriden //productVariant.SalePrice.Value : productVariant.Price }
public void Init() { _extendedData = new ExtendedDataCollection(); var product = MockProductDataMaker.MockProductComplete(Guid.NewGuid()); _extendedData.AddProductVariantValues(((Product)product).MasterVariant); }
/// <summary> /// Performs the task of validating the pricing information. /// </summary> /// <param name="value"> /// The value. /// </param> /// <returns> /// The <see cref="Attempt"/>. /// </returns> public override Attempt <ValidationResult <CustomerItemCacheBase> > PerformTask(ValidationResult <CustomerItemCacheBase> value) { var visitor = new ProductPricingValidationVisitor(Merchello); value.Validated.Accept(visitor); if (visitor.InvalidPrices.Any()) { foreach (var result in visitor.InvalidPrices.ToArray()) { var lineItem = result.Key; var quantity = lineItem.Quantity; var name = lineItem.Name; var removedEd = lineItem.ExtendedData.AsEnumerable(); value.Validated.RemoveItem(lineItem.Sku); var extendedData = new ExtendedDataCollection(); ProductVariantDisplay variant; if (result.Value is ProductDisplay) { var product = result.Value as ProductDisplay; variant = product.AsMasterVariantDisplay(); } else { variant = result.Value as ProductVariantDisplay; } if (variant == null) { var nullReference = new NullReferenceException("ProductVariantDisplay cannot be null"); LogHelper.Error <ValidateProductPriceTask>("Exception occurred when attempting to adjust pricing information", nullReference); throw nullReference; } extendedData.AddProductVariantValues(variant); extendedData.MergeDataModifierLogs(variant); extendedData.MergeDataModifierLogs(variant); // preserve any custom extended data values foreach (var val in removedEd.Where(val => !extendedData.ContainsKey(val.Key))) { extendedData.SetValue(val.Key, val.Value); } var price = variant.OnSale ? extendedData.GetSalePriceValue() : extendedData.GetPriceValue(); var keys = lineItem.ExtendedData.Keys.Where(x => extendedData.Keys.Any(y => y != x)); foreach (var k in keys) { extendedData.SetValue(k, lineItem.ExtendedData.GetValue(k)); } value.Validated.AddItem(string.IsNullOrEmpty(name) ? variant.Name : name, variant.Sku, quantity, price, extendedData); value.Messages.Add("Price updated for " + variant.Sku + " to " + price); } value.Validated.Save(); } return(Attempt <ValidationResult <CustomerItemCacheBase> > .Succeed(value)); }