Example #1
0
        public IEnumerable <IShipmentRateQuote> GetShippingMethods(BackofficeAddItemModel model)
        {
            _customer   = MerchelloContext.Services.CustomerService.GetAnyByKey(new Guid(model.CustomerKey));
            _backoffice = _customer.Backoffice();

            var shipment = _backoffice.PackageBackoffice(model.ShippingAddress.ToAddress()).FirstOrDefault();

            return(shipment.ShipmentRateQuotes());
        }
Example #2
0
        /// <summary>
        /// Saves the backoffice.
        /// </summary>
        /// <param name="merchelloContext">
        /// The merchello context.
        /// </param>
        /// <param name="backoffice">
        /// The backoffice.
        /// </param>
        internal static void Save(IMerchelloContext merchelloContext, IBackoffice backoffice)
        {
            // Update the backoffice item cache version so that it can be validated in the checkout
            ((Backoffice)backoffice).VersionKey = Guid.NewGuid();

            merchelloContext.Services.ItemCacheService.Save(((Backoffice)backoffice).ItemCache);

            Refresh(merchelloContext, backoffice);
        }
Example #3
0
        /// <summary>
        /// Refreshes the runtime cache
        /// </summary>
        /// <param name="merchelloContext">The merchello context</param>
        /// <param name="backoffice">The <see cref="IBackoffice"/></param>
        public static void Refresh(IMerchelloContext merchelloContext, IBackoffice backoffice)
        {
            var cacheKey = MakeCacheKey(backoffice.Customer);

            merchelloContext.Cache.RuntimeCache.ClearCacheItem(cacheKey);

            var customerItemCache = merchelloContext.Services.ItemCacheService.GetItemCacheWithKey(backoffice.Customer, ItemCacheType.Backoffice);

            backoffice = new Backoffice(customerItemCache, backoffice.Customer);
            merchelloContext.Cache.RuntimeCache.GetCacheItem(cacheKey, () => backoffice);
        }
Example #4
0
        public bool FinalizeBackofficeOrder(BackofficeAddItemModel model)
        {
            _customer   = MerchelloContext.Services.CustomerService.GetAnyByKey(new Guid(model.CustomerKey));
            _backoffice = _customer.Backoffice();

            // This check asserts that we have enough
            // this should be handled a bit nicer for the customer.
            if (!_backoffice.SalePreparation().IsReadyToInvoice())
            {
                return(false);
            }

            var preparation = _backoffice.SalePreparation();

            // Get the shipment again
            var shippingAddress = _backoffice.SalePreparation().GetShipToAddress();

            var shipment = _backoffice.PackageBackoffice(shippingAddress).FirstOrDefault();

            // Clear any previously saved quotes (eg. the user went back to their basket and started the process over again).
            _backoffice.SalePreparation().ClearShipmentRateQuotes();

            // get the quote using the "approved shipping method"
            var quote = shipment.ShipmentRateQuoteByShipMethod(model.ShipmentKey);

            // save the quote
            _backoffice.SalePreparation().SaveShipmentRateQuote(quote);

            // for cash providers we only want to authorize the payment
            var paymentMethod = _backoffice.SalePreparation().GetPaymentMethod();

            IPaymentResult attempt;

            if (Merchello.Core.Constants.ProviderKeys.Payment.CashPaymentProviderKey == new Guid(model.PaymentProviderKey))
            {
                // AuthorizePayment will save the invoice with an Invoice Number.
                //
                attempt = preparation.AuthorizePayment(new Guid(model.PaymentKey));
            }
            else // we
            {
                // TODO wire in redirect to Credit Card view or PayPal ... etc.
                throw new NotImplementedException();
            }

            _backoffice.Empty();
            _backoffice.Save();

            return(true);
        }
        /// <summary>
        /// Packages a basket into one or more shipments
        /// </summary>
        /// <param name="backoffice">
        /// The backoffice.
        /// </param>
        /// <param name="merchelloContext">
        /// The merchello context.
        /// </param>
        /// <param name="destination">
        /// The destination.
        /// </param>
        /// <returns>
        /// A collection of <see cref="IShipment"/>.
        /// </returns>
        /// <exception cref="Exception">
        /// Throws an exception if the basket packaging strategy fails to instantiate
        /// </exception>
        internal static IEnumerable <IShipment> PackageBackoffice(this IBackoffice backoffice, IMerchelloContext merchelloContext, IAddress destination)
        {
            var defaultStrategy = MerchelloConfiguration.Current.GetStrategyElement(Constants.StrategyTypeAlias.DefaultPackaging).Type;

            var ctoArgValues = new object[] { merchelloContext, backoffice.Items, destination, backoffice.VersionKey };
            var strategy     = ActivatorHelper.CreateInstance <PackagingStrategyBase>(defaultStrategy, ctoArgValues);

            if (strategy.Success)
            {
                return(backoffice.PackageBackoffice(merchelloContext, destination, strategy.Result));
            }

            LogHelper.Error <PackagingStrategyBase>("PackageBackoffice failed to instantiate the defaultStrategy.", strategy.Exception);

            throw strategy.Exception;
        }
Example #6
0
        public BackofficeOrderSummary ProcessesProductsToBackofficeOrder(BackofficeAddItemModel model)
        {
            _customer   = MerchelloContext.Services.CustomerService.GetAnyByKey(new Guid(model.CustomerKey));
            _backoffice = _customer.Backoffice();

            _backoffice.Empty();
            _backoffice.Save();

            if (model.ProductKeys != null && model.ProductKeys.Any())
            {
                foreach (var key in model.ProductKeys)
                {
                    var extendedData = new ExtendedDataCollection();
                    //extendedData.SetValue("umbracoContentId", model.ContentId.ToString(CultureInfo.InvariantCulture));

                    var product = MerchelloContext.Services.ProductService.GetByKey(new Guid(key));

                    //if (model.OptionChoices != null && model.OptionChoices.Any())
                    //{
                    //    var variant = MerchelloContext.Services.ProductVariantService.GetProductVariantWithAttributes(product, model.OptionChoices);

                    //    extendedData.SetValue("isVariant", "true");

                    //    _backoffice.AddItem(variant, variant.Name, 1, extendedData);
                    //}
                    //else
                    //{
                    _backoffice.AddItem(product, product.Name, 1, extendedData);
                    //}
                }

                var salesPreparation = _customer.Backoffice().SalePreparation();

                salesPreparation.SaveBillToAddress(model.BillingAddress.ToAddress());
                salesPreparation.SaveShipToAddress(model.ShippingAddress.ToAddress());

                return(GetBackofficeOrderSummary(salesPreparation));
            }
            else
            {
                return(new BackofficeOrderSummary());
            }
        }
 /// <summary>
 /// Packages a basket into one or more shipments.
 /// </summary>
 /// <param name="backoffice">
 /// The backoffice.
 /// </param>
 /// <param name="merchelloContext">
 /// The merchello context.
 /// </param>
 /// <param name="destination">
 /// The destination.
 /// </param>
 /// <param name="strategy">
 /// The strategy.
 /// </param>
 /// <returns>
 /// The collection of <see cref="IShipment"/>.
 /// </returns>
 internal static IEnumerable <IShipment> PackageBackoffice(this IBackoffice backoffice, IMerchelloContext merchelloContext, IAddress destination, PackagingStrategyBase strategy)
 {
     return(!backoffice.Items.Any() ? new List <IShipment>() : strategy.PackageShipments());
 }
 /// <summary>
 /// Gets the <see cref="IBackofficeSalePreparation"/>
 /// </summary>
 /// <param name="backoffice">The backoffice with items use in the checkout</param>
 /// <param name="merchelloContext">The <see cref="IMerchelloContext"/></param>
 /// <returns>A <see cref="IBackofficeSalePreparation"/></returns>
 internal static BackofficeSalePreparation SalePreparation(this IBackoffice backoffice, IMerchelloContext merchelloContext)
 {
     return(BackofficeSalePreparation.GetBackofficeCheckoutPreparation(merchelloContext, backoffice));
 }
 /// <summary>
 /// Gets the <see cref="IBackofficeSalePreparation"/>
 /// </summary>
 /// <param name="backoffice">The backoffice with items use in the checkout</param>
 /// <returns>A <see cref="IBackofficeSalePreparation"/></returns>
 internal static BackofficeSalePreparation SalePreparation(this IBackoffice backoffice)
 {
     return(backoffice.SalePreparation(MerchelloContext.Current));
 }
Example #10
0
        /// <summary>
        /// Refreshes the runtime cache
        /// </summary>
        /// <param name="merchelloContext">The merchello context</param>
        /// <param name="backoffice">The <see cref="IBackoffice"/></param>
        public static void Refresh(IMerchelloContext merchelloContext, IBackoffice backoffice)
        {
            var cacheKey = MakeCacheKey(backoffice.Customer);
            merchelloContext.Cache.RuntimeCache.ClearCacheItem(cacheKey);

            var customerItemCache = merchelloContext.Services.ItemCacheService.GetItemCacheWithKey(backoffice.Customer, ItemCacheType.Backoffice);
            backoffice = new Backoffice(customerItemCache, backoffice.Customer);
            merchelloContext.Cache.RuntimeCache.GetCacheItem(cacheKey, () => backoffice);
        }
Example #11
0
        public bool FinalizeBackofficeOrder(BackofficeAddItemModel model)
        {
            _customer = MerchelloContext.Services.CustomerService.GetAnyByKey(new Guid(model.CustomerKey));
            _backoffice = _customer.Backoffice();

            // This check asserts that we have enough
            // this should be handled a bit nicer for the customer.
            if (!_backoffice.SalePreparation().IsReadyToInvoice()) return false;

            var preparation = _backoffice.SalePreparation();

            // Get the shipment again
            var shippingAddress = _backoffice.SalePreparation().GetShipToAddress();

            var shipment = _backoffice.PackageBackoffice(shippingAddress).FirstOrDefault();

            // Clear any previously saved quotes (eg. the user went back to their basket and started the process over again).
            _backoffice.SalePreparation().ClearShipmentRateQuotes();

            // get the quote using the "approved shipping method"
            var quote = shipment.ShipmentRateQuoteByShipMethod(model.ShipmentKey);

            // save the quote
            _backoffice.SalePreparation().SaveShipmentRateQuote(quote);

            // for cash providers we only want to authorize the payment
            var paymentMethod = _backoffice.SalePreparation().GetPaymentMethod();

            IPaymentResult attempt;

            if (Merchello.Core.Constants.ProviderKeys.Payment.CashPaymentProviderKey == new Guid(model.PaymentProviderKey))
            {
                // AuthorizePayment will save the invoice with an Invoice Number.
                //
                attempt = preparation.AuthorizePayment(new Guid(model.PaymentKey));
            }
            else // we
            {
                // TODO wire in redirect to Credit Card view or PayPal ... etc.
                throw new NotImplementedException();
            }

            _backoffice.Empty();
            _backoffice.Save();

            return true;
        }
 /// <summary>
 /// Packages the current basket instantiation into a collection of <see cref="IShipment"/> using the <see cref="PackagingStrategyBase"/> strategy
 /// </summary>
 /// <param name="backoffice">
 /// The backoffice.
 /// </param>
 /// <param name="destination">
 /// The destination.
 /// </param>
 /// <param name="strategy">
 /// The strategy.
 /// </param>
 /// <returns>
 /// A collection of <see cref="IShipment"/>
 /// </returns>
 public static IEnumerable <IShipment> PackageBackoffice(this IBackoffice backoffice, IAddress destination, PackagingStrategyBase strategy)
 {
     return(backoffice.PackageBackoffice(MerchelloContext.Current, destination, strategy));
 }
Example #13
0
        public IEnumerable<IShipmentRateQuote> GetShippingMethods(BackofficeAddItemModel model)
        {
            _customer = MerchelloContext.Services.CustomerService.GetAnyByKey(new Guid(model.CustomerKey));
            _backoffice = _customer.Backoffice();

            var shipment = _backoffice.PackageBackoffice(model.ShippingAddress.ToAddress()).FirstOrDefault();

            return shipment.ShipmentRateQuotes();
        }
Example #14
0
        public BackofficeOrderSummary ProcessesProductsToBackofficeOrder(BackofficeAddItemModel model)
        {
            _customer = MerchelloContext.Services.CustomerService.GetAnyByKey(new Guid(model.CustomerKey));
            _backoffice = _customer.Backoffice();

            _backoffice.Empty();
            _backoffice.Save();

            if (model.ProductKeys != null && model.ProductKeys.Any())
            {

                foreach (var key in model.ProductKeys)
                {
                    var extendedData = new ExtendedDataCollection();
                    //extendedData.SetValue("umbracoContentId", model.ContentId.ToString(CultureInfo.InvariantCulture));

                    var product = MerchelloContext.Services.ProductService.GetByKey(new Guid(key));

                    //if (model.OptionChoices != null && model.OptionChoices.Any())
                    //{
                    //    var variant = MerchelloContext.Services.ProductVariantService.GetProductVariantWithAttributes(product, model.OptionChoices);

                    //    extendedData.SetValue("isVariant", "true");

                    //    _backoffice.AddItem(variant, variant.Name, 1, extendedData);
                    //}
                    //else
                    //{
                    _backoffice.AddItem(product, product.Name, 1, extendedData);
                    //}
                }

                var salesPreparation = _customer.Backoffice().SalePreparation();

                salesPreparation.SaveBillToAddress(model.BillingAddress.ToAddress());
                salesPreparation.SaveShipToAddress(model.ShippingAddress.ToAddress());

                return GetBackofficeOrderSummary(salesPreparation);
            }
            else
            {
                return new BackofficeOrderSummary();
            }
        }
Example #15
0
        /// <summary>
        /// Saves the backoffice.
        /// </summary>
        /// <param name="merchelloContext">
        /// The merchello context.
        /// </param>
        /// <param name="backoffice">
        /// The backoffice.
        /// </param>
        internal static void Save(IMerchelloContext merchelloContext, IBackoffice backoffice)
        {
            // Update the backoffice item cache version so that it can be validated in the checkout
            ((Backoffice)backoffice).VersionKey = Guid.NewGuid();

            merchelloContext.Services.ItemCacheService.Save(((Backoffice)backoffice).ItemCache);

            Refresh(merchelloContext, backoffice);
        }
Example #16
0
 /// <summary>
 /// Empties the backoffice.
 /// </summary>
 /// <param name="merchelloContext">
 /// The merchello context.
 /// </param>
 /// <param name="backoffice">
 /// The backoffice.
 /// </param>
 internal static void Empty(IMerchelloContext merchelloContext, IBackoffice backoffice)
 {
     backoffice.Items.Clear();
     Save(merchelloContext, backoffice);
 }
Example #17
0
 /// <summary>
 /// Empties the backoffice.
 /// </summary>
 /// <param name="merchelloContext">
 /// The merchello context.
 /// </param>
 /// <param name="backoffice">
 /// The backoffice.
 /// </param>
 internal static void Empty(IMerchelloContext merchelloContext, IBackoffice backoffice)
 {
     backoffice.Items.Clear();
     Save(merchelloContext, backoffice);
 }
        /// <summary>
        /// The get basket checkout preparation.
        /// </summary>
        /// <param name="merchelloContext">
        /// The merchello context.
        /// </param>
        /// <param name="backoffice">
        /// The basket.
        /// </param>
        /// <returns>
        /// The <see cref="BasketSalePreparation"/>.
        /// </returns>
        internal static BackofficeSalePreparation GetBackofficeCheckoutPreparation(IMerchelloContext merchelloContext, IBackoffice backoffice)
        {
            var customer = backoffice.Customer;
            var itemCache = GetItemCache(merchelloContext, customer, backoffice.VersionKey);

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

            return new BackofficeSalePreparation(merchelloContext, itemCache, customer);
        }
 /// <summary>
 /// The get basket checkout preparation.
 /// </summary>
 /// <param name="backoffice">
 /// The basket.
 /// </param>
 /// <returns>
 /// The <see cref="BasketSalePreparation"/>.
 /// </returns>
 internal static BackofficeSalePreparation GetBackofficeCheckoutPreparation(IBackoffice backoffice)
 {
     return GetBackofficeCheckoutPreparation(Core.MerchelloContext.Current, backoffice);
 }
        /// <summary>
        /// The get basket checkout preparation.
        /// </summary>
        /// <param name="merchelloContext">
        /// The merchello context.
        /// </param>
        /// <param name="backoffice">
        /// The basket.
        /// </param>
        /// <returns>
        /// The <see cref="BasketSalePreparation"/>.
        /// </returns>
        internal static BackofficeSalePreparation GetBackofficeCheckoutPreparation(IMerchelloContext merchelloContext, IBackoffice backoffice)
        {
            var customer  = backoffice.Customer;
            var itemCache = GetItemCache(merchelloContext, customer, backoffice.VersionKey);

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

            return(new BackofficeSalePreparation(merchelloContext, itemCache, customer));
        }
 /// <summary>
 /// The get basket checkout preparation.
 /// </summary>
 /// <param name="backoffice">
 /// The basket.
 /// </param>
 /// <returns>
 /// The <see cref="BasketSalePreparation"/>.
 /// </returns>
 internal static BackofficeSalePreparation GetBackofficeCheckoutPreparation(IBackoffice backoffice)
 {
     return(GetBackofficeCheckoutPreparation(Core.MerchelloContext.Current, backoffice));
 }