https://medium.com/@lmeyer./get-an-error-free-e-commerce-web-site-using-sentry-b6061264efc8...
Lire la suite
Add PDF credit in the mail for partial refund - Prestashop 1.7
Problème
Kaëlig Bérel 21 h ·
Bonsoir, Une fois que l'on génère un remboursement partiel, nous avons un email nous indiquant que le remboursement a bien été effectué. Comment je peux faire pour ajouter l'avoir PDF dans cet email ? Je ne trouve rien sur le net et dans les configurations Prestashop. Merci pour votre aide.
Belle soirée. Kaëlig
Aide apportée sur facebook
Solution
Testé sur Prestashop 1.7.8.7
Création du module BabaRefundPdf
Si vous n'avez pas les compétences techniques ou que vous voulez gagner du temps je vous propose le module en téléchargement gratuit:
Télécharger ce module GRATUITEMENT
Ce module Prestashop utilise le hook actionProductCancel
<?php
use PrestaShop\PrestaShop\Core\Domain\Order\CancellationActionType;
if (!defined('_PS_VERSION_')) {
exit;
}
class BabaRefundPdf extends Module
{
protected $config_form = false;
public function __construct()
{
$this->name = 'babaRefundPdf';
$this->tab = 'administration';
$this->version = '1.0.0';
$this->author = 'presta.cafe';
$this->need_instance = 0;
/**
* Set $this->bootstrap to true if your module is compliant with bootstrap (PrestaShop 1.6)
*/
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('babaRefundPdf');
$this->description = $this->l('Allows you to add the credit note in pdf to the email');
$this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_);
}
public function install()
{
return parent::install() &&
$this->registerHook('actionProductCancel');
}
public function uninstall()
{
return parent::uninstall();
}
public function getContent()
{
$this->context->smarty->assign('module_dir', $this->_path);
$output = $this->context->smarty->fetch($this->local_path.'views/templates/admin/configure.tpl');
return $output;
}
public function hookActionProductCancel($params)
{
if ($params['action'] === CancellationActionType::PARTIAL_REFUND) {
$customer = new Customer((int)$params['order']->id_customer);
$order = new Order((int)$params['order']->id);
$from = Configuration::get('PS_SHOP_EMAIL');
$orderDetailId = $params["id_order_detail"];
$quantity = $params["cancel_quantity"];
$amount = $params["cancel_amount"];
$cancelledProducts = [[
'id_order_detail' => $orderDetailId,
'quantity' => $quantity,
'amount' => $amount,
'unit_price' => $amount/$quantity,
'unit_price_tax_incl' => 0,
'unit_price_tax_excl' => $amount/$quantity,
'total_price_tax_incl' => 0,
'total_price_tax_excl' => $amount,
]];
$orderSlipTemp = OrderSlip::Create($order,$cancelledProducts,false,$amount,false,false);
$getorderSlip = OrderSlip::getOrdersSlip((int)($order->id_customer), (int)($order->id), true);
//on recupere et on instancie le dernier orderslip
$orderSlip = new OrderSlip($getorderSlip[0]["id_order_slip"]);
$pdf = new PDF($orderSlip, PDF::TEMPLATE_ORDER_SLIP, $this->context->smarty);
$file_attachement['content'] = $pdf->render(false);
$file_attachement['name'] = sprintf('d', $orderSlip->id).'.pdf';
$file_attachement['mime'] = 'application/pdf';
$var_list = [
'{firstname}' => $customer->firstname,
'{lastname}' => $customer->lastname,
'{order_name}' => $order->reference,
'{attached_file}' => '-',
];
Mail::Send(
$this->context->language->id,
'credit_slip',
$this->trans('New credit slip regarding your order', [], 'Emails.Subject'),
$var_list,
$customer->email,
$customer->firstname .' '. $customer->lastname,
null,
null,
$file_attachement,
null,
_PS_MAIL_DIR_,
false,
null,
null,
$from
);
$message_txt="Yeah. PARTIAL_REFUND";
$type="success"; // can be error..
$router = $this->get('router');
$this->get('session')->getFlashBag()->add($type, $message_txt);
$urlResend = $router->generate('admin_orders_view', ['orderId'=> (int)$order->id]);
Tools::redirectAdmin($urlResend);
} else {
return false;
}
}
}
Ressource utilisé pour la création de cette article:
Doc prestashop Cancellations and refunds
Posted in:
Aide Prestashop
Leave a comment