asef. Posted March 19, 2019 Share Posted March 19, 2019 (edited) Bonjour à tous, J'ai besoin de générer un nouveau fichier pdf certifiant l'authenticité de mes produits dans la commande de mes clients en back office. L'objectif étant de cliquer sur un bouton qui me télécharger le fichier ".pdf" avec les informations du produit sélectionné (la fiche caractéristique). Aujourd’hui, niveau fonctionnel, j'en suis à 80% de mon objectif. Voici un récapitulatif des modifications apportées: - Ajout du bouton "print" à la ligne du produit dans la page commande d'un client (src/override/controllers/admin/templates/orders/_product_line.tpl). <a href="{$link->getAdminLink('AdminPdf')|escape:'html':'UTF-8'}&submitAction=generateMyPDF&id_order={$order->id}" class="print_my_pdf_product_line"> <i class="icon-print"></i> {l s='Certificat' d='Admin.Actions'} </a> - Ajout de ma fonction qui génère mon pdf (src/controllers/admin/AdminPdfController.php). public function generateMyPDFByIdOrder($id_order) { $order = new Order((int)$id_order); if (!Validate::isLoadedObject($order)) { die($this->trans('The order cannot be found within your database.', array(), 'Admin.Orderscustomers.Notification')); } $order_invoice_list = $order->getInvoicesCollection(); require_once _PS_MODULE_DIR_ . 'cm_myPdf/HTMLTemplateMyPdf.php'; $pdf = new PDF($order_invoice_list, 'CustomPdf', $this->context->smarty); $pdf->render(); } - Ajout de ma fonction qui va construire et remplir mon pdf (src/modules/cm_myPdf/HTMLTemplateCertificatPdf.php). class HTMLTemplateCustomPdf extends HTMLTemplate { public $custom_model ; public function __construct($custom_object, $smarty) { $this -> custom_model = $custom_object; $this -> smarty = $smarty; // header informations $id_lang = Context::getContext() -> language -> id; $this -> title = HTMLTemplateCustomPdf::l('Custom Title'); // footer informations $this -> shop = new Shop(Context::getContext() -> shop -> id); } public function getContent() { $this -> smarty -> assign(array( 'custom_model' => $this -> custom_model, )); return $this -> smarty -> fetch(_PS_MODULE_DIR_.'cm_customPdf/custom_template_content.tpl'); } public function getFilename() { return 'custom_pdf.pdf'; } - Ajout du template pdf (src/modules/cm_myPdf/custom_template_content.tpl). Et c'est la où je bloque, je n'arrive pas à récupérer les infos de mon produit.. <div style="width: 100%; height: 50%; vertical-align: middle;"> <table style="width: 100%; margin: 0 auto; text-align: left;"> <tbody> <tr> <td style="text-align: center; height: 20px;" colspan="2"></td> </tr> <tr> <td style="width: 5%; text-align: center;" colspan="2"></td> <td style="width: 90%; font-size: 14pt; font-weight: 100; font-family: Cormorant Garamond,serif; font-style: italic; text-align: center;" colspan="2"> {$product_name} </td> <td style="width: 5%; text-align: center;" colspan="2"></td> </tr> <tr> <td style="text-align: center; height: 20px;" colspan="2"></td> </tr> </tbody> </table> </div> Je suis nouveau sur Prestashop et malheureusement je ne m'y connais pas trop en php, Quelqu'un aurait une idée svp ? Merci d'avance, Edited March 19, 2019 by Asef. (see edit history) Link to comment Share on other sites More sharing options...
tuk66 Posted March 19, 2019 Share Posted March 19, 2019 (edited) You must assing all variables used in your template. $this -> smarty -> assign(array( 'custom_model' => $this -> custom_model, 'product_name' => 'My product', )); Edited March 19, 2019 by tuk66 (see edit history) Link to comment Share on other sites More sharing options...
asef. Posted March 19, 2019 Author Share Posted March 19, 2019 (edited) Thanks for your answer. Edited March 19, 2019 by Younes.asef (see edit history) Link to comment Share on other sites More sharing options...
asef. Posted March 19, 2019 Author Share Posted March 19, 2019 Hello tuk66, How to catch the product name of line to replace 'My product' on your code, please ? Link to comment Share on other sites More sharing options...
tuk66 Posted March 20, 2019 Share Posted March 20, 2019 See $order_details in HTMLTemplateInvoice::getContent(). Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now