public void SaveCookie(QuickBuyModel model) { var cookie = HttpContext.Current.Request.Cookies["QuickBuy"] ?? new HttpCookie("QuickBuy"); cookie.Expires = DateTime.Now.AddDays(1d); cookie.HttpOnly = true; cookie.Value = HttpUtility.UrlEncode(model.ToString()); HttpContext.Current.Response.Cookies.Add(cookie); }
public QuickBuyViewModel(QuickBuyModel cookieModel) { Frequencies = Enum.GetValues(typeof(Frequency)).Cast <Frequency>().ToList(); FirstName = cookieModel.FirstName; LastName = cookieModel.LastName; Address = cookieModel.Address; ZipCode = cookieModel.ZipCode; City = cookieModel.ZipCode; PhoneNumber = cookieModel.PhoneNumber; Mail = cookieModel.Mail; }
private IOrderAddress CreateAddress(QuickBuyModel model, Cart cart, string name) { var shippingAddress = _orderGroupFactory.CreateOrderAddress(cart); shippingAddress.Id = name; shippingAddress.LastName = model.LastName; shippingAddress.FirstName = model.FirstName; shippingAddress.Line1 = model.Address; shippingAddress.PostalCode = model.ZipCode; shippingAddress.City = model.City; shippingAddress.CountryCode = "NOR"; return(shippingAddress); }
public QuickBuyModel GetFromCookie() { try { var cookie = HttpContext.Current.Request.Cookies["QuickBuy"]; var model = cookie == null ? new QuickBuyModel() : QuickBuyModel.FromString(HttpUtility.UrlDecode(cookie.Value)); return(model); } catch { return(new QuickBuyModel()); } }
private IPayment CreateQuickBuyPayment(QuickBuyModel model, IOrderGroup cart) { var payment = _orderGroupFactory.CreatePayment(cart); var paymentMethod = PaymentManager.GetPaymentMethodsByMarket(_market.MarketId.Value) .PaymentMethod.Rows.OfType <PaymentMethodDto.PaymentMethodRow>() .FirstOrDefault(x => x.SystemKeyword.Equals("quickbuy", StringComparison.OrdinalIgnoreCase)); if (paymentMethod != null) { payment.PaymentMethodId = paymentMethod.PaymentMethodId; } payment.Amount = cart.GetTotal().Amount; payment.PaymentType = PaymentType.Other; payment.TransactionType = TransactionType.Sale.ToString(); return(payment); }
public PurchaseOrderModel QuickBuyOrder(QuickBuyModel model, Guid customerId) { var cart = _orderRepository.LoadOrCreateCart <Cart>(customerId, Constants.Order.Cartname.Quickbuy); var item = _orderGroupFactory.CreateLineItem(model.Sku, cart); item.Quantity = 1; cart.GetFirstShipment().LineItems.Add(item); cart.GetFirstShipment().ShippingAddress = CreateAddress(model, cart, "Shipping"); if (!string.IsNullOrEmpty(model.CouponCode)) { cart.GetFirstForm().CouponCodes.Add(model.CouponCode); } cart.ValidateOrRemoveLineItems(ProcessValidationIssue); cart.UpdatePlacedPriceOrRemoveLineItems(ProcessValidationIssue); cart.UpdateInventoryOrRemoveLineItems(ProcessValidationIssue); _promotionEngine.Run(cart); cart.GetFirstForm().Payments.Add(CreateQuickBuyPayment(model, cart)); cart.GetFirstForm().Payments.FirstOrDefault().BillingAddress = CreateAddress(model, cart, "Billing"); cart.ProcessPayments(); cart.OrderNumberMethod = cart1 => GetInvoiceNumber(); var orderRef = _orderRepository.SaveAsPurchaseOrder(cart); var order = _orderRepository.Load <PurchaseOrder>(orderRef.OrderGroupId); order[Constants.Metadata.PurchaseOrder.Frequency] = model.Frequency.ToString(); order[Constants.Metadata.PurchaseOrder.LatestDelivery] = DateTime.Now.AddDays(5); OrderStatusManager.CompleteOrderShipment(order.GetFirstShipment() as Shipment); _orderRepository.Save(order); return(MapToModel(order)); }