julianbaros Posted July 3, 2018 Share Posted July 3, 2018 (edited) Bonjour, Je souhaiterais modifier mon bon de livraison pour facilité la vie des préparateurs de commandes. Je souhaiterais récupérer les images des produits afin de les ajouter dans mes bons de livraison. J'ai réussi à créer la colonne pour les photos, mais je n'arrive pas à récupérer la photo. Auriez-vous une idée svp ? Je suis sous prestashop 1.6.0.11 Je vous remercie d'avance. Julien Edited July 5, 2018 by julianbaros (see edit history) Link to comment Share on other sites More sharing options...
julianbaros Posted July 4, 2018 Author Share Posted July 4, 2018 Bonjour, J'ai avancé un peu sur le sujet. Voici ma fonction getContent() dans le fichier HTMLTemplateDeliverySlip.php public function getContent() { $delivery_address = new Address((int)$this->order->id_address_delivery); $formatted_delivery_address = AddressFormat::generateAddress($delivery_address, array(), '<br />', ' '); $formatted_invoice_address = ''; if ($this->order->id_address_delivery != $this->order->id_address_invoice) { $invoice_address = new Address((int)$this->order->id_address_invoice); $formatted_invoice_address = AddressFormat::generateAddress($invoice_address, array(), '<br />', ' '); } $carrier = new Carrier($this->order->id_carrier); $carrier->name = ($carrier->name == '0' ? Configuration::get('PS_SHOP_NAME') : $carrier->name); $this->smarty->assign(array( 'order' => $this->order, 'order_details' => $this->order_invoice->getProducts(), 'delivery_address' => $formatted_delivery_address, 'invoice_address' => $formatted_invoice_address, 'order_invoice' => $this->order_invoice, 'carrier' => $carrier )); return $this->smarty->fetch($this->getTemplate('delivery-slip')); } Voici le tableau qui gère l'affichage des produits dans le bon de livraison dans le fichier delivery-slip.tpl <tr style="line-height:6px;"> <td style="background-color: #4D4D4D; color: #FFF; text-align: center; font-weight: bold; width: 10%">{l s='IMAGE' pdf='true'}</td> <td style="text-align: left; background-color: #4D4D4D; color: #FFF; padding-left: 10px; font-weight: bold; width: 55%">{l s='ITEMS TO BE DELIVERED' pdf='true'}</td> <td style="background-color: #4D4D4D; color: #FFF; text-align: left; font-weight: bold; width: 20%">{l s='REFERENCE' pdf='true'}</td> <td style="background-color: #4D4D4D; color: #FFF; text-align: center; font-weight: bold; width: 15%">{l s='QTY' pdf='true'}</td> </tr> {foreach $order_details as $order_detail} {cycle values='#FFF,#DDD' assign=bgcolor} <tr style="line-height:6px;background-color:{$bgcolor};"> <td style="text-align: center; width: 10%">{html_image file='https://www.monsite.fr/191637-thickbox_default/productref-10000419.jpg' height="40px" width="40px"}</td> <td style="text-align: left; width: 55%;">{$order_detail.product_name}</td> <td style="text-align: left; width: 20%;"> {if empty($order_detail.product_reference)} --- {else} {$order_detail.product_reference} {/if} </td> <td style="text-align: center; width: 15%;">{$order_detail.product_quantity}</td> </tr> Avec ce code je peux afficher directement l'image que je souhaite mais je voudrais que ça soit automatique. Pouvez-vous m'aider s'il vous plait ? ? Link to comment Share on other sites More sharing options...
julianbaros Posted July 5, 2018 Author Share Posted July 5, 2018 Bonjour, J'ai enfin résolu mon problème. Dans ma version 1.6.0.11, l'affichage des images n'est pas natif, alors qu'il l'est dans la version 1.6.1.x. Je me suis donc inspiré du code contenu dans cette version que j'ai ajouté dans ma version 1.6.0.11. Les modifications à effectuer sont : Modifier le fichier AdminDeliverySlipController.php : repérer : $this->fields_options = array( 'general' => array( 'title' => $this->l('Delivery slip options'), 'fields' => array( 'PS_DELIVERY_PREFIX' => array( 'title' => $this->l('Delivery prefix'), 'desc' => $this->l('Prefix used for delivery slips.'), 'type' => 'textLang' ), 'PS_DELIVERY_NUMBER' => array( 'title' => $this->l('Delivery number'), 'desc' => $this->l('The next delivery slip will begin with this number and then increase with each additional slip.'), 'cast' => 'intval', 'type' => 'text' ), et ajouter à la suite : 'PS_PDF_IMG_DELIVERY' => array( 'title' => $this->l('Enable product image'), 'hint' => $this->l('Adds an image before product name on Delivery-slip'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool' ), Puis allez dans Commandes / Bons de livaison / puis dans la section Options des bons de livraison, mettre " Enable product image" sur "OUI". Modifier le fichier HTMLTemplateDeliverySlip.php : modifier la fonction : public function getContent() par : public function getContent() { $delivery_address = new Address((int)$this->order->id_address_delivery); $formatted_delivery_address = AddressFormat::generateAddress($delivery_address, array(), '<br />', ' '); $formatted_invoice_address = ''; if ($this->order->id_address_delivery != $this->order->id_address_invoice) { $invoice_address = new Address((int)$this->order->id_address_invoice); $formatted_invoice_address = AddressFormat::generateAddress($invoice_address, array(), '<br />', ' '); } $carrier = new Carrier($this->order->id_carrier); $carrier->name = ($carrier->name == '0' ? Configuration::get('PS_SHOP_NAME') : $carrier->name); $order_details = $this->order_invoice->getProducts(); if (Configuration::get('PS_PDF_IMG_DELIVERY')) { foreach ($order_details as &$order_detail) { if ($order_detail['image'] != null) { $name = 'product_mini_'.(int)$order_detail['product_id'].(isset($order_detail['product_attribute_id']) ? '_'.(int)$order_detail['product_attribute_id'] : '').'.jpg'; $path = _PS_PROD_IMG_DIR_.$order_detail['image']->getExistingImgPath().'.jpg'; $order_detail['image_tag'] = preg_replace( '/\.*'.preg_quote(__PS_BASE_URI__, '/').'/', _PS_ROOT_DIR_.DIRECTORY_SEPARATOR, ImageManager::thumbnail($path, $name, 45, 'jpg', false), 1 ); if (file_exists(_PS_TMP_IMG_DIR_.$name)) { $order_detail['image_size'] = getimagesize(_PS_TMP_IMG_DIR_.$name); } else { $order_detail['image_size'] = false; } } } } $this->smarty->assign(array( 'order' => $this->order, 'order_details' => $order_details, 'delivery_address' => $formatted_delivery_address, 'invoice_address' => $formatted_invoice_address, 'order_invoice' => $this->order_invoice, 'carrier' => $carrier, 'display_product_images' => Configuration::get('PS_PDF_IMG_DELIVERY') )); $tpls = array( 'style_tab' => $this->smarty->fetch($this->getTemplate('delivery-slip.style-tab')), 'addresses_tab' => $this->smarty->fetch($this->getTemplate('delivery-slip.addresses-tab')), 'summary_tab' => $this->smarty->fetch($this->getTemplate('delivery-slip.summary-tab')), 'product_tab' => $this->smarty->fetch($this->getTemplate('delivery-slip.product-tab')), 'payment_tab' => $this->smarty->fetch($this->getTemplate('delivery-slip.payment-tab')), ); $this->smarty->assign($tpls); return $this->smarty->fetch($this->getTemplate('delivery-slip')); } Ensuite, il faut aller dans monsite/pdf ajouter les 6 fichiers en pièce jointe. Le fichier delivery-slip.product-tab.tpl est le fichier qui gère l'affichage des produits. Je l'ai mis à ma convenance et j'ai une image spéciale quand le produit n'a pas de photo. delivery-slip.addresses-tab.tpl delivery-slip.payment-tab.tpl delivery-slip.product-tab.tpl delivery-slip.style-tab.tpl delivery-slip.summary-tab.tpl delivery-slip.tpl 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