Esempio n. 1
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);
        }
Esempio n. 2
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());
            }
        }
Esempio n. 3
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;
        }
Esempio n. 4
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();
            }
        }