Posted on 21/10/2024 10:25:50
Hi Nicolai,
In this case, it's using the PDF method, not even doing pdf=true. I may be wrong thinking this should be fixed in the template. Here is our code
public static void GenerateCertificationForm(Order order)
{
if(order is null
|| !order.Complete
|| order.CheckoutPageId.Equals(0))
{
return;
}
var certificationFormPathField = order.OrderFieldValues.GetOrderFieldValue(Constants.OrderFields.OrderCertificationFormPath);
if(certificationFormPathField is null)
{
return;
}
var checkoutPage = Dynamicweb.Services.Pages.GetPage(order.CheckoutPageId);
if(checkoutPage is null)
{
return;
}
var formCertificationPage = Dynamicweb.Services.Pages.GetPageByNavigationTag(checkoutPage.AreaId, Constants.Miscellaneous.FormNavigationTag);
if(formCertificationPage is null)
{
return;
}
var url = string.Concat(Dynamicweb.Context.Current.Request.Url.Scheme, "://", Dynamicweb.Context.Current.Request.Url.Host);
url += Dynamicweb.Frontend.SearchEngineFriendlyURLs.GetFriendlyUrl(formCertificationPage.ID);
var pid = Dynamicweb.Services.Paragraphs.GetParagraphsByPageId(formCertificationPage.ID).FirstOrDefault(p => p.ModuleSystemName.Equals("eCom_CustomerCenter") && p.ShowParagraph)?.ID ?? 0;
if (pid > 0)
{
url += $"?CC{pid}=Order&OrderID={order.Id}";
}
var user = Dynamicweb.Security.UserManagement.User.GetCurrentExtranetUser();
try
{
var pdf = new Pdf(url, user?.UserName ?? string.Empty, user?.DecryptedPassword ?? string.Empty, false, false, 15, 15, Pdf.GetPaperSizeValue(SystemConfiguration.Instance.GetValue(" /Globalsettings/Settings/Pdf/PageSize")));
var folderPath = $"/Files/Files/CommonwealthCharterAcademy/OrderCertificationForms";
var pdfFilePath = $"{folderPath}/{order.Id}_Certification_Form.pdf";
var pdfFileServerPath = Dynamicweb.Core.SystemInformation.MapPath(pdfFilePath);
System.IO.Directory.CreateDirectory(Dynamicweb.Core.SystemInformation.MapPath(folderPath));
pdf.SaveToFile(pdfFileServerPath);
pdf.Dispose();
certificationFormPathField.Value = pdfFileServerPath;
Dynamicweb.Ecommerce.Services.Orders.Save(order);
}
catch(Exception ex)
{
OrderDebuggingInfo.Save(order, ex.Message + ". " + ex.InnerException, "OrderCertificationForm");
}
}
Best Regards,
Nuno Aguiar