Jump to content

[Résolu] - Afficher le détail du retour produit sur le PDF généré lors d'un retour et envoyé dans le colis pour le e-commerçant.


Recommended Posts

Bonjour,

J'aimerais simplement ajouter le détail du retour produit sur le PDF généré pour le client qui demande un retour produit et ce quelque soit l'endroit dans le PDF (header, footer, peu importe tant que le motif est présent cela fait gagner du temps au e-commerçant).

Le scénario : Le client se connecte au backoffice et se rend dans la section retour produits. A cet instant il saisit le motif du retour. Le motif est bien consultable côté e-commercant dans la rubrique SAV -> retours. Le client génère sont étiquette de retour mais le PDF ne comporte pas le motif du retour qu'il vient de saisir. 

Mes essais

Je pense qu'il faudrait réussir à ajouter dans le fichier "/www/classes/pdf/HTMLTemplateOrderReturn.php" la fonction getOrdersReturnDetail afin de récupérer le motif du retour et l'ajouter dans le fichier '/www/classes/pdf/HTMLTemplateOrderReturn.php' mais j'avoue ne pas réussir à trouver comment faire.

Mes questions :

- Avez-vous déjà développé cela et si oui, serait-il possible de me dire la fonction à ajouter ?
- Cela vous paraît t-il trop complexe à développer ?

 

 

 public static function getOrdersReturnDetail($id_order_return)
    {
        return Db::getInstance()->executeS('
        SELECT *
        FROM `' . _DB_PREFIX_ . 'order_return_detail`
        WHERE `id_order_return` = ' . (int) $id_order_return);
    }

 

-

Les fichiers concernés

/www/classes/order/OrderReturn.php

<?php
/**
 * Copyright since 2007 PrestaShop SA and Contributors
 * PrestaShop is an International Registered Trademark & Property of PrestaShop SA
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.md.
 * It is also available through the world-wide-web at this URL:
 * https://opensource.org/licenses/OSL-3.0
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to [email protected] so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
 * versions in the future. If you wish to customize PrestaShop for your
 * needs please refer to https://devdocs.prestashop.com/ for more information.
 *
 * @author    PrestaShop SA and Contributors <[email protected]>
 * @copyright Since 2007 PrestaShop SA and Contributors
 * @license   https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
 */
class OrderReturnCore extends ObjectModel
{
    /** @var int */
    public $id;

    /** @var int */
    public $id_customer;

    /** @var int */
    public $id_order;

    /** @var int */
    public $state;

    /** @var string message content */
    public $question;

    /** @var string Object creation date */
    public $date_add;

    /** @var string Object last modification date */
    public $date_upd;

    /**
     * @see ObjectModel::$definition
     */
    public static $definition = [
        'table' => 'order_return',
        'primary' => 'id_order_return',
        'fields' => [
            'id_customer' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true],
            'id_order' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true],
            'question' => ['type' => self::TYPE_HTML, 'validate' => 'isCleanHtml'],
            'state' => ['type' => self::TYPE_STRING],
            'date_add' => ['type' => self::TYPE_DATE, 'validate' => 'isDate'],
            'date_upd' => ['type' => self::TYPE_DATE, 'validate' => 'isDate'],
        ],
    ];

    public function addReturnDetail($order_detail_list, $product_qty_list, $customization_ids, $customization_qty_input)
    {
        /* Classic product return */
        if ($order_detail_list) {
            foreach ($order_detail_list as $key => $order_detail) {
                if ($qty = (int) $product_qty_list[$key]) {
                    Db::getInstance()->insert('order_return_detail', ['id_order_return' => (int) $this->id, 'id_order_detail' => (int) $order_detail, 'product_quantity' => $qty, 'id_customization' => 0]);
                }
            }
        }
        /* Customized product return */
        if ($customization_ids) {
            foreach ($customization_ids as $order_detail_id => $customizations) {
                foreach ($customizations as $customization_id) {
                    if ($quantity = (int) $customization_qty_input[(int) $customization_id]) {
                        Db::getInstance()->insert('order_return_detail', ['id_order_return' => (int) $this->id, 'id_order_detail' => (int) $order_detail_id, 'product_quantity' => $quantity, 'id_customization' => (int) $customization_id]);
                    }
                }
            }
        }
    }

    public function checkEnoughProduct($order_detail_list, $product_qty_list, $customization_ids, $customization_qty_input)
    {
        $order = new Order((int) $this->id_order);
        if (!Validate::isLoadedObject($order)) {
            die(Tools::displayError());
        }
        $products = $order->getProducts();
        /* Products already returned */
        $order_return = OrderReturn::getOrdersReturn($order->id_customer, $order->id, true);
        foreach ($order_return as $or) {
            $order_return_products = OrderReturn::getOrdersReturnProducts($or['id_order_return'], $order);
            foreach ($order_return_products as $key => $orp) {
                $products[$key]['product_quantity'] -= (int) $orp['product_quantity'];
            }
        }
        /* Quantity check */
        if ($order_detail_list) {
            foreach (array_keys($order_detail_list) as $key) {
                if (!isset($product_qty_list[$key])) {
                    return false;
                }
                if ($qty = (int) $product_qty_list[$key]) {
                    if ($products[$key]['product_quantity'] - $qty < 0) {
                        return false;
                    }
                }
            }
        }
        /* Customization quantity check */
        if ($customization_ids) {
            $ordered_customizations = Customization::getOrderedCustomizations((int) $order->id_cart);
            foreach ($customization_ids as $customizations) {
                foreach ($customizations as $customization_id) {
                    $customization_id = (int) $customization_id;
                    if (!isset($ordered_customizations[$customization_id])) {
                        return false;
                    }
                    $quantity = (isset($customization_qty_input[$customization_id]) ? (int) $customization_qty_input[$customization_id] : 0);
                    if ((int) $ordered_customizations[$customization_id]['quantity'] - $quantity < 0) {
                        return false;
                    }
                }
            }
        }

        return true;
    }

    public function countProduct()
    {
        if (!$data = Db::getInstance()->getRow('
		SELECT COUNT(`id_order_return`) AS total
		FROM `' . _DB_PREFIX_ . 'order_return_detail`
		WHERE `id_order_return` = ' . (int) $this->id)) {
            return false;
        }

        return (int) ($data['total']);
    }

    public static function getOrdersReturn($customer_id, $order_id = false, $no_denied = false, Context $context = null)
    {
        if (!$context) {
            $context = Context::getContext();
        }
        $data = Db::getInstance()->executeS('
		SELECT *
		FROM `' . _DB_PREFIX_ . 'order_return`
		WHERE `id_customer` = ' . (int) $customer_id .
        ($order_id ? ' AND `id_order` = ' . (int) $order_id : '') .
        ($no_denied ? ' AND `state` != 4' : '') . '
		ORDER BY `date_add` DESC');
        foreach ($data as $k => $or) {
            $state = new OrderReturnState($or['state']);
            $data[$k]['state_name'] = $state->name[$context->language->id];
            $data[$k]['type'] = 'Return';
            $data[$k]['tracking_number'] = $or['id_order_return'];
            $data[$k]['can_edit'] = false;
            $data[$k]['reference'] = Order::getUniqReferenceOf($or['id_order']);
        }

        return $data;
    }

    public static function getOrdersReturnDetail($id_order_return)
    {
        return Db::getInstance()->executeS('
		SELECT *
		FROM `' . _DB_PREFIX_ . 'order_return_detail`
		WHERE `id_order_return` = ' . (int) $id_order_return);
    }

    /**
     * @param int $order_return_id
     * @param Order $order
     *
     * @return array
     */
    public static function getOrdersReturnProducts($order_return_id, $order)
    {
        $products_ret = OrderReturn::getOrdersReturnDetail($order_return_id);
        $products = $order->getProducts();
        $tmp = [];
        foreach ($products_ret as $return_detail) {
            $tmp[$return_detail['id_order_detail']]['quantity'] = isset($tmp[$return_detail['id_order_detail']]['quantity']) ? $tmp[$return_detail['id_order_detail']]['quantity'] + (int) $return_detail['product_quantity'] : (int) $return_detail['product_quantity'];
            $tmp[$return_detail['id_order_detail']]['customizations'] = (int) $return_detail['id_customization'];
        }
        $res_tab = [];
        foreach ($products as $key => $product) {
            if (isset($tmp[$product['id_order_detail']])) {
                $res_tab[$key] = $product;
                $res_tab[$key]['product_quantity'] = $tmp[$product['id_order_detail']]['quantity'];
                $res_tab[$key]['customizations'] = $tmp[$product['id_order_detail']]['customizations'];
            }
        }

        return $res_tab;
    }

    public static function getReturnedCustomizedProducts($id_order)
    {
        $returns = Customization::getReturnedCustomizations($id_order);
        $order = new Order((int) $id_order);
        if (!Validate::isLoadedObject($order)) {
            die(Tools::displayError());
        }
        $products = $order->getProducts();

        foreach ($returns as &$return) {
            $return['product_id'] = (int) $products[(int) $return['id_order_detail']]['product_id'];
            $return['product_attribute_id'] = (int) $products[(int) $return['id_order_detail']]['product_attribute_id'];
            $return['name'] = $products[(int) $return['id_order_detail']]['product_name'];
            $return['reference'] = $products[(int) $return['id_order_detail']]['product_reference'];
            $return['id_address_delivery'] = $products[(int) $return['id_order_detail']]['id_address_delivery'];
        }

        return $returns;
    }

    public static function deleteOrderReturnDetail($id_order_return, $id_order_detail, $id_customization = 0)
    {
        return Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'order_return_detail` WHERE `id_order_detail` = ' . (int) $id_order_detail . ' AND `id_order_return` = ' . (int) $id_order_return . ' AND `id_customization` = ' . (int) $id_customization);
    }

    /**
     * Get return details for one product line.
     *
     * @param $id_order_detail
     */
    public static function getProductReturnDetail($id_order_detail)
    {
        return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
			SELECT product_quantity, date_add, orsl.name as state
			FROM `' . _DB_PREFIX_ . 'order_return_detail` ord
			LEFT JOIN `' . _DB_PREFIX_ . 'order_return` o
			ON o.id_order_return = ord.id_order_return
			LEFT JOIN `' . _DB_PREFIX_ . 'order_return_state_lang` orsl
			ON orsl.id_order_return_state = o.state AND orsl.id_lang = ' . (int) Context::getContext()->language->id . '
			WHERE ord.`id_order_detail` = ' . (int) $id_order_detail);
    }

    /**
     * Add returned quantity to products list.
     *
     * @param array $products
     * @param int $id_order
     */
    public static function addReturnedQuantity(&$products, $id_order)
    {
        $details = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
            'SELECT od.id_order_detail, GREATEST(od.product_quantity_return, IFNULL(SUM(ord.product_quantity),0)) as qty_returned
			FROM ' . _DB_PREFIX_ . 'order_detail od
			LEFT JOIN ' . _DB_PREFIX_ . 'order_return_detail ord
			ON ord.id_order_detail = od.id_order_detail
			WHERE od.id_order = ' . (int) $id_order . '
			GROUP BY od.id_order_detail'
        );
        if (!$details) {
            return;
        }

        $detail_list = [];
        foreach ($details as $detail) {
            $detail_list[$detail['id_order_detail']] = $detail;
        }

        foreach ($products as &$product) {
            if (isset($detail_list[$product['id_order_detail']]['qty_returned'])) {
                $product['qty_returned'] = $detail_list[$product['id_order_detail']]['qty_returned'];
            }
        }
    }
}

 

/www/classes/pdf/HTMLTemplateOrderReturn.php

<?php
/**
 * Copyright since 2007 PrestaShop SA and Contributors
 * PrestaShop is an International Registered Trademark & Property of PrestaShop SA
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.md.
 * It is also available through the world-wide-web at this URL:
 * https://opensource.org/licenses/OSL-3.0
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to [email protected] so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
 * versions in the future. If you wish to customize PrestaShop for your
 * needs please refer to https://devdocs.prestashop.com/ for more information.
 *
 * @author    PrestaShop SA and Contributors <[email protected]>
 * @copyright Since 2007 PrestaShop SA and Contributors
 * @license   https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
 */

/**
 * @since 1.5
 */
class HTMLTemplateOrderReturnCore extends HTMLTemplate
{
    /**
     * @var OrderReturn
     */
    public $order_return;

    /**
     * @var Order
     */
    public $order;

    /**
     * @param OrderReturn $order_return
     * @param Smarty $smarty
     *
     * @throws PrestaShopException
     */
    public function __construct(OrderReturn $order_return, Smarty $smarty)
    {
        $this->order_return = $order_return;
        $this->smarty = $smarty;
        $this->order = new Order($order_return->id_order);

        // header informations
        $this->date = Tools::displayDate($this->order->invoice_date);
        $prefix = Configuration::get('PS_RETURN_PREFIX', Context::getContext()->language->id);
        $this->title = sprintf(HTMLTemplateOrderReturn::l('%1$s%2$06d'), $prefix, $this->order_return->id);

        $this->shop = new Shop((int) $this->order->id_shop);
    }

    /**
     * Returns the template's HTML content.
     *
     * @return string HTML content
     */
    public function getContent()
    {
        $delivery_address = new Address((int) $this->order->id_address_delivery);
        $formatted_delivery_address = AddressFormat::generateAddress($delivery_address, [], '<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, [], '<br />', ' ');
        }

        $this->smarty->assign([
            'order_return' => $this->order_return,
            'return_nb_days' => (int) Configuration::get('PS_ORDER_RETURN_NB_DAYS'),
            'products' => OrderReturn::getOrdersReturnProducts((int) $this->order_return->id, $this->order),
            'delivery_address' => $formatted_delivery_address,
            'invoice_address' => $formatted_invoice_address,
            'shop_address' => AddressFormat::generateAddress($this->shop->getAddress(), [], '<br />', ' '),
        ]);

        $tpls = [
            'style_tab' => $this->smarty->fetch($this->getTemplate('invoice.style-tab')),
            'addresses_tab' => $this->smarty->fetch($this->getTemplate('order-return.addresses-tab')),
            'summary_tab' => $this->smarty->fetch($this->getTemplate('order-return.summary-tab')),
            'product_tab' => $this->smarty->fetch($this->getTemplate('order-return.product-tab')),
            'conditions_tab' => $this->smarty->fetch($this->getTemplate('order-return.conditions-tab')),
        ];
        $this->smarty->assign($tpls);

        return $this->smarty->fetch($this->getTemplate('order-return'));
    }

    /**
     * Returns the template filename.
     *
     * @return string filename
     */
    public function getFilename()
    {
        return Configuration::get('PS_RETURN_PREFIX', Context::getContext()->language->id, null, $this->order->id_shop) . sprintf('%06d', $this->order_return->id) . '.pdf';
    }

    /**
     * Returns the template filename when using bulk rendering.
     *
     * @return string filename
     */
    public function getBulkFilename()
    {
        return 'invoices.pdf';
    }

    /**
     * Returns the template's HTML header.
     *
     * @return string HTML header
     */
    public function getHeader()
    {
        $this->assignCommonHeaderData();
        $this->smarty->assign(['header' => Context::getContext()->getTranslator()->trans('Order return', [], 'Shop.Pdf')]);

        return $this->smarty->fetch($this->getTemplate('header'));
    }
}

 

Merci par avance de vos éclairages.

Site:

Prestashop 1.7.8.9
PHP : 7.4

 

 

Edited by prestaconfig
Résolu (see edit history)
Link to comment
Share on other sites

C'est pas super propre mais ca devrait fonctionner : 

Dans HTMLTemplateOrderReturn.php rajouter dans la fonction getContent

$getOrderReturns = \OrderReturn::getOrdersReturn($this->order->id_customer, $this->order->id);
$orderReturnDetails = []
foreach ($getOrderReturns as $orderReturn) {
	$orderReturnDetails[] = \OrderReturn:getOrdersReturnDetail($orderReturn['id_order_return']);
}

Tu rajoutes dans le smarty assign

 $this->smarty->assign([
	'orderReturnDetails' = $orderReturnDetails,

]);

Puis dans le template tu as juste a faire

{$foreach from=$orderReturnDetails item=orderReturnDetail}
	ce que tu veux afficher par exemple {$orderReturnDetail->product_quantity}
{$foreach}

J'espère avoir bien compris ta demande

Edited by wepresta (see edit history)
Link to comment
Share on other sites

Bonjour @wepresta

Merci encore du retour ! 

J'ai testé l'implémentation proposé mais malgré mes essais je ne parvient pas à faire apparaitre le motif du retour sur le PDF. Je devrais voir retourner "je test les retours" dans ma variable sur le PDF que je génère vie la fonction Imprimer (en bleu).

image.thumb.png.fb39466eaa050af1620ea4aca5117840.png

 

Voici le PDF une fois généré (j'ai fait un var dump sur la variable pour voir ce qu'elle contenait) : 

image.thumb.png.8ca8c2966b12ed2ddd26c8eef12e0d69.png

 

J'ai regardé le contenu de la variable $orderReturnDetails mais elle ne contient pas le motif du retour. 

 

------------------

Voici le fichier template (j'ai utilisé le fichier order-return.conditions-tab.tpl car je souhaite afficher le motif du retour au dessus des conditions)   :

<table id="summary-tab" width="100%">
	<tr>
		<th class="header small" valign="middle">Motif du retour</th>
	</tr>
	<tr>
		<td class="center small white">{foreach from=$orderReturnDetails item=orderReturnDetail}
										{$orderReturnDetails|var_dump}	{$orderReturnDetail->product_quantity}
												{/foreach}</td>
	</tr>
</table>

 

Voici le fichier HTMLTemplateOrderReturn.php modifié en conséquence : 

<?php
/**
 * Copyright since 2007 PrestaShop SA and Contributors
 * PrestaShop is an International Registered Trademark & Property of PrestaShop SA
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.md.
 * It is also available through the world-wide-web at this URL:
 * https://opensource.org/licenses/OSL-3.0
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to [email protected] so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
 * versions in the future. If you wish to customize PrestaShop for your
 * needs please refer to https://devdocs.prestashop.com/ for more information.
 *
 * @author    PrestaShop SA and Contributors <[email protected]>
 * @copyright Since 2007 PrestaShop SA and Contributors
 * @license   https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
 */

/**
 * @since 1.5
 */
class HTMLTemplateOrderReturnCore extends HTMLTemplate
{
    /**
     * @var OrderReturn
     */
    public $order_return;

    /**
     * @var Order
     */
    public $order;

    /**
     * @param OrderReturn $order_return
     * @param Smarty $smarty
     *
     * @throws PrestaShopException
     */
    public function __construct(OrderReturn $order_return, Smarty $smarty)
    {
        $this->order_return = $order_return;
        $this->smarty = $smarty;
        $this->order = new Order($order_return->id_order);

        // header informations
        $this->date = Tools::displayDate($this->order->invoice_date);
        $prefix = Configuration::get('PS_RETURN_PREFIX', Context::getContext()->language->id);
        $this->title = sprintf(HTMLTemplateOrderReturn::l('%1$s%2$06d'), $prefix, $this->order_return->id);

        $this->shop = new Shop((int) $this->order->id_shop);
    }

    /**
     * Returns the template's HTML content.
     *
     * @return string HTML content
     */
    public function getContent()
    {
        $delivery_address = new Address((int) $this->order->id_address_delivery);
        $formatted_delivery_address = AddressFormat::generateAddress($delivery_address, [], '<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, [], '<br />', ' ');
        }
		$getOrderReturns = \OrderReturn::getOrdersReturn($this->order->id_customer, $this->order->id);
		$orderReturnDetails = [];
		foreach ($getOrderReturns as $orderReturn) {
		$orderReturnDetails[] = \OrderReturn::getOrdersReturnDetail($orderReturn['id_order_return']);
		}

        $this->smarty->assign([
            'order_return' => $this->order_return,
            'return_nb_days' => (int) Configuration::get('PS_ORDER_RETURN_NB_DAYS'),
            'products' => OrderReturn::getOrdersReturnProducts((int) $this->order_return->id, $this->order),
            'delivery_address' => $formatted_delivery_address,
            'invoice_address' => $formatted_invoice_address,
            'shop_address' => AddressFormat::generateAddress($this->shop->getAddress(), [], '<br />', ' '),
			'orderReturnDetails' => $orderReturnDetails,
        ]);

        $tpls = [
            'style_tab' => $this->smarty->fetch($this->getTemplate('invoice.style-tab')),
            'addresses_tab' => $this->smarty->fetch($this->getTemplate('order-return.addresses-tab')),
            'summary_tab' => $this->smarty->fetch($this->getTemplate('order-return.summary-tab')),
            'product_tab' => $this->smarty->fetch($this->getTemplate('order-return.product-tab')),
            'conditions_tab' => $this->smarty->fetch($this->getTemplate('order-return.conditions-tab')),
        ];
        $this->smarty->assign($tpls);

        return $this->smarty->fetch($this->getTemplate('order-return'));
    }

    /**
     * Returns the template filename.
     *
     * @return string filename
     */
    public function getFilename()
    {
        return Configuration::get('PS_RETURN_PREFIX', Context::getContext()->language->id, null, $this->order->id_shop) . sprintf('%06d', $this->order_return->id) . '.pdf';
    }

    /**
     * Returns the template filename when using bulk rendering.
     *
     * @return string filename
     */
    public function getBulkFilename()
    {
        return 'invoices.pdf';
    }

    /**
     * Returns the template's HTML header.
     *
     * @return string HTML header
     */
    public function getHeader()
    {
        $this->assignCommonHeaderData();
        $this->smarty->assign(['header' => Context::getContext()->getTranslator()->trans('Order return', [], 'Shop.Pdf')]);

        return $this->smarty->fetch($this->getTemplate('header'));
    }
}

 

 

 

motif-retour.png

Link to comment
Share on other sites

Merci @wepresta,pour toutes les explications et la logique à suivre.

Voici donc les fichiers finaux modifiés pour obtenir le numéro de commande ainsi que le motif du retour produit sur le PDF.

Les limites : Je ne me suis pas chargé de la partie traduction des libellés dans les entêtes du tableau pour les en-têtes "Raison du retour" et "ID commande".

Contenu fichier /classes/pdf/HTMLTemplateOrderReturn.php

<?php
/**
 * Copyright since 2007 PrestaShop SA and Contributors
 * PrestaShop is an International Registered Trademark & Property of PrestaShop SA
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.md.
 * It is also available through the world-wide-web at this URL:
 * https://opensource.org/licenses/OSL-3.0
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to [email protected] so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
 * versions in the future. If you wish to customize PrestaShop for your
 * needs please refer to https://devdocs.prestashop.com/ for more information.
 *
 * @author    PrestaShop SA and Contributors <[email protected]>
 * @copyright Since 2007 PrestaShop SA and Contributors
 * @license   https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
 */

/**
 * @since 1.5
 */
class HTMLTemplateOrderReturnCore extends HTMLTemplate
{
    /**
     * @var OrderReturn
     */
    public $order_return;

    /**
     * @var Order
     */
    public $order;

    /**
     * @param OrderReturn $order_return
     * @param Smarty $smarty
     *
     * @throws PrestaShopException
     */
    public function __construct(OrderReturn $order_return, Smarty $smarty)
    {
        $this->order_return = $order_return;
        $this->smarty = $smarty;
        $this->order = new Order($order_return->id_order);

        // header informations
        $this->date = Tools::displayDate($this->order->invoice_date);
        $prefix = Configuration::get('PS_RETURN_PREFIX', Context::getContext()->language->id);
        $this->title = sprintf(HTMLTemplateOrderReturn::l('%1$s%2$06d'), $prefix, $this->order_return->id);

        $this->shop = new Shop((int) $this->order->id_shop);
    }

    /**
     * Returns the template's HTML content.
     *
     * @return string HTML content
     */
    public function getContent()
    {
        $delivery_address = new Address((int) $this->order->id_address_delivery);
        $formatted_delivery_address = AddressFormat::generateAddress($delivery_address, [], '<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, [], '<br />', ' ');
        }
		$getOrderReturns = \OrderReturn::getOrdersReturn($this->order->id_customer, $this->order->id);
		$orderReturn = [];
		foreach ($getOrderReturns as $orderReturn) {
		$orderReturns[] = new OrderReturn($orderReturn['id_order_return']);
		}

        $this->smarty->assign([
            'order_return' => $this->order_return,
            'return_nb_days' => (int) Configuration::get('PS_ORDER_RETURN_NB_DAYS'),
            'products' => OrderReturn::getOrdersReturnProducts((int) $this->order_return->id, $this->order),
            'delivery_address' => $formatted_delivery_address,
            'invoice_address' => $formatted_invoice_address,
            'shop_address' => AddressFormat::generateAddress($this->shop->getAddress(), [], '<br />', ' '),
			'orderReturns' => $orderReturns,
        ]);

        $tpls = [
            'style_tab' => $this->smarty->fetch($this->getTemplate('invoice.style-tab')),
            'addresses_tab' => $this->smarty->fetch($this->getTemplate('order-return.addresses-tab')),
            'summary_tab' => $this->smarty->fetch($this->getTemplate('order-return.summary-tab')),
            'product_tab' => $this->smarty->fetch($this->getTemplate('order-return.product-tab')),
            'conditions_tab' => $this->smarty->fetch($this->getTemplate('order-return.conditions-tab')),

        ];
        $this->smarty->assign($tpls);

        return $this->smarty->fetch($this->getTemplate('order-return'));
    }

    /**
     * Returns the template filename.
     *
     * @return string filename
     */
    public function getFilename()
    {
        return Configuration::get('PS_RETURN_PREFIX', Context::getContext()->language->id, null, $this->order->id_shop) . sprintf('%06d', $this->order_return->id) . '.pdf';
    }

    /**
     * Returns the template filename when using bulk rendering.
     *
     * @return string filename
     */
    public function getBulkFilename()
    {
        return 'invoices.pdf';
    }

    /**
     * Returns the template's HTML header.
     *
     * @return string HTML header
     */
    public function getHeader()
    {
        $this->assignCommonHeaderData();
        $this->smarty->assign(['header' => Context::getContext()->getTranslator()->trans('Order return', [], 'Shop.Pdf')]);

        return $this->smarty->fetch($this->getTemplate('header'));
    }
}

 

Contenu du fichier: /pdf/order-return.summary-tab.tpl

{**
 * Copyright since 2007 PrestaShop SA and Contributors
 * PrestaShop is an International Registered Trademark & Property of PrestaShop SA
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.md.
 * It is also available through the world-wide-web at this URL:
 * https://opensource.org/licenses/OSL-3.0
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to [email protected] so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
 * versions in the future. If you wish to customize PrestaShop for your
 * needs please refer to https://devdocs.prestashop.com/ for more information.
 *
 * @author    PrestaShop SA and Contributors <contact@prestashop.com>
 * @copyright Since 2007 PrestaShop SA and Contributors
 * @license   https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
 *}
{l s='We have logged your return request.' d='Shop.Pdf' pdf='true'}<br />
{l s='Your package must be returned to us within' d='Shop.Pdf' pdf='true'} {$return_nb_days} {l s='days of receiving your order.' d='Shop.Pdf' pdf='true'}<br /><br />

<table id="summary-tab" width="100%" cellpadding="4" cellspacing="0">
	<thead>
		<tr>
			<th class="header small" valign="middle">{l s='ID Commande' d='Shop.Pdf' pdf='true'}</th>
			<th class="header small" valign="middle">{l s='Return Number' d='Shop.Pdf' pdf='true'}</th>
			<th class="header small" valign="middle">{l s='Date' d='Shop.Pdf' pdf='true'}</th>
			<th class="header small" valign="middle">{l s='Raison du retour' d='Shop.Pdf' pdf='true'}</th>
		</tr>
	</thead>
	
	<tbody>
		<tr>
			<td class="center small white">{foreach from=$orderReturns item=orderReturn}
										{$orderReturn->id_order}
										{/foreach}</td>
			<td class="center small white">{'%06d'|sprintf:$order_return->id}</td>
			<td class="center small white">{dateFormat date=$order_return->date_add full=0}</td>
			<td class="center small white">{foreach from=$orderReturns item=orderReturn}
										{$orderReturn->question}
												{/foreach}</td>
		</tr>
	</tbody>
	
</table>

Résultat d'un PDF imprimé par le client et imprimable par le e-commerçant d'un retour au format PDF avant la modification des fichiers :

2023-07-18_14h21_48.png.9cb07878eda56fee6901acfbd2c48100.png

Résultat d'un PDF imprimé par le client et imprimable par le e-commerçant d'un retour au format PDF après la modification des fichiers :

 

2023-07-18_14h22_12.png.1a76777f1ee0e6b3452198fd41a09cda.png

 

Rappel : L'objectif étant que lorsqu'un retour est emballé par le client et qu'il arrive ensuite à l'entrepôt, la commande retour soit traitée plus rapidement car il est rattaché à une commande.

Merci.

Edited by prestaconfig
Forgot to put content on order-return.summary-tab.pl (see edit history)
Link to comment
Share on other sites

  • prestaconfig changed the title to [Résolu] - Afficher le détail du retour produit sur le PDF généré lors d'un retour et envoyé dans le colis pour le e-commerçant.
  • 4 months later...
On 12/3/2023 at 12:40 PM, StevenFree said:

Bonjour,

 

merci pour le tuto

 

Mais si vous pouviez affichier le contenu du fichier: /pdf/order-return.summary-tab.tpl

il n'y a rien de copié

 

en vous remerciant par avance

Steeve

Bonjour Steeve,

En effet, j'avais mal inséré le code du fichier order-return.summary-tab.tpl. Je viens de le rajouter.

Cordialement,

Link to comment
Share on other sites

Merci encore Prestaconfig 😘

En reprenant exactement les memes fichiers que PRestaconfig, cela ne marchait pas chez moi ( Prestashop version 8.0.4 ), champs toujours vide. ( Champs ID et Motif )

Je pensais que pour avoir le MOTIF du retour sur le pdf , je devais egalement afficher l'ID ORDER car j'ai constatais qu'il y avait un FOR EACH dans le fichier *.tpl

JE pensais que les 2 allez de pairs.

mais non.

J'ai épuré son fichier php

Donc, en résumé

 

FICHIER 1/2: /pdf/order-return.summary-tab.tpl

 

resultat final :

image.png.0706cc5815ee433294485df0c5adbe25.png

J'ai fait ainsi pour le fichier


 

<table id="summary-tab" width="100%" cellpadding="4" cellspacing="0">
    <thead>
        <tr>
            <th class="header small" valign="middle">{l s='Numero Retorno' d='Shop.Pdf' pdf='true'}</th>
            <th class="header small" valign="middle">{l s='Fecha' d='Shop.Pdf' pdf='true'}</th>
            <th class="header small" valign="middle">{l s='n° ID Pedido' d='Shop.Pdf' pdf='true'}</th>
            <th class="header small" valign="middle">{l s='n° Pedido' pdf='true'}</th>
            <th class="header small" valign="middle">{l s='Razon del retorno' d='Shop.Pdf' pdf='true'}</th>
   </tr>
   </thead>
   <tbody>
   <tr>                               
   <td class="center small white">{'#RE%06d'|sprintf:$order_return->id}</td>   /** mon numero de RETOUR tel que presenté depuis le compte du client  */
   <td class="center small white">{dateFormat date=$order_return->date_add full=0}</td>      /** Date de commande */
   <td class="center small white">{$order_return->id_order}</td>                            /** ID de commande */
   <td class="center small white">{$order->getUniqReference()}</td>                        /** N° de commande */
   <td class="center small white">{$order_return->question}</td>                          /** ici c'est le motif du retour */
   </tr>
   </tbody>
   </table>

 

FICHIER 2/2Concernant le fichier /classes/pdf/HTMLTemplateOrderReturn.php

J'ai supprimé cette partie que proposait Prestaconfig

$getOrderReturns = \OrderReturn::getOrdersReturn($this->order->id_customer, $this->order->id); 
$orderReturn = []; 
foreach ($getOrderReturns as $orderReturn) { 
$orderReturns[] = new OrderReturn($orderReturn['id_order_return']); }

 

J'ai  remplacé cette ligne chez lui

'orderReturns' => $orderReturns,

par  cela :

 'order' => $this->order,

 

ce qui donne avec une vue de hauteur :

   public function getContent()
    {
        $delivery_address = new Address((int) $this->order->id_address_delivery);
        $formatted_delivery_address = AddressFormat::generateAddress($delivery_address, [], '<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, [], '<br />', ' ');
        }
        


        $this->smarty->assign([
            'order' => $this->order,                                                                           /** mon ajout perso */
            'order_return' => $this->order_return,
            'return_nb_days' => (int) Configuration::get('PS_ORDER_RETURN_NB_DAYS'),
            'products' => OrderReturn::getOrdersReturnProducts((int) $this->order_return->id, $this->order),
            'delivery_address' => $formatted_delivery_address,
            'invoice_address' => $formatted_invoice_address,
            'shop_address' => AddressFormat::generateAddress($this->shop->getAddress(), [], '<br />', ' '),
           
                                                              
                                                                         
        ]);

        $tpls = [
            'style_tab' => $this->smarty->fetch($this->getTemplate('invoice.style-tab')),
            'addresses_tab' => $this->smarty->fetch($this->getTemplate('order-return.addresses-tab')),
            'summary_tab' => $this->smarty->fetch($this->getTemplate('order-return.summary-tab')),
            'product_tab' => $this->smarty->fetch($this->getTemplate('order-return.product-tab')),
            'conditions_tab' => $this->smarty->fetch($this->getTemplate('order-return.conditions-tab')),
        ];
        $this->smarty->assign($tpls);

        return $this->smarty->fetch($this->getTemplate('order-return'));
    }

Rien d'autre !!

une ligne, pas plus

 

 

N'oubliez pas de positionner votre fichier dans OVERRIDE/classes/pdf

image.png.d975ce94897a89ae1b2c441c63a6c156.png

 

Merci Prestaconfig

C'etait tres gentil de ta part

Je suis un homme comblé

 

Edited by StevenFree (see edit history)
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...