Skip to content

Commit

Permalink
Merge branch 'issue-4498-Post-action-selected' into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	upgradescripts/4.20-4.30 (under development)/upgrade.sql
  • Loading branch information
DmitriyKulagin committed Apr 21, 2020
2 parents 588588c + afd9460 commit cc07338
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11064,6 +11064,9 @@
<LocaleResource Name="Admin.Customers.OnlineCustomers.Fields.Location">
<Value>Location</Value>
</LocaleResource>
<LocaleResource Name="Admin.Customers.NoCustomers">
<Value>No customers selected</Value>
</LocaleResource>
<LocaleResource Name="Admin.Dashboard">
<Value>Dashboard</Value>
</LocaleResource>
Expand Down Expand Up @@ -11907,6 +11910,9 @@
<LocaleResource Name="Admin.Orders.List.Warehouse.Hint">
<Value>Load orders with products from a specified warehouse.</Value>
</LocaleResource>
<LocaleResource Name="Admin.Orders.NoOrders">
<Value>No orders selected</Value>
</LocaleResource>
<LocaleResource Name="Admin.Orders.OrderItem.DeleteAssociatedGiftCardRecordError">
<Value>This order item has an associated gift card record. Please delete it first</Value>
</LocaleResource>
Expand Down Expand Up @@ -11957,10 +11963,7 @@
</LocaleResource>
<LocaleResource Name="Admin.Orders.PdfInvoice">
<Value>Invoice (PDF)</Value>
</LocaleResource>
<LocaleResource Name="Admin.Orders.PdfInvoice.NoOrders">
<Value>No orders selected</Value>
</LocaleResource>
</LocaleResource>
<LocaleResource Name="Admin.Orders.PdfInvoices">
<Value>Print PDF invoices</Value>
</LocaleResource>
Expand Down Expand Up @@ -12387,6 +12390,9 @@
<LocaleResource Name="Admin.Plugins.Saved">
<Value>The plugin has been updated successfully.</Value>
</LocaleResource>
<LocaleResource Name="Admin.Products.NoProducts">
<Value>No products selected</Value>
</LocaleResource>
<LocaleResource Name="Admin.Promotions">
<Value>Promotions</Value>
</LocaleResource>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1685,8 +1685,16 @@ public virtual IActionResult ExportXmlSelected(string selectedIds)
customers.AddRange(_customerService.GetCustomersByIds(ids));
}

var xml = _exportManager.ExportCustomersToXml(customers);
return File(Encoding.UTF8.GetBytes(xml), "application/xml", "customers.xml");
try
{
var xml = _exportManager.ExportCustomersToXml(customers);
return File(Encoding.UTF8.GetBytes(xml), "application/xml", "customers.xml");
}
catch (Exception exc)
{
_notificationService.ErrorNotification(exc);
return RedirectToAction("List");
}
}

#endregion
Expand Down
114 changes: 62 additions & 52 deletions src/Presentation/Nop.Web/Areas/Admin/Controllers/OrderController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,14 +357,13 @@ public virtual IActionResult ExportXmlAll(OrderSearchModel model)
//ensure that we at least one order selected
if (!orders.Any())
{
_notificationService.ErrorNotification(_localizationService.GetResource("Admin.Orders.PdfInvoice.NoOrders"));
_notificationService.ErrorNotification(_localizationService.GetResource("Admin.Orders.NoOrders"));
return RedirectToAction("List");
}

try
{
var xml = _exportManager.ExportOrdersToXml(orders);

return File(Encoding.UTF8.GetBytes(xml), MimeTypes.ApplicationXml, "orders.xml");
}
catch (Exception exc)
Expand All @@ -390,16 +389,16 @@ public virtual IActionResult ExportXmlSelected(string selectedIds)
orders.AddRange(_orderService.GetOrdersByIds(ids).Where(HasAccessToOrder));
}

//ensure that we at least one order selected
if (!orders.Any())
try
{
var xml = _exportManager.ExportOrdersToXml(orders);
return File(Encoding.UTF8.GetBytes(xml), MimeTypes.ApplicationXml, "orders.xml");
}
catch (Exception exc)
{
_notificationService.ErrorNotification(_localizationService.GetResource("Admin.Orders.PdfInvoice.NoOrders"));
_notificationService.ErrorNotification(exc);
return RedirectToAction("List");
}

var xml = _exportManager.ExportOrdersToXml(orders);

return File(Encoding.UTF8.GetBytes(xml), MimeTypes.ApplicationXml, "orders.xml");
}

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

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

//ensure that we at least one order selected
if (!orders.Any())
{
_notificationService.ErrorNotification(_localizationService.GetResource("Admin.Orders.PdfInvoice.NoOrders"));
return RedirectToAction("List");
}

try
{
var bytes = _exportManager.ExportOrdersToXlsx(orders);
Expand Down Expand Up @@ -1034,18 +1026,26 @@ public virtual IActionResult PdfInvoiceAll(OrderSearchModel model)
//ensure that we at least one order selected
if (!orders.Any())
{
_notificationService.ErrorNotification(_localizationService.GetResource("Admin.Orders.PdfInvoice.NoOrders"));
_notificationService.ErrorNotification(_localizationService.GetResource("Admin.Orders.NoOrders"));
return RedirectToAction("List");
}

byte[] bytes;
using (var stream = new MemoryStream())
try
{
_pdfService.PrintOrdersToPdf(stream, orders, _orderSettings.GeneratePdfInvoiceInCustomerLanguage ? 0 : _workContext.WorkingLanguage.Id, model.VendorId);
bytes = stream.ToArray();
}
byte[] bytes;
using (var stream = new MemoryStream())
{
_pdfService.PrintOrdersToPdf(stream, orders, _orderSettings.GeneratePdfInvoiceInCustomerLanguage ? 0 : _workContext.WorkingLanguage.Id, model.VendorId);
bytes = stream.ToArray();
}

return File(bytes, MimeTypes.ApplicationPdf, "orders.pdf");
return File(bytes, MimeTypes.ApplicationPdf, "orders.pdf");
}
catch (Exception exc)
{
_notificationService.ErrorNotification(exc);
return RedirectToAction("List");
}
}

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

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

byte[] bytes;
using (var stream = new MemoryStream())
return File(bytes, MimeTypes.ApplicationPdf, "orders.pdf");
}
catch (Exception exc)
{
_pdfService.PrintOrdersToPdf(stream, orders, _orderSettings.GeneratePdfInvoiceInCustomerLanguage ? 0 : _workContext.WorkingLanguage.Id, vendorId);
bytes = stream.ToArray();
_notificationService.ErrorNotification(exc);
return RedirectToAction("List");
}

return File(bytes, MimeTypes.ApplicationPdf, "orders.pdf");
}

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

byte[] bytes;
using (var stream = new MemoryStream())
try
{
_pdfService.PrintPackagingSlipsToPdf(stream, shipments, _orderSettings.GeneratePdfInvoiceInCustomerLanguage ? 0 : _workContext.WorkingLanguage.Id);
bytes = stream.ToArray();
}
byte[] bytes;
using (var stream = new MemoryStream())
{
_pdfService.PrintPackagingSlipsToPdf(stream, shipments, _orderSettings.GeneratePdfInvoiceInCustomerLanguage ? 0 : _workContext.WorkingLanguage.Id);
bytes = stream.ToArray();
}

return File(bytes, MimeTypes.ApplicationPdf, "packagingslips.pdf");
return File(bytes, MimeTypes.ApplicationPdf, "packagingslips.pdf");
}
catch (Exception exc)
{
_notificationService.ErrorNotification(exc);
return RedirectToAction("ShipmentList");
}
}

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

//ensure that we at least one shipment selected
if (!shipments.Any())
try
{
_notificationService.ErrorNotification(_localizationService.GetResource("Admin.Orders.Shipments.NoShipmentsSelected"));
return RedirectToAction("ShipmentList");
}
byte[] bytes;
using (var stream = new MemoryStream())
{
_pdfService.PrintPackagingSlipsToPdf(stream, shipments, _orderSettings.GeneratePdfInvoiceInCustomerLanguage ? 0 : _workContext.WorkingLanguage.Id);
bytes = stream.ToArray();
}

byte[] bytes;
using (var stream = new MemoryStream())
return File(bytes, MimeTypes.ApplicationPdf, "packagingslips.pdf");
}
catch (Exception exc)
{
_pdfService.PrintPackagingSlipsToPdf(stream, shipments, _orderSettings.GeneratePdfInvoiceInCustomerLanguage ? 0 : _workContext.WorkingLanguage.Id);
bytes = stream.ToArray();
_notificationService.ErrorNotification(exc);
return RedirectToAction("ShipmentList");
}

return File(bytes, MimeTypes.ApplicationPdf, "packagingslips.pdf");
}

[HttpPost]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2222,9 +2222,16 @@ public virtual IActionResult ExportXmlSelected(string selectedIds)
products = products.Where(p => p.VendorId == _workContext.CurrentVendor.Id).ToList();
}

var xml = _exportManager.ExportProductsToXml(products);

return File(Encoding.UTF8.GetBytes(xml), MimeTypes.ApplicationXml, "products.xml");
try
{
var xml = _exportManager.ExportProductsToXml(products);
return File(Encoding.UTF8.GetBytes(xml), MimeTypes.ApplicationXml, "products.xml");
}
catch (Exception exc)
{
_notificationService.ErrorNotification(exc);
return RedirectToAction("List");
}
}

[HttpPost, ActionName("ExportToExcel")]
Expand Down Expand Up @@ -2268,7 +2275,6 @@ public virtual IActionResult ExportExcelAll(ProductSearchModel model)
try
{
var bytes = _exportManager.ExportProductsToXlsx(products);

return File(bytes, MimeTypes.TextXlsx, "products.xlsx");
}
catch (Exception exc)
Expand Down Expand Up @@ -2299,9 +2305,16 @@ public virtual IActionResult ExportExcelSelected(string selectedIds)
products = products.Where(p => p.VendorId == _workContext.CurrentVendor.Id).ToList();
}

var bytes = _exportManager.ExportProductsToXlsx(products);

return File(bytes, MimeTypes.TextXlsx, "products.xlsx");
try
{
var bytes = _exportManager.ExportProductsToXlsx(products);
return File(bytes, MimeTypes.TextXlsx, "products.xlsx");
}
catch (Exception exc)
{
_notificationService.ErrorNotification(exc);
return RedirectToAction("List");
}
}

[HttpPost]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,6 @@
</div>
</div>
</div>
<nop-alert asp-alert-id="deleteSelectedCommentsFailed " />
<nop-alert asp-alert-id="deleteSelectedCommentsFailed" />
<nop-alert asp-alert-id="approveSelectedFailed" />
<nop-alert asp-alert-id="disapproveSelectedFailed" />
28 changes: 21 additions & 7 deletions src/Presentation/Nop.Web/Areas/Admin/Views/Customer/List.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -369,13 +369,20 @@
$('#exportxml-selected').click(function (e) {
e.preventDefault();
var ids = selectedIds.join(",");
$('#export-xml-selected-form #selectedIds').val(ids);
$('#export-xml-selected-form').submit();
updateTable('#customers-grid');
if (!ids) {
$('#exportXmlSelected-info').text("@T("Admin.Customers.NoCustomers")");
$("#exportXmlSelected").click();
}
else {
$('#export-xml-selected-form #selectedIds').val(ids);
$('#export-xml-selected-form').submit();
updateTable('#customers-grid');
}
return false;
});
});
</script>
<nop-alert asp-alert-id="exportXmlSelected" />

@*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*@
<form asp-controller="Customer" asp-action="ExportExcelSelected" method="post" id="export-excel-selected-form">
Expand All @@ -386,10 +393,17 @@
$('#exportexcel-selected').click(function (e) {
e.preventDefault();
var ids = selectedIds.join(",");
$('#export-excel-selected-form #selectedIds').val(ids);
$('#export-excel-selected-form').submit();
updateTable('#customers-grid');
if (!ids) {
$('#exportExcelSelected-info').text("@T("Admin.Customers.NoCustomers")");
$("#exportExcelSelected").click();
}
else {
$('#export-excel-selected-form #selectedIds').val(ids);
$('#export-excel-selected-form').submit();
updateTable('#customers-grid');
}
return false;
});
});
</script>
</script>
<nop-alert asp-alert-id="exportExcelSelected" />
Loading

0 comments on commit cc07338

Please sign in to comment.