Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CheckoutContext"/> class.
        /// </summary>
        /// <param name="customer">
        /// The <see cref="ICustomerBase"/> associated with this checkout.
        /// </param>
        /// <param name="itemCache">
        /// The temporary <see cref="IItemCache"/> of the basket <see cref="IItemCache"/> to be used in the
        /// checkout process.
        /// </param>
        /// <param name="merchelloContext">
        /// The <see cref="IMerchelloContext"/>.
        /// </param>
        /// <param name="settings">
        /// The version change settings.
        /// </param>
        public CheckoutContext(ICustomerBase customer, IItemCache itemCache, IMerchelloContext merchelloContext, ICheckoutContextSettings settings)
        {
            Mandate.ParameterNotNull(customer, "customer");
            Mandate.ParameterNotNull(itemCache, "itemCache");
            Mandate.ParameterNotNull(merchelloContext, "merchelloContext");
            Mandate.ParameterNotNull(settings, "settings");

            this.MerchelloContext = merchelloContext;
            this.ItemCache = itemCache;
            this.Customer = customer;
            this.Cache = merchelloContext.Cache.RuntimeCache;
            this.ApplyTaxesToInvoice = true;
            this.Settings = settings;
            this.RaiseCustomerEvents = false;
        }
Exemple #2
0
        /// <summary>
        /// The get checkout context.
        /// </summary>
        /// <param name="basket">
        /// The basket.
        /// </param>
        /// <param name="merchelloContext">
        /// The merchello context.
        /// </param>
        /// <param name="settings">
        /// The settings.
        /// </param>
        /// <returns>
        /// The <see cref="ICheckoutContext"/>.
        /// </returns>
        internal static ICheckoutContext CreateCheckoutContext(this IBasket basket, IMerchelloContext merchelloContext, ICheckoutContextSettings settings)
        {
            var context = CheckoutContext.CreateCheckoutContext(merchelloContext, basket.Customer, basket.VersionKey, settings);

            if (context.IsNewVersion && basket.Validate())
            {
                if (!context.ItemCache.Items.Any() && basket.Validate())
                {
                    // this is either a new preparation or a reset due to version
                    foreach (var item in basket.Items)
                    {
                        // convert to a LineItem of the same type for use in the CheckoutPrepartion collection
                        context.ItemCache.AddItem(item.AsLineItemOf <ItemCacheLineItem>());
                    }

                    merchelloContext.Services.ItemCacheService.Save(context.ItemCache);
                }
            }

            return(context);
        }
Exemple #3
0
 /// <summary>
 /// Gets a <see cref="ICheckoutManagerBase"/> for the basket.
 /// </summary>
 /// <param name="basket">
 /// The basket.
 /// </param>
 /// <param name="merchelloContext">
 /// The merchello Context.
 /// </param>
 /// <param name="settings">
 /// The checkout context version change settings.
 /// </param>
 /// <returns>
 /// The <see cref="ICheckoutManagerBase"/>.
 /// </returns>
 internal static ICheckoutManagerBase GetCheckoutManager(this IBasket basket, IMerchelloContext merchelloContext, ICheckoutContextSettings settings)
 {
     return(new BasketCheckoutManager(basket.CreateCheckoutContext(merchelloContext, settings)));
 }
Exemple #4
0
 /// <summary>
 /// The get checkout manager.
 /// </summary>
 /// <param name="basket">
 /// The basket.
 /// </param>
 /// <param name="settings">
 /// The checkout context version change settings.
 /// </param>
 /// <returns>
 /// The <see cref="ICheckoutManagerBase"/>.
 /// </returns>
 public static ICheckoutManagerBase GetCheckoutManager(this IBasket basket, ICheckoutContextSettings settings)
 {
     return(new BasketCheckoutManager(basket.CreateCheckoutContext(MerchelloContext.Current, settings)));
 }
Exemple #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CheckoutContext"/> class.
        /// </summary>
        /// <param name="customer">
        /// The <see cref="ICustomerBase"/> associated with this checkout.
        /// </param>
        /// <param name="itemCache">
        /// The temporary <see cref="IItemCache"/> of the basket <see cref="IItemCache"/> to be used in the
        /// checkout process.
        /// </param>
        /// <param name="merchelloContext">
        /// The <see cref="IMerchelloContext"/>.
        /// </param>
        /// <param name="settings">
        /// The version change settings.
        /// </param>
        public CheckoutContext(ICustomerBase customer, IItemCache itemCache, IMerchelloContext merchelloContext, ICheckoutContextSettings settings)
        {
            Mandate.ParameterNotNull(customer, "customer");
            Mandate.ParameterNotNull(itemCache, "itemCache");
            Mandate.ParameterNotNull(merchelloContext, "merchelloContext");
            Mandate.ParameterNotNull(settings, "settings");

            this.MerchelloContext    = merchelloContext;
            this.ItemCache           = itemCache;
            this.Customer            = customer;
            this.Cache               = merchelloContext.Cache.RuntimeCache;
            this.ApplyTaxesToInvoice = true;
            this.Settings            = settings;
            this.RaiseCustomerEvents = false;
        }
Exemple #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CheckoutContext"/> class.
 /// </summary>
 /// <param name="customer">
 /// The customer.
 /// </param>
 /// <param name="itemCache">
 /// The item cache.
 /// </param>
 /// <param name="settings">
 /// The settings.
 /// </param>
 public CheckoutContext(ICustomerBase customer, IItemCache itemCache, ICheckoutContextSettings settings)
     : this(customer, itemCache, Core.MerchelloContext.Current, settings)
 {
 }
Exemple #7
0
        /// <summary>
        /// Gets the <see cref="ICheckoutContext"/> for the customer
        /// </summary>
        /// <param name="merchelloContext">
        /// The merchello Context.
        /// </param>
        /// <param name="customer">
        /// The customer.
        /// </param>
        /// <param name="versionKey">
        /// The version Key.
        /// </param>
        /// <param name="settings">
        /// The checkout context version change settings.
        /// </param>
        /// <returns>
        /// The <see cref="ICheckoutContext"/> associated with the customer checkout
        /// </returns>
        internal static ICheckoutContext CreateCheckoutContext(IMerchelloContext merchelloContext, ICustomerBase customer, Guid versionKey, ICheckoutContextSettings settings)
        {
            var cache     = merchelloContext.Cache.RuntimeCache;
            var cacheKey  = MakeCacheKey(customer, versionKey);
            var itemCache = cache.GetCacheItem(cacheKey) as IItemCache;

            if (itemCache != null)
            {
                return(new CheckoutContext(customer, itemCache, merchelloContext, settings));
            }

            itemCache = merchelloContext.Services.ItemCacheService.GetItemCacheWithKey(customer, ItemCacheType.Checkout, versionKey);

            // this is probably an invalid version of the checkout
            if (!itemCache.VersionKey.Equals(versionKey))
            {
                var oldCacheKey = MakeCacheKey(customer, versionKey);
                cache.ClearCacheItem(oldCacheKey);

                // delete the old version
                merchelloContext.Services.ItemCacheService.Delete(itemCache);
                return(CreateCheckoutContext(merchelloContext, customer, versionKey, settings));
            }

            cache.InsertCacheItem(cacheKey, () => itemCache, TimeSpan.FromHours(6));

            return(new CheckoutContext(customer, itemCache, merchelloContext, settings)
            {
                IsNewVersion = true
            });
        }
Exemple #8
0
 /// <summary>
 /// Gets the <see cref="ICheckoutContext"/> for the customer.
 /// </summary>
 /// <param name="customer">
 /// The customer.
 /// </param>
 /// <param name="versionKey">
 /// The version key.
 /// </param>
 /// <param name="settings">
 /// The settings.
 /// </param>
 /// <returns>
 /// The <see cref="ICheckoutContext"/>.
 /// </returns>
 public static ICheckoutContext CreateCheckoutContext(ICustomerBase customer, Guid versionKey, ICheckoutContextSettings settings)
 {
     return(CreateCheckoutContext(Core.MerchelloContext.Current, customer, versionKey, settings));
 }
 /// <summary>
 /// The get checkout manager.
 /// </summary>
 /// <param name="basket">
 /// The basket.
 /// </param>
 /// <param name="settings">
 /// The checkout context version change settings.
 /// </param>
 /// <returns>
 /// The <see cref="ICheckoutManagerBase"/>.
 /// </returns>
 public static ICheckoutManagerBase GetCheckoutManager(this IBasket basket, ICheckoutContextSettings settings)
 {
     return new BasketCheckoutManager(basket.CreateCheckoutContext(MerchelloContext.Current, settings));
 }
Exemple #10
0
 /// <summary>
 /// Gets a <see cref="ICheckoutManagerBase"/> for the basket.
 /// </summary>
 /// <param name="basket">
 /// The basket.
 /// </param>
 /// <param name="merchelloContext">
 /// The merchello Context.
 /// </param>
 /// <param name="settings">
 /// The checkout context version change settings.
 /// </param>
 /// <returns>
 /// The <see cref="ICheckoutManagerBase"/>.
 /// </returns>
 internal static ICheckoutManagerBase GetCheckoutManager(this IBasket basket, IMerchelloContext merchelloContext, ICheckoutContextSettings settings)
 {
     return new BasketCheckoutManager(basket.CreateCheckoutContext(merchelloContext, settings));
 }
Exemple #11
0
        /// <summary>
        /// The get checkout context.
        /// </summary>
        /// <param name="basket">
        /// The basket.
        /// </param>
        /// <param name="merchelloContext">
        /// The merchello context.
        /// </param>
        /// <param name="settings">
        /// The settings.
        /// </param>
        /// <returns>
        /// The <see cref="ICheckoutContext"/>.
        /// </returns>
        internal static ICheckoutContext CreateCheckoutContext(this IBasket basket, IMerchelloContext merchelloContext, ICheckoutContextSettings settings)
        {
            var context = CheckoutContext.CreateCheckoutContext(merchelloContext, basket.Customer, basket.VersionKey, settings);

            if (context.IsNewVersion && basket.Validate())
            {
                if (!context.ItemCache.Items.Any() && basket.Validate())
                {
                    // this is either a new preparation or a reset due to version
                    foreach (var item in basket.Items)
                    {
                        // convert to a LineItem of the same type for use in the CheckoutPrepartion collection
                        context.ItemCache.AddItem(item.AsLineItemOf<ItemCacheLineItem>());
                    }

                    merchelloContext.Services.ItemCacheService.Save(context.ItemCache);
                }
            }

            return context;
        }
 /// <summary>
 /// An overridable method that allows for modifying the <see cref="ICheckoutContextSettings"/> before
 /// being used to instantiate the <see cref="CheckoutContextManagerBase"/>
 /// </summary>
 /// <param name="settings">
 /// The <see cref="ICheckoutContextSettings"/>.
 /// </param>
 /// <returns>
 /// The modified <see cref="ICheckoutContextSettings"/>.
 /// </returns>
 protected virtual ICheckoutContextSettings OnCreate(ICheckoutContextSettings settings)
 {
     return(settings);
 }
 /// <summary>
 /// An overridable method that allows for modifying the <see cref="ICheckoutContextSettings"/> before
 /// being used to instantiate the <see cref="CheckoutContextManagerBase"/>
 /// </summary>
 /// <param name="settings">
 /// The <see cref="ICheckoutContextSettings"/>.
 /// </param>
 /// <returns>
 /// The modified <see cref="ICheckoutContextSettings"/>.
 /// </returns>
 protected virtual ICheckoutContextSettings OnCreate(ICheckoutContextSettings settings)
 {
     return settings;
 }
Exemple #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CheckoutContext"/> class.
 /// </summary>
 /// <param name="customer">
 /// The customer.
 /// </param>
 /// <param name="itemCache">
 /// The item cache.
 /// </param>
 /// <param name="settings">
 /// The settings.
 /// </param>
 public CheckoutContext(ICustomerBase customer, IItemCache itemCache, ICheckoutContextSettings settings)
     : this(customer, itemCache, Core.MerchelloContext.Current, settings)
 {
 }
Exemple #15
0
        /// <summary>
        /// Gets the <see cref="ICheckoutContext"/> for the customer
        /// </summary>
        /// <param name="merchelloContext">
        /// The merchello Context.
        /// </param>
        /// <param name="customer">
        /// The customer.
        /// </param>
        /// <param name="versionKey">
        /// The version Key.
        /// </param>
        /// <param name="settings">
        /// The checkout context version change settings.
        /// </param>
        /// <returns>
        /// The <see cref="ICheckoutContext"/> associated with the customer checkout
        /// </returns>
        internal static ICheckoutContext CreateCheckoutContext(IMerchelloContext merchelloContext, ICustomerBase customer, Guid versionKey, ICheckoutContextSettings settings)
        {
            var cache = merchelloContext.Cache.RuntimeCache;
            var cacheKey = MakeCacheKey(customer, versionKey);
            var itemCache = cache.GetCacheItem(cacheKey) as IItemCache;
            if (itemCache != null) return new CheckoutContext(customer, itemCache, merchelloContext, settings);

            itemCache = merchelloContext.Services.ItemCacheService.GetItemCacheWithKey(customer, ItemCacheType.Checkout, versionKey);

            // this is probably an invalid version of the checkout
            if (!itemCache.VersionKey.Equals(versionKey))
            {
                var oldCacheKey = MakeCacheKey(customer, versionKey);
                cache.ClearCacheItem(oldCacheKey);

                // delete the old version
                merchelloContext.Services.ItemCacheService.Delete(itemCache);
                return CreateCheckoutContext(merchelloContext, customer, versionKey, settings);
            }

            cache.InsertCacheItem(cacheKey, () => itemCache);

            return new CheckoutContext(customer, itemCache, merchelloContext, settings) { IsNewVersion = true };
        }
Exemple #16
0
 /// <summary>
 /// Gets the <see cref="ICheckoutContext"/> for the customer.
 /// </summary>
 /// <param name="customer">
 /// The customer.
 /// </param>
 /// <param name="versionKey">
 /// The version key.
 /// </param>
 /// <param name="settings">
 /// The settings.
 /// </param>
 /// <returns>
 /// The <see cref="ICheckoutContext"/>.
 /// </returns>
 public static ICheckoutContext CreateCheckoutContext(ICustomerBase customer, Guid versionKey, ICheckoutContextSettings settings)
 {
     return CreateCheckoutContext(Core.MerchelloContext.Current, customer, versionKey, settings);
 }