/// <summary>
 /// The product pre tax sale price.
 /// </summary>
 /// <param name="extendedData">
 /// The extended data.
 /// </param>
 /// <returns>
 /// The <see cref="decimal"/>.
 /// </returns>
 public static decimal ProductPreTaxSalePrice(this ExtendedDataCollection extendedData)
 {
     return(!extendedData.TaxIncludedInProductPrice()
                ? extendedData.GetPriceValue()
                : extendedData.ContainsKey(Constants.ExtendedDataKeys.ProductSalePriceNoTax)
                      ? extendedData.GetValue(Constants.ExtendedDataKeys.ProductSalePriceNoTax).AsDecimal()
                      : extendedData.GetPriceValue());
 }
        /// <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);
        }
Beispiel #3
0
        /// <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);
        }
Beispiel #4
0
        /// <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
        }
Beispiel #5
0
        /// <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);
        }
Beispiel #7
0
        /// <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
        }
Beispiel #8
0
        /// <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));
        }