public override object Map(object source, object target, Type sourceType, Type targetType, string prefix, MappingContext context) { var model = base.Map(source, target, sourceType, targetType, prefix, context) as ProductVariant; var variant = source as Kooboo.Commerce.Products.ProductVariant; // Final price var shoppingContext = new Kooboo.Commerce.Carts.ShoppingContext { Culture = context.ApiContext.Culture.Name }; if (!context.ApiContext.Customer.IsGuest()) { var service = new Kooboo.Commerce.Customers.CustomerService(context.ApiContext.Instance); var customer = service.FindByEmail(context.ApiContext.Customer.Email); if (customer != null) { shoppingContext.CustomerId = customer.Id; } } model.FinalPrice = variant.GetFinalPrice(shoppingContext); return(model); }
public override object Map(object source, object target, Type sourceType, Type targetType, string prefix, MappingContext context) { var model = base.Map(source, target, sourceType, targetType, prefix, context) as ProductVariant; var variant = source as Kooboo.Commerce.Products.ProductVariant; // Final price var shoppingContext = new Kooboo.Commerce.Carts.ShoppingContext { Culture = context.ApiContext.Culture.Name }; if (!context.ApiContext.Customer.IsGuest()) { var service = new Kooboo.Commerce.Customers.CustomerService(context.ApiContext.Instance); var customer = service.FindByEmail(context.ApiContext.Customer.Email); if (customer != null) { shoppingContext.CustomerId = customer.Id; } } model.FinalPrice = variant.GetFinalPrice(shoppingContext); return model; }
public int GetCartIdByCustomer(string email) { var service = new Core.ShoppingCartService(_context.Instance); var cart = service.FindByCustomerEmail(email); if (cart == null) { var customer = new Kooboo.Commerce.Customers.CustomerService(_context.Instance).FindByEmail(email); cart = Kooboo.Commerce.Carts.ShoppingCart.Create(customer); service.Create(cart); } return(cart.Id); }
public int AddAddress(int customerId, Address address) { var service = new Kooboo.Commerce.Customers.CustomerService(_context.Instance); var customer = service.Find(customerId); var addr = CreateAddress(address); if (String.IsNullOrEmpty(addr.FirstName) && String.IsNullOrEmpty(addr.LastName)) { addr.FirstName = customer.FirstName; addr.LastName = customer.LastName; } service.AddAddress(customer, addr); address.Id = addr.Id; return addr.Id; }
public int AddAddress(int customerId, Address address) { var service = new Kooboo.Commerce.Customers.CustomerService(_context.Instance); var customer = service.Find(customerId); var addr = CreateAddress(address); if (String.IsNullOrEmpty(addr.FirstName) && String.IsNullOrEmpty(addr.LastName)) { addr.FirstName = customer.FirstName; addr.LastName = customer.LastName; } service.AddAddress(customer, addr); address.Id = addr.Id; return(addr.Id); }
private Kooboo.Commerce.Customers.Address GetOrCreateAddress(int customerId, Address address) { var service = new Kooboo.Commerce.Customers.CustomerService(_context.Instance); Kooboo.Commerce.Customers.Address addr = null; if (address.Id > 0) { addr = service.Addresses().ById(address.Id); } else { _customerApi.AddAddress(customerId, address); addr = service.Addresses().ById(address.Id); } return(addr); }
private Kooboo.Commerce.Customers.Address GetOrCreateAddress(int customerId, Address address) { var service = new Kooboo.Commerce.Customers.CustomerService(_context.Instance); Kooboo.Commerce.Customers.Address addr = null; if (address.Id > 0) { addr = service.Addresses().ById(address.Id); } else { _customerApi.AddAddress(customerId, address); addr = service.Addresses().ById(address.Id); } return addr; }
public int GetCartIdByCustomer(string email) { var service = new Core.ShoppingCartService(_context.Instance); var cart = service.FindByCustomerEmail(email); if (cart == null) { var customer = new Kooboo.Commerce.Customers.CustomerService(_context.Instance).FindByEmail(email); cart = Kooboo.Commerce.Carts.ShoppingCart.Create(customer); service.Create(cart); } return cart.Id; }