diff --git a/src/VirtoCommerce.OrdersModule.Web/Controllers/Api/OrderModuleController.cs b/src/VirtoCommerce.OrdersModule.Web/Controllers/Api/OrderModuleController.cs index 52b29fd5..d68fdc49 100644 --- a/src/VirtoCommerce.OrdersModule.Web/Controllers/Api/OrderModuleController.cs +++ b/src/VirtoCommerce.OrdersModule.Web/Controllers/Api/OrderModuleController.cs @@ -406,21 +406,26 @@ public async Task UpdateOrder([FromBody] CustomerOrder customerOrd public async Task> GetNewShipment(string id) { var order = await _customerOrderService.GetNoCloneAsync(id, CustomerOrderResponseGroup.Full.ToString()); - if (order != null) + if (order == null) { - var retVal = AbstractTypeFactory.TryCreateInstance(); - retVal.Id = Guid.NewGuid().ToString(); - retVal.Currency = order.Currency; - retVal.Status = "New"; - - var store = await _storeService.GetNoCloneAsync(order.StoreId, StoreResponseGroup.StoreInfo.ToString()); - var numberTemplate = store.Settings.GetValue(ModuleConstants.Settings.General.OrderShipmentNewNumberTemplate); - retVal.Number = _uniqueNumberGenerator.GenerateNumber(numberTemplate.ToString()); + return NotFound(); + } - return Ok(retVal); + var store = await _storeService.GetNoCloneAsync(order.StoreId, StoreResponseGroup.StoreInfo.ToString()); + if (store == null) + { + return BadRequest(GetNoStoreErrorMessage(order)); } - return NotFound(); + var retVal = AbstractTypeFactory.TryCreateInstance(); + retVal.Id = Guid.NewGuid().ToString(); + retVal.Currency = order.Currency; + retVal.Status = "New"; + + var numberTemplate = store.Settings.GetValue(ModuleConstants.Settings.General.OrderShipmentNewNumberTemplate); + retVal.Number = _uniqueNumberGenerator.GenerateNumber(numberTemplate.ToString()); + + return Ok(retVal); } /// @@ -433,23 +438,29 @@ public async Task> GetNewShipment(string id) public async Task> GetNewPayment(string id) { var order = await _customerOrderService.GetNoCloneAsync(id, CustomerOrderResponseGroup.Full.ToString()); - if (order != null) + if (order == null) { - var retVal = AbstractTypeFactory.TryCreateInstance(); - retVal.Id = Guid.NewGuid().ToString(); - retVal.Currency = order.Currency; - retVal.CustomerId = order.CustomerId; - retVal.Status = retVal.PaymentStatus.ToString(); + return NotFound(); + } - var store = await _storeService.GetNoCloneAsync(order.StoreId, StoreResponseGroup.StoreInfo.ToString()); - var numberTemplate = store.Settings.GetValue(ModuleConstants.Settings.General.OrderPaymentInNewNumberTemplate); - retVal.Number = _uniqueNumberGenerator.GenerateNumber(numberTemplate.ToString()); - return Ok(retVal); + var store = await _storeService.GetNoCloneAsync(order.StoreId, StoreResponseGroup.StoreInfo.ToString()); + if (store == null) + { + return BadRequest(GetNoStoreErrorMessage(order)); } - return NotFound(); + var retVal = AbstractTypeFactory.TryCreateInstance(); + retVal.Id = Guid.NewGuid().ToString(); + retVal.Currency = order.Currency; + retVal.CustomerId = order.CustomerId; + retVal.Status = retVal.PaymentStatus.ToString(); + + var numberTemplate = store.Settings.GetValue(ModuleConstants.Settings.General.OrderPaymentInNewNumberTemplate); + retVal.Number = _uniqueNumberGenerator.GenerateNumber(numberTemplate.ToString()); + return Ok(retVal); } + /// /// Delete a whole customer orders /// @@ -741,5 +752,10 @@ private async Task ValidateAsync(CustomerOrder customerOrder) return new ValidationResult(); } + + private static string GetNoStoreErrorMessage(CustomerOrder order) + { + return $"Store {order.StoreId} does not exist in the system. Please create {order.StoreId} store or select another store for the order."; + } } } diff --git a/src/VirtoCommerce.OrdersModule.Web/Scripts/blades/payment-detail.js b/src/VirtoCommerce.OrdersModule.Web/Scripts/blades/payment-detail.js index 82324be1..465a0b3d 100644 --- a/src/VirtoCommerce.OrdersModule.Web/Scripts/blades/payment-detail.js +++ b/src/VirtoCommerce.OrdersModule.Web/Scripts/blades/payment-detail.js @@ -28,7 +28,10 @@ angular.module('virtoCommerce.orderModule') foundField.isReadOnly = false; } - customerOrders.getNewPayment({ id: blade.customerOrder.id }, blade.initialize); + customerOrders.getNewPayment({ id: blade.customerOrder.id }, blade.initialize, function (error) { + blade.isLocked = true; + bladeNavigationService.setError(error.data, blade); + }); } else { blade.isLocked = !blade.currentEntity || (blade.currentEntity.status === 'Paid' || blade.currentEntity.cancelledState === 'Requested' @@ -127,6 +130,10 @@ angular.module('virtoCommerce.orderModule') } blade.fetchVendors = function (criteria) { + if (blade.isLocked) { + return []; + } + return members.search(criteria); } @@ -154,7 +161,7 @@ angular.module('virtoCommerce.orderModule') blade.customInitialize = function () { if (!blade.currentEntity) { return; - } + } blade.isLocked = blade.currentEntity.status === 'Paid' || blade.currentEntity.cancelledState === 'Completed' || blade.currentEntity.isCancelled; }; diff --git a/src/VirtoCommerce.OrdersModule.Web/Scripts/blades/shipment-detail.js b/src/VirtoCommerce.OrdersModule.Web/Scripts/blades/shipment-detail.js index 9a7da92a..f9ed11e1 100644 --- a/src/VirtoCommerce.OrdersModule.Web/Scripts/blades/shipment-detail.js +++ b/src/VirtoCommerce.OrdersModule.Web/Scripts/blades/shipment-detail.js @@ -23,7 +23,10 @@ angular.module('virtoCommerce.orderModule') foundField.isReadOnly = false; } - customerOrders.getNewShipment({ id: blade.customerOrder.id }, blade.initialize); + customerOrders.getNewShipment({ id: blade.customerOrder.id }, blade.initialize, function (error) { + blade.isLocked = true; + bladeNavigationService.setError(error.data, blade); + }); } else { blade.isLocked = !blade.currentEntity || blade.currentEntity.status === 'Send' || blade.currentEntity.cancelledState === 'Completed' @@ -62,6 +65,10 @@ angular.module('virtoCommerce.orderModule') } blade.fetchEmployees = function (criteria) { + if (blade.isLocked) { + return []; + } + criteria.memberType = 'Employee'; criteria.deepSearch = true; criteria.sort = 'name'; @@ -84,6 +91,10 @@ angular.module('virtoCommerce.orderModule') } blade.fetchVendors = function (criteria) { + if (blade.isLocked) { + return []; + } + return members.search(criteria); }