public IHttpActionResult Create(webModel.Store store) { var coreStore = store.ToCoreModel(_shippingService.GetAllShippingMethods(), _paymentService.GetAllPaymentMethods(), _taxService.GetAllTaxProviders()); var retVal = _storeService.Create(coreStore); return(Ok(retVal.ToWebModel())); }
public virtual CustomerOrder GetById(string orderId, CustomerOrderResponseGroup respGroup) { CustomerOrder retVal = null; using (var repository = _repositoryFactory()) { var orderEntity = repository.GetCustomerOrderById(orderId, respGroup); if (orderEntity != null) { retVal = orderEntity.ToCoreModel(_shippingMethodsService.GetAllShippingMethods(), _paymentMethodsService.GetAllPaymentMethods()); if ((respGroup & CustomerOrderResponseGroup.WithProducts) == CustomerOrderResponseGroup.WithProducts) { var productIds = retVal.Items.Select(x => x.ProductId).ToArray(); var products = _productService.GetByIds(productIds, Domain.Catalog.Model.ItemResponseGroup.ItemInfo); foreach (var lineItem in retVal.Items) { var product = products.FirstOrDefault(x => x.Id == lineItem.ProductId); if (product != null) { lineItem.Product = product; } } } } } _dynamicPropertyService.LoadDynamicPropertyValues(retVal); _eventPublisher.Publish(new OrderChangeEvent(EntryState.Unchanged, retVal, retVal)); return(retVal); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { object retVal; var obj = JObject.Load(reader); if (objectType == typeof(PaymentMethod)) { var paymentGatewayCode = obj["code"].Value <string>(); retVal = _paymentMethodsService.GetAllPaymentMethods().FirstOrDefault(x => x.Code.EqualsInvariant(paymentGatewayCode)); } else if (objectType == typeof(ShippingMethod)) { var shippingGatewayCode = obj["code"].Value <string>(); retVal = _shippingMethodsService.GetAllShippingMethods().FirstOrDefault(x => x.Code.EqualsInvariant(shippingGatewayCode)); } else { var tryCreateInstance = typeof(AbstractTypeFactory <>).MakeGenericType(objectType).GetMethods().FirstOrDefault(x => x.Name.EqualsInvariant("TryCreateInstance") && x.GetParameters().Length == 0); retVal = tryCreateInstance?.Invoke(null, null); } //Reset ChildrenOperations property to prevent polymorphic deserialization error var operation = retVal as IOperation; if (operation != null) { obj.Remove("childrenOperations"); } serializer.Populate(obj.CreateReader(), retVal); return(retVal); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { object retVal = null; var obj = JObject.Load(reader); if (typeof(Store).IsAssignableFrom(objectType)) { retVal = AbstractTypeFactory <Store> .TryCreateInstance(); } else if (typeof(SearchCriteria).IsAssignableFrom(objectType)) { retVal = AbstractTypeFactory <SearchCriteria> .TryCreateInstance(); } else if (objectType == typeof(PaymentMethod)) { var paymentGatewayCode = obj["code"].Value <string>(); retVal = _paymentMethodsService.GetAllPaymentMethods().FirstOrDefault(x => x.Code.EqualsInvariant(paymentGatewayCode)); } else if (objectType == typeof(ShippingMethod)) { var shippingGatewayCode = obj["code"].Value <string>(); retVal = _shippingMethodsService.GetAllShippingMethods().FirstOrDefault(x => x.Code.EqualsInvariant(shippingGatewayCode)); } else if (objectType == typeof(TaxProvider)) { var taxProviderCode = obj["code"].Value <string>(); retVal = _taxService.GetAllTaxProviders().FirstOrDefault(x => x.Code.EqualsInvariant(taxProviderCode)); } serializer.Populate(obj.CreateReader(), retVal); return(retVal); }
public coreModel.Store[] GetByIds(string[] ids) { var retVal = new List <coreModel.Store>(); using (var repository = _repositoryFactory()) { var fulfillmentCenters = _commerceService.GetAllFulfillmentCenters().ToList(); var dbStores = repository.GetStoresByIds(ids); foreach (var dbStore in dbStores) { //Load original typed shipping method and populate it personalized information from db var store = dbStore.ToCoreModel(_shippingService.GetAllShippingMethods(), _paymentService.GetAllPaymentMethods(), _taxService.GetAllTaxProviders()); store.ReturnsFulfillmentCenter = fulfillmentCenters.FirstOrDefault(x => x.Id == dbStore.ReturnsFulfillmentCenterId); store.FulfillmentCenter = fulfillmentCenters.FirstOrDefault(x => x.Id == dbStore.FulfillmentCenterId); //Set default settings for store it can be override by store instance setting in LoadEntitySettingsValues store.Settings = _settingManager.GetModuleSettings("VirtoCommerce.Store"); _settingManager.LoadEntitySettingsValues(store); _dynamicPropertyService.LoadDynamicPropertyValues(store); retVal.Add(store); } } _commerceService.LoadSeoForObjects(retVal.ToArray()); return(retVal.ToArray()); }
public Store[] GetByIds(string[] ids) { var stores = new List <Store>(); using (var repository = _repositoryFactory()) { var fulfillmentCenters = _commerceService.GetAllFulfillmentCenters().ToList(); var dbStores = repository.GetStoresByIds(ids); foreach (var dbStore in dbStores) { var store = AbstractTypeFactory <Store> .TryCreateInstance(); dbStore.ToModel(store); //Return all registered methods with store settings store.PaymentMethods = _paymentService.GetAllPaymentMethods(); foreach (var paymentMethod in store.PaymentMethods) { var dbStoredPaymentMethod = dbStore.PaymentMethods.FirstOrDefault(x => x.Code.EqualsInvariant(paymentMethod.Code)); if (dbStoredPaymentMethod != null) { dbStoredPaymentMethod.ToModel(paymentMethod); } } store.ShippingMethods = _shippingService.GetAllShippingMethods(); foreach (var shippingMethod in store.ShippingMethods) { var dbStoredShippingMethod = dbStore.ShippingMethods.FirstOrDefault(x => x.Code.EqualsInvariant(shippingMethod.Code)); if (dbStoredShippingMethod != null) { dbStoredShippingMethod.ToModel(shippingMethod); } } store.TaxProviders = _taxService.GetAllTaxProviders(); foreach (var taxProvider in store.TaxProviders) { var dbStoredTaxProvider = dbStore.TaxProviders.FirstOrDefault(x => x.Code.EqualsInvariant(taxProvider.Code)); if (dbStoredTaxProvider != null) { dbStoredTaxProvider.ToModel(taxProvider); } } store.ReturnsFulfillmentCenter = fulfillmentCenters.FirstOrDefault(x => x.Id == dbStore.ReturnsFulfillmentCenterId); store.FulfillmentCenter = fulfillmentCenters.FirstOrDefault(x => x.Id == dbStore.FulfillmentCenterId); //Set default settings for store it can be override by store instance setting in LoadEntitySettingsValues store.Settings = _settingManager.GetModuleSettings("VirtoCommerce.Store"); _settingManager.LoadEntitySettingsValues(store); stores.Add(store); } } var result = stores.ToArray(); _dynamicPropertyService.LoadDynamicPropertyValues(result); _commerceService.LoadSeoForObjects(result); return(result); }
public Cart GetCartWithShipment(string shipmentId) { var cart = GetCart(); var shipmentRate = _shipmentService.GetAllShippingMethods().SelectMany(x => x.MethodRates).FirstOrDefault(x => x.Id == shipmentId)?.Rate ?? 0; cart.Shipment = shipmentRate; cart.Total = cart.SubTotal + cart.Taxes + cart.Shipment; return(cart); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { object retVal; var obj = JObject.Load(reader); if (objectType == typeof(PaymentMethod)) { var paymentGatewayCode = obj["code"].Value <string>(); retVal = _paymentMethodsService.GetAllPaymentMethods().FirstOrDefault(x => x.Code.EqualsInvariant(paymentGatewayCode)); } else if (objectType == typeof(ShippingMethod)) { var shippingGatewayCode = obj["code"].Value <string>(); retVal = _shippingMethodsService.GetAllShippingMethods().FirstOrDefault(x => x.Code.EqualsInvariant(shippingGatewayCode)); } else { var tryCreateInstance = typeof(AbstractTypeFactory <>).MakeGenericType(objectType).GetMethods().FirstOrDefault(x => x.Name.EqualsInvariant("TryCreateInstance") && x.GetParameters().Length == 0); retVal = tryCreateInstance?.Invoke(null, null); } //Reset ChildrenOperations property to prevent polymorphic deserialization error var operation = retVal as IOperation; if (operation != null) { obj.Remove("childrenOperations"); } var payment = operation as PaymentIn; if (payment != null) { var paymentStatus = obj["paymentStatus"].Value <string>(); var hasStatusValue = Enum.IsDefined(typeof(PaymentStatus), paymentStatus); if (!hasStatusValue) { obj["paymentStatus"] = PaymentStatus.Custom.ToString(); } } serializer.Populate(obj.CreateReader(), retVal); // The ChildrenOperations property was reset on lines 57-61, so now we rebuild it if (operation != null) { operation.ChildrenOperations = OperationUtilities.GetAllChildOperations(operation); } return(retVal); }
public coreModel.Store GetById(string id) { coreModel.Store retVal = null; using (var repository = _repositoryFactory()) { var entity = repository.GetStoreById(id); if (entity != null) { //Load original typed shipping method and populate it personalized information from db retVal = entity.ToCoreModel(_shippingService.GetAllShippingMethods(), _paymentService.GetAllPaymentMethods(), _taxService.GetAllTaxProviders()); var fulfillmentCenters = _commerceService.GetAllFulfillmentCenters().ToList(); retVal.ReturnsFulfillmentCenter = fulfillmentCenters.FirstOrDefault(x => x.Id == entity.ReturnsFulfillmentCenterId); retVal.FulfillmentCenter = fulfillmentCenters.FirstOrDefault(x => x.Id == entity.FulfillmentCenterId); _commerceService.LoadSeoForObjects(new[] { retVal }); _settingManager.LoadEntitySettingsValues(retVal); _dynamicPropertyService.LoadDynamicPropertyValues(retVal); } } return(retVal); }
public SearchResult Search(SearchCriteria criteria) { SearchResult retVal = null; using (var repository = _orderRepositoryFactory()) { var query = repository.CustomerOrders; if (criteria.CustomerId != null) { query = query.Where(x => x.CustomerId == criteria.CustomerId); } if (criteria.StoreIds != null && criteria.StoreIds.Any()) { query = query.Where(x => criteria.StoreIds.Contains(x.StoreId)); } if (criteria.EmployeeId != null) { query = query.Where(x => x.EmployeeId == criteria.EmployeeId); } if (criteria.StartDate != null) { query = query.Where(x => x.CreatedDate >= criteria.StartDate); } if (criteria.EndDate != null) { query = query.Where(x => x.CreatedDate <= criteria.EndDate); } if ((criteria.ResponseGroup & ResponseGroup.WithDiscounts) == ResponseGroup.WithDiscounts) { query = query.Include(x => x.Discounts); } if ((criteria.ResponseGroup & ResponseGroup.WithAddresses) == ResponseGroup.WithAddresses) { query = query.Include(x => x.Addresses); } if ((criteria.ResponseGroup & ResponseGroup.WithItems) == ResponseGroup.WithItems) { query = query.Include(x => x.Items); if ((criteria.ResponseGroup & ResponseGroup.WithDiscounts) == ResponseGroup.WithDiscounts) { query = query.Include(x => x.Items.Select(y => y.Discounts)); } } if ((criteria.ResponseGroup & ResponseGroup.WithInPayments) == ResponseGroup.WithInPayments) { query = query.Include(x => x.InPayments); } if ((criteria.ResponseGroup & ResponseGroup.WithShipments) == ResponseGroup.WithShipments) { query = query.Include(x => x.Shipments); if ((criteria.ResponseGroup & ResponseGroup.WithItems) == ResponseGroup.WithItems) { query = query.Include(x => x.Shipments.Select(y => y.Items)); } if ((criteria.ResponseGroup & ResponseGroup.WithDiscounts) == ResponseGroup.WithDiscounts) { query = query.Include(x => x.Shipments.Select(y => y.Discounts)); } if ((criteria.ResponseGroup & ResponseGroup.WithAddresses) == ResponseGroup.WithAddresses) { query = query.Include(x => x.Shipments.Select(y => y.Addresses)); } } retVal = new SearchResult { TotalCount = query.Count(), CustomerOrders = query.OrderByDescending(x => x.CreatedDate) .Skip(criteria.Start) .Take(criteria.Count) .ToArray() .Select(x => x.ToCoreModel(_shippingMethodsService.GetAllShippingMethods(), _paymentMethodsService.GetAllPaymentMethods())) .ToList() }; } return(retVal); }
public ICollection <ShippingMethod> ShippingMethods() { return(_shippingMethodService.GetAllShippingMethods()); }