Skip to content

Commit

Permalink
PT-14000: handle null Store in payment/shipment blade (#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksavosteev committed Oct 25, 2023
1 parent d1ad181 commit 5ce3b5a
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -406,32 +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.GetSettingValue(
ModuleConstants.Settings.General.OrderShipmentNewNumberTemplate.Name,
ModuleConstants.Settings.General.OrderShipmentNewNumberTemplate.DefaultValue);
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));
}

////Detect not whole shipped items
////TODO: LineItem partial shipping
//var shippedLineItemIds = order.Shipments.SelectMany(x => x.Items).Select(x => x.LineItemId);
var retVal = AbstractTypeFactory<Shipment>.TryCreateInstance();
retVal.Id = Guid.NewGuid().ToString();
retVal.Currency = order.Currency;
retVal.Status = "New";

////TODO Add check for digital products (don't add to shipment)
//retVal.Items = order.Items.Where(x => !shippedLineItemIds.Contains(x.Id))
// .Select(x => new coreModel.ShipmentItem(x)).ToList();
//return Ok(retVal.ToWebModel());
}
var numberTemplate = store.Settings.GetValue<string>(ModuleConstants.Settings.General.OrderShipmentNewNumberTemplate);
retVal.Number = _uniqueNumberGenerator.GenerateNumber(numberTemplate.ToString());

return NotFound();
return Ok(retVal);
}

/// <summary>
Expand All @@ -444,25 +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.GetSettingValue(
ModuleConstants.Settings.General.OrderPaymentInNewNumberTemplate.Name,
ModuleConstants.Settings.General.OrderPaymentInNewNumberTemplate.DefaultValue);
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 @@ -756,5 +754,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

0 comments on commit 5ce3b5a

Please sign in to comment.