コード例 #1
0
        public UpdatedSaleSummary UpdateShipRateQuote(string customerToken, string methodKey)
        {
            var tokenKey = customerToken.DecryptWithMachineKey();
            var customerKey = new Guid(tokenKey);
            var customerBase = _merchelloContext.Services.CustomerService.GetAnyByKey(customerKey);

            var preparation = customerBase.Basket().SalePreparation();
            preparation.RaiseCustomerEvents = false;

            var shipment = customerBase.Basket().PackageBasket(preparation.GetShipToAddress()).FirstOrDefault();
            var quote = shipment.ShipmentRateQuoteByShipMethod(methodKey);
            if (quote != null)
            {
                preparation.ClearShipmentRateQuotes();
                preparation.SaveShipmentRateQuote(quote);
            }

            var invoice = preparation.PrepareInvoice();

            var summary = new UpdatedSaleSummary()
                              {
                                  TotalLabel = "Total",
                                  InvoiceTotal = ModelExtensions.FormatPrice(invoice.Total, _currency.Symbol),
                                  TaxTotal = ModelExtensions.FormatPrice(invoice.TaxLineItems().Sum(x => x.TotalPrice), _currency.Symbol),
                                  DiscountsTotal = ModelExtensions.FormatPrice(invoice.DiscountLineItems().Sum(x => x.TotalPrice), _currency.Symbol),
                                  ShippingTotal = ModelExtensions.FormatPrice(invoice.ShippingLineItems().Sum(x => x.TotalPrice), _currency.Symbol)
                              };
            return summary;
        }
コード例 #2
0
        public UpdatedSaleSummary UpdateShipRateQuote(string customerToken, string methodKey)
        {
            var tokenKey = customerToken.DecryptWithMachineKey();
            var customerKey = new Guid(tokenKey);
            var customerBase = _merchelloContext.Services.CustomerService.GetAnyByKey(customerKey);

            var checkoutManager = customerBase.Basket().GetCheckoutManager();
            var shippingManager = checkoutManager.Shipping;
            var customerManager = checkoutManager.Customer;
            var paymentManager = checkoutManager.Payment;

            var shipment = customerBase.Basket().PackageBasket(customerManager.GetShipToAddress()).FirstOrDefault();
            var quote = shipment.ShipmentRateQuoteByShipMethod(methodKey);
            if (quote != null)
            {
                shippingManager.ClearShipmentRateQuotes();
                shippingManager.SaveShipmentRateQuote(quote);
            }

            var invoice = paymentManager.PrepareInvoice();

            var summary = new UpdatedSaleSummary
                              {
                                  TotalLabel = "Total",
                                  InvoiceTotal = ModelExtensions.FormatPrice(invoice.Total, _currency),
                                  TaxTotal = ModelExtensions.FormatPrice(invoice.TaxLineItems().Sum(x => x.TotalPrice), _currency),
                                  DiscountsTotal = ModelExtensions.FormatPrice(invoice.DiscountLineItems().Sum(x => x.TotalPrice), _currency),
                                  ShippingTotal = ModelExtensions.FormatPrice(invoice.ShippingLineItems().Sum(x => x.TotalPrice), _currency)
                              };
            return summary;
        }