Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PT-14000: handle null Store in payment/shipment blade #384

Merged
merged 2 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -406,21 +406,26 @@ public async Task<ActionResult> UpdateOrder([FromBody] CustomerOrder customerOrd
public async Task<ActionResult<Shipment>> GetNewShipment(string id)
{
var order = await _customerOrderService.GetNoCloneAsync(id, CustomerOrderResponseGroup.Full.ToString());
if (order != null)
if (order == null)
{
var retVal = AbstractTypeFactory<Shipment>.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<string>(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<Shipment>.TryCreateInstance();
retVal.Id = Guid.NewGuid().ToString();
retVal.Currency = order.Currency;
retVal.Status = "New";

var numberTemplate = store.Settings.GetValue<string>(ModuleConstants.Settings.General.OrderShipmentNewNumberTemplate);
retVal.Number = _uniqueNumberGenerator.GenerateNumber(numberTemplate.ToString());

return Ok(retVal);
}

/// <summary>
Expand All @@ -433,23 +438,29 @@ public async Task<ActionResult<Shipment>> GetNewShipment(string id)
public async Task<ActionResult<PaymentIn>> GetNewPayment(string id)
{
var order = await _customerOrderService.GetNoCloneAsync(id, CustomerOrderResponseGroup.Full.ToString());
if (order != null)
if (order == null)
{
var retVal = AbstractTypeFactory<PaymentIn>.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<string>(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<PaymentIn>.TryCreateInstance();
retVal.Id = Guid.NewGuid().ToString();
retVal.Currency = order.Currency;
retVal.CustomerId = order.CustomerId;
retVal.Status = retVal.PaymentStatus.ToString();

var numberTemplate = store.Settings.GetValue<string>(ModuleConstants.Settings.General.OrderPaymentInNewNumberTemplate);
retVal.Number = _uniqueNumberGenerator.GenerateNumber(numberTemplate.ToString());
return Ok(retVal);
}


/// <summary>
/// Delete a whole customer orders
/// </summary>
Expand Down Expand Up @@ -741,5 +752,10 @@ private async Task<ValidationResult> 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.";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -127,6 +130,10 @@ angular.module('virtoCommerce.orderModule')
}

blade.fetchVendors = function (criteria) {
if (blade.isLocked) {
return [];
}

return members.search(criteria);
}

Expand Down Expand Up @@ -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;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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';
Expand All @@ -84,6 +91,10 @@ angular.module('virtoCommerce.orderModule')
}

blade.fetchVendors = function (criteria) {
if (blade.isLocked) {
return [];
}

return members.search(criteria);
}

Expand Down
Loading