wertyuio1 wrote:Hi Tim,
Just wondering do you have any idea how to implement Exporting the catalog to Pdf from the frontend, I know it can be done in Admin but can users do it?? Or can it be done.
Kind regards
Richard
I spent some time playing around with it but it looks like the URL to download the PDF catalog is denied if the user is not an administrator.
If you look in
ProductController.csPresentation -> Nop.Web -> Administration -> Controllers -> ProductController.cs
You can find the following code:
///////////////////////////////////////////////////////////////////
public ActionResult DownloadCatalogAsPdf()
{
if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
return AccessDeniedView();
try
{
var products = _productService.SearchProducts(0, 0, null, null, null, 0, string.Empty, false,
_workContext.WorkingLanguage.Id, new List<int>(),
ProductSortingEnum.Position, 0, int.MaxValue, true);
string fileName = string.Format("pdfcatalog_{0}_{1}.pdf", DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"), CommonHelper.GenerateRandomDigitCode(4));
string filePath = string.Format("{0}content\\files\\ExportImport\\{1}", this.Request.PhysicalApplicationPath, fileName);
_pdfService.PrintProductsToPdf(products, _workContext.WorkingLanguage, filePath);
var bytes = System.IO.File.ReadAllBytes(filePath);
return File(bytes, "application/pdf", fileName);
}
catch (Exception exc)
{
ErrorNotification(exc);
return RedirectToAction("List");
}
}
//////////////////////////////////////////////////////////////////////
I was wondering this was the problem
if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
return AccessDeniedView();
I tried replacing the return AccessDeniedView(); with the code under the "try," changing the variable names, but I could not get it to work. I also tried to take out the AccessDeniedView(); part but that did not do it. However, you might want to look at this code and try playing with it.
Here is an easy way you could allow your customers to download a PDF of your catalog from the public store side.
Once you have added all your products to your store you could go to admin and download the PDF of your catalog to you computer. Then you could upload your catalog to the root folder of your website and put a link to it on your store.
For example:
www.yourstore.com/catalog.PDF
The good side of doing it this way would be that you would not have to worry that you had caused a security problem by allowing access to part of the admin side.
The bad side of doing it this way is that you would have to upload a new version of you catalog when you made any changes to your products.
I am sorry I don't know the best way to do this, but you could use this method as a quick fix. I will let you know if I figure out the real way to do it.