Skip to content

Commit cc07338

Browse files
Merge branch 'issue-4498-Post-action-selected' into develop
# Conflicts: # upgradescripts/4.20-4.30 (under development)/upgrade.sql
2 parents 588588c + afd9460 commit cc07338

File tree

11 files changed

+203
-98
lines changed

11 files changed

+203
-98
lines changed

src/Presentation/Nop.Web/App_Data/Localization/defaultResources.nopres.xml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11064,6 +11064,9 @@
1106411064
<LocaleResource Name="Admin.Customers.OnlineCustomers.Fields.Location">
1106511065
<Value>Location</Value>
1106611066
</LocaleResource>
11067+
<LocaleResource Name="Admin.Customers.NoCustomers">
11068+
<Value>No customers selected</Value>
11069+
</LocaleResource>
1106711070
<LocaleResource Name="Admin.Dashboard">
1106811071
<Value>Dashboard</Value>
1106911072
</LocaleResource>
@@ -11907,6 +11910,9 @@
1190711910
<LocaleResource Name="Admin.Orders.List.Warehouse.Hint">
1190811911
<Value>Load orders with products from a specified warehouse.</Value>
1190911912
</LocaleResource>
11913+
<LocaleResource Name="Admin.Orders.NoOrders">
11914+
<Value>No orders selected</Value>
11915+
</LocaleResource>
1191011916
<LocaleResource Name="Admin.Orders.OrderItem.DeleteAssociatedGiftCardRecordError">
1191111917
<Value>This order item has an associated gift card record. Please delete it first</Value>
1191211918
</LocaleResource>
@@ -11957,10 +11963,7 @@
1195711963
</LocaleResource>
1195811964
<LocaleResource Name="Admin.Orders.PdfInvoice">
1195911965
<Value>Invoice (PDF)</Value>
11960-
</LocaleResource>
11961-
<LocaleResource Name="Admin.Orders.PdfInvoice.NoOrders">
11962-
<Value>No orders selected</Value>
11963-
</LocaleResource>
11966+
</LocaleResource>
1196411967
<LocaleResource Name="Admin.Orders.PdfInvoices">
1196511968
<Value>Print PDF invoices</Value>
1196611969
</LocaleResource>
@@ -12387,6 +12390,9 @@
1238712390
<LocaleResource Name="Admin.Plugins.Saved">
1238812391
<Value>The plugin has been updated successfully.</Value>
1238912392
</LocaleResource>
12393+
<LocaleResource Name="Admin.Products.NoProducts">
12394+
<Value>No products selected</Value>
12395+
</LocaleResource>
1239012396
<LocaleResource Name="Admin.Promotions">
1239112397
<Value>Promotions</Value>
1239212398
</LocaleResource>

src/Presentation/Nop.Web/Areas/Admin/Controllers/CustomerController.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,8 +1685,16 @@ public virtual IActionResult ExportXmlSelected(string selectedIds)
16851685
customers.AddRange(_customerService.GetCustomersByIds(ids));
16861686
}
16871687

1688-
var xml = _exportManager.ExportCustomersToXml(customers);
1689-
return File(Encoding.UTF8.GetBytes(xml), "application/xml", "customers.xml");
1688+
try
1689+
{
1690+
var xml = _exportManager.ExportCustomersToXml(customers);
1691+
return File(Encoding.UTF8.GetBytes(xml), "application/xml", "customers.xml");
1692+
}
1693+
catch (Exception exc)
1694+
{
1695+
_notificationService.ErrorNotification(exc);
1696+
return RedirectToAction("List");
1697+
}
16901698
}
16911699

16921700
#endregion

src/Presentation/Nop.Web/Areas/Admin/Controllers/OrderController.cs

Lines changed: 62 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -357,14 +357,13 @@ public virtual IActionResult ExportXmlAll(OrderSearchModel model)
357357
//ensure that we at least one order selected
358358
if (!orders.Any())
359359
{
360-
_notificationService.ErrorNotification(_localizationService.GetResource("Admin.Orders.PdfInvoice.NoOrders"));
360+
_notificationService.ErrorNotification(_localizationService.GetResource("Admin.Orders.NoOrders"));
361361
return RedirectToAction("List");
362362
}
363363

364364
try
365365
{
366366
var xml = _exportManager.ExportOrdersToXml(orders);
367-
368367
return File(Encoding.UTF8.GetBytes(xml), MimeTypes.ApplicationXml, "orders.xml");
369368
}
370369
catch (Exception exc)
@@ -390,16 +389,16 @@ public virtual IActionResult ExportXmlSelected(string selectedIds)
390389
orders.AddRange(_orderService.GetOrdersByIds(ids).Where(HasAccessToOrder));
391390
}
392391

393-
//ensure that we at least one order selected
394-
if (!orders.Any())
392+
try
393+
{
394+
var xml = _exportManager.ExportOrdersToXml(orders);
395+
return File(Encoding.UTF8.GetBytes(xml), MimeTypes.ApplicationXml, "orders.xml");
396+
}
397+
catch (Exception exc)
395398
{
396-
_notificationService.ErrorNotification(_localizationService.GetResource("Admin.Orders.PdfInvoice.NoOrders"));
399+
_notificationService.ErrorNotification(exc);
397400
return RedirectToAction("List");
398401
}
399-
400-
var xml = _exportManager.ExportOrdersToXml(orders);
401-
402-
return File(Encoding.UTF8.GetBytes(xml), MimeTypes.ApplicationXml, "orders.xml");
403402
}
404403

405404
[HttpPost, ActionName("ExportExcel")]
@@ -456,7 +455,7 @@ public virtual IActionResult ExportExcelAll(OrderSearchModel model)
456455
//ensure that we at least one order selected
457456
if (!orders.Any())
458457
{
459-
_notificationService.ErrorNotification(_localizationService.GetResource("Admin.Orders.PdfInvoice.NoOrders"));
458+
_notificationService.ErrorNotification(_localizationService.GetResource("Admin.Orders.NoOrders"));
460459
return RedirectToAction("List");
461460
}
462461

@@ -488,13 +487,6 @@ public virtual IActionResult ExportExcelSelected(string selectedIds)
488487
orders.AddRange(_orderService.GetOrdersByIds(ids).Where(HasAccessToOrder));
489488
}
490489

491-
//ensure that we at least one order selected
492-
if (!orders.Any())
493-
{
494-
_notificationService.ErrorNotification(_localizationService.GetResource("Admin.Orders.PdfInvoice.NoOrders"));
495-
return RedirectToAction("List");
496-
}
497-
498490
try
499491
{
500492
var bytes = _exportManager.ExportOrdersToXlsx(orders);
@@ -1034,18 +1026,26 @@ public virtual IActionResult PdfInvoiceAll(OrderSearchModel model)
10341026
//ensure that we at least one order selected
10351027
if (!orders.Any())
10361028
{
1037-
_notificationService.ErrorNotification(_localizationService.GetResource("Admin.Orders.PdfInvoice.NoOrders"));
1029+
_notificationService.ErrorNotification(_localizationService.GetResource("Admin.Orders.NoOrders"));
10381030
return RedirectToAction("List");
10391031
}
10401032

1041-
byte[] bytes;
1042-
using (var stream = new MemoryStream())
1033+
try
10431034
{
1044-
_pdfService.PrintOrdersToPdf(stream, orders, _orderSettings.GeneratePdfInvoiceInCustomerLanguage ? 0 : _workContext.WorkingLanguage.Id, model.VendorId);
1045-
bytes = stream.ToArray();
1046-
}
1035+
byte[] bytes;
1036+
using (var stream = new MemoryStream())
1037+
{
1038+
_pdfService.PrintOrdersToPdf(stream, orders, _orderSettings.GeneratePdfInvoiceInCustomerLanguage ? 0 : _workContext.WorkingLanguage.Id, model.VendorId);
1039+
bytes = stream.ToArray();
1040+
}
10471041

1048-
return File(bytes, MimeTypes.ApplicationPdf, "orders.pdf");
1042+
return File(bytes, MimeTypes.ApplicationPdf, "orders.pdf");
1043+
}
1044+
catch (Exception exc)
1045+
{
1046+
_notificationService.ErrorNotification(exc);
1047+
return RedirectToAction("List");
1048+
}
10491049
}
10501050

10511051
[HttpPost]
@@ -1072,21 +1072,22 @@ public virtual IActionResult PdfInvoiceSelected(string selectedIds)
10721072
vendorId = _workContext.CurrentVendor.Id;
10731073
}
10741074

1075-
//ensure that we at least one order selected
1076-
if (!orders.Any())
1075+
try
10771076
{
1078-
_notificationService.ErrorNotification(_localizationService.GetResource("Admin.Orders.PdfInvoice.NoOrders"));
1079-
return RedirectToAction("List");
1080-
}
1077+
byte[] bytes;
1078+
using (var stream = new MemoryStream())
1079+
{
1080+
_pdfService.PrintOrdersToPdf(stream, orders, _orderSettings.GeneratePdfInvoiceInCustomerLanguage ? 0 : _workContext.WorkingLanguage.Id, vendorId);
1081+
bytes = stream.ToArray();
1082+
}
10811083

1082-
byte[] bytes;
1083-
using (var stream = new MemoryStream())
1084+
return File(bytes, MimeTypes.ApplicationPdf, "orders.pdf");
1085+
}
1086+
catch (Exception exc)
10841087
{
1085-
_pdfService.PrintOrdersToPdf(stream, orders, _orderSettings.GeneratePdfInvoiceInCustomerLanguage ? 0 : _workContext.WorkingLanguage.Id, vendorId);
1086-
bytes = stream.ToArray();
1088+
_notificationService.ErrorNotification(exc);
1089+
return RedirectToAction("List");
10871090
}
1088-
1089-
return File(bytes, MimeTypes.ApplicationPdf, "orders.pdf");
10901091
}
10911092

10921093
//currently we use this method on the add product to order details pages
@@ -2469,14 +2470,22 @@ public virtual IActionResult PdfPackagingSlipAll(ShipmentSearchModel model)
24692470
return RedirectToAction("ShipmentList");
24702471
}
24712472

2472-
byte[] bytes;
2473-
using (var stream = new MemoryStream())
2473+
try
24742474
{
2475-
_pdfService.PrintPackagingSlipsToPdf(stream, shipments, _orderSettings.GeneratePdfInvoiceInCustomerLanguage ? 0 : _workContext.WorkingLanguage.Id);
2476-
bytes = stream.ToArray();
2477-
}
2475+
byte[] bytes;
2476+
using (var stream = new MemoryStream())
2477+
{
2478+
_pdfService.PrintPackagingSlipsToPdf(stream, shipments, _orderSettings.GeneratePdfInvoiceInCustomerLanguage ? 0 : _workContext.WorkingLanguage.Id);
2479+
bytes = stream.ToArray();
2480+
}
24782481

2479-
return File(bytes, MimeTypes.ApplicationPdf, "packagingslips.pdf");
2482+
return File(bytes, MimeTypes.ApplicationPdf, "packagingslips.pdf");
2483+
}
2484+
catch (Exception exc)
2485+
{
2486+
_notificationService.ErrorNotification(exc);
2487+
return RedirectToAction("ShipmentList");
2488+
}
24802489
}
24812490

24822491
[HttpPost]
@@ -2500,21 +2509,22 @@ public virtual IActionResult PdfPackagingSlipSelected(string selectedIds)
25002509
shipments = shipments.Where(HasAccessToShipment).ToList();
25012510
}
25022511

2503-
//ensure that we at least one shipment selected
2504-
if (!shipments.Any())
2512+
try
25052513
{
2506-
_notificationService.ErrorNotification(_localizationService.GetResource("Admin.Orders.Shipments.NoShipmentsSelected"));
2507-
return RedirectToAction("ShipmentList");
2508-
}
2514+
byte[] bytes;
2515+
using (var stream = new MemoryStream())
2516+
{
2517+
_pdfService.PrintPackagingSlipsToPdf(stream, shipments, _orderSettings.GeneratePdfInvoiceInCustomerLanguage ? 0 : _workContext.WorkingLanguage.Id);
2518+
bytes = stream.ToArray();
2519+
}
25092520

2510-
byte[] bytes;
2511-
using (var stream = new MemoryStream())
2521+
return File(bytes, MimeTypes.ApplicationPdf, "packagingslips.pdf");
2522+
}
2523+
catch (Exception exc)
25122524
{
2513-
_pdfService.PrintPackagingSlipsToPdf(stream, shipments, _orderSettings.GeneratePdfInvoiceInCustomerLanguage ? 0 : _workContext.WorkingLanguage.Id);
2514-
bytes = stream.ToArray();
2525+
_notificationService.ErrorNotification(exc);
2526+
return RedirectToAction("ShipmentList");
25152527
}
2516-
2517-
return File(bytes, MimeTypes.ApplicationPdf, "packagingslips.pdf");
25182528
}
25192529

25202530
[HttpPost]

src/Presentation/Nop.Web/Areas/Admin/Controllers/ProductController.cs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2222,9 +2222,16 @@ public virtual IActionResult ExportXmlSelected(string selectedIds)
22222222
products = products.Where(p => p.VendorId == _workContext.CurrentVendor.Id).ToList();
22232223
}
22242224

2225-
var xml = _exportManager.ExportProductsToXml(products);
2226-
2227-
return File(Encoding.UTF8.GetBytes(xml), MimeTypes.ApplicationXml, "products.xml");
2225+
try
2226+
{
2227+
var xml = _exportManager.ExportProductsToXml(products);
2228+
return File(Encoding.UTF8.GetBytes(xml), MimeTypes.ApplicationXml, "products.xml");
2229+
}
2230+
catch (Exception exc)
2231+
{
2232+
_notificationService.ErrorNotification(exc);
2233+
return RedirectToAction("List");
2234+
}
22282235
}
22292236

22302237
[HttpPost, ActionName("ExportToExcel")]
@@ -2268,7 +2275,6 @@ public virtual IActionResult ExportExcelAll(ProductSearchModel model)
22682275
try
22692276
{
22702277
var bytes = _exportManager.ExportProductsToXlsx(products);
2271-
22722278
return File(bytes, MimeTypes.TextXlsx, "products.xlsx");
22732279
}
22742280
catch (Exception exc)
@@ -2299,9 +2305,16 @@ public virtual IActionResult ExportExcelSelected(string selectedIds)
22992305
products = products.Where(p => p.VendorId == _workContext.CurrentVendor.Id).ToList();
23002306
}
23012307

2302-
var bytes = _exportManager.ExportProductsToXlsx(products);
2303-
2304-
return File(bytes, MimeTypes.TextXlsx, "products.xlsx");
2308+
try
2309+
{
2310+
var bytes = _exportManager.ExportProductsToXlsx(products);
2311+
return File(bytes, MimeTypes.TextXlsx, "products.xlsx");
2312+
}
2313+
catch (Exception exc)
2314+
{
2315+
_notificationService.ErrorNotification(exc);
2316+
return RedirectToAction("List");
2317+
}
23052318
}
23062319

23072320
[HttpPost]

src/Presentation/Nop.Web/Areas/Admin/Views/Blog/BlogComments.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,6 @@
264264
</div>
265265
</div>
266266
</div>
267-
<nop-alert asp-alert-id="deleteSelectedCommentsFailed " />
267+
<nop-alert asp-alert-id="deleteSelectedCommentsFailed" />
268268
<nop-alert asp-alert-id="approveSelectedFailed" />
269269
<nop-alert asp-alert-id="disapproveSelectedFailed" />

src/Presentation/Nop.Web/Areas/Admin/Views/Customer/List.cshtml

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -369,13 +369,20 @@
369369
$('#exportxml-selected').click(function (e) {
370370
e.preventDefault();
371371
var ids = selectedIds.join(",");
372-
$('#export-xml-selected-form #selectedIds').val(ids);
373-
$('#export-xml-selected-form').submit();
374-
updateTable('#customers-grid');
372+
if (!ids) {
373+
$('#exportXmlSelected-info').text("@T("Admin.Customers.NoCustomers")");
374+
$("#exportXmlSelected").click();
375+
}
376+
else {
377+
$('#export-xml-selected-form #selectedIds').val(ids);
378+
$('#export-xml-selected-form').submit();
379+
updateTable('#customers-grid');
380+
}
375381
return false;
376382
});
377383
});
378384
</script>
385+
<nop-alert asp-alert-id="exportXmlSelected" />
379386

380387
@*export selected (Excel). We don't use GET approach because it's limited to 2K-4K chars and won't work for large number of entities*@
381388
<form asp-controller="Customer" asp-action="ExportExcelSelected" method="post" id="export-excel-selected-form">
@@ -386,10 +393,17 @@
386393
$('#exportexcel-selected').click(function (e) {
387394
e.preventDefault();
388395
var ids = selectedIds.join(",");
389-
$('#export-excel-selected-form #selectedIds').val(ids);
390-
$('#export-excel-selected-form').submit();
391-
updateTable('#customers-grid');
396+
if (!ids) {
397+
$('#exportExcelSelected-info').text("@T("Admin.Customers.NoCustomers")");
398+
$("#exportExcelSelected").click();
399+
}
400+
else {
401+
$('#export-excel-selected-form #selectedIds').val(ids);
402+
$('#export-excel-selected-form').submit();
403+
updateTable('#customers-grid');
404+
}
392405
return false;
393406
});
394407
});
395-
</script>
408+
</script>
409+
<nop-alert asp-alert-id="exportExcelSelected" />

0 commit comments

Comments
 (0)