jivemoj473 Posted July 13, 2022 Share Posted July 13, 2022 (edited) Hi everyone! I use PS 1.7.8 and figured out that there is no option to attach credit slip as PDF to customer's email. I believe that it is necessary to make changes to the AdminOrdersController.php on line 759 and 1022, as it was mentioned here: Can anyone suggest how this can be implemented? Thanks in advance. Here is the code: Line 759: if (!OrderSlip::create( $order, $order_detail_list, $shipping_cost_amount, $voucher, $choosen, (Tools::getValue('TaxMethod') ? false : true) )) { $this->errors[] = $this->trans('You cannot generate a partial credit slip.', array(), 'Admin.Orderscustomers.Notification'); } else { Hook::exec('actionOrderSlipAdd', array('order' => $order, 'productList' => $order_detail_list, 'qtyList' => $full_quantity_list), null, false, true, false, $order->id_shop); $customer = new Customer((int) ($order->id_customer)); $params['{lastname}'] = $customer->lastname; $params['{firstname}'] = $customer->firstname; $params['{id_order}'] = $order->id; $params['{order_name}'] = $order->getUniqReference(); $orderLanguage = new Language((int) $order->id_lang); @Mail::Send( (int) $order->id_lang, 'credit_slip', $this->trans( 'New credit slip regarding your order', array(), 'Emails.Subject', $orderLanguage->locale ), $params, $customer->email, $customer->firstname . ' ' . $customer->lastname, null, null, null, null, _PS_MAIL_DIR_, true, (int) $order->id_shop ); } Line 1023: // Generate credit slip if (Tools::isSubmit('generateCreditSlip') && !count($this->errors)) { $product_list = array(); $amount = $order_detail->unit_price_tax_incl * $full_quantity_list[$id_order_detail]; $choosen = false; if ((int) Tools::getValue('refund_total_voucher_off') == 1) { $amount -= $voucher = (float) Tools::getValue('order_discount_price'); } elseif ((int) Tools::getValue('refund_total_voucher_off') == 2) { $choosen = true; $amount = $voucher = (float) Tools::getValue('refund_total_voucher_choose'); } foreach ($full_product_list as $id_order_detail) { $order_detail = new OrderDetail((int) $id_order_detail); $product_list[$id_order_detail] = array( 'id_order_detail' => $id_order_detail, 'quantity' => $full_quantity_list[$id_order_detail], 'unit_price' => $order_detail->unit_price_tax_excl, 'amount' => isset($amount) ? $amount : $order_detail->unit_price_tax_incl * $full_quantity_list[$id_order_detail], ); } $shipping = Tools::isSubmit('shippingBack') ? null : false; if (!OrderSlip::create($order, $product_list, $shipping, $voucher, $choosen)) { $this->errors[] = $this->trans('A credit slip cannot be generated.', array(), 'Admin.Orderscustomers.Notification'); } else { Hook::exec('actionOrderSlipAdd', array('order' => $order, 'productList' => $full_product_list, 'qtyList' => $full_quantity_list), null, false, true, false, $order->id_shop); $orderLanguage = new Language((int) $order->id_lang); @Mail::Send( (int) $order->id_lang, 'credit_slip', $this->trans( 'New credit slip regarding your order', array(), 'Emails.Subject', $orderLanguage->locale ), $params, $customer->email, $customer->firstname . ' ' . $customer->lastname, null, null, null, null, _PS_MAIL_DIR_, true, (int) $order->id_shop ); } } Edited July 13, 2022 by jivemoj473 Added PS version to the title (see edit history) Link to comment Share on other sites More sharing options...
ben chagra Posted March 28, 2023 Share Posted March 28, 2023 PrestaShop\PrestaShop\Adapter\Order\Refund\OrderSlipCreator LIGNE 27 namespace PrestaShop\PrestaShop\Adapter\Order\Refund; use PDF; use Address; use Carrier; use Currency; use Customer; use Context; use Db; use Hook; use Mail; use Order; use OrderDetail; use OrderSlip; use PrestaShop\PrestaShop\Core\ConfigurationInterface; use PrestaShop\PrestaShop\Core\Domain\Order\Exception\InvalidCancelProductException; use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderException; use PrestaShop\PrestaShop\Core\Domain\Order\VoucherRefundType; use PrestaShop\PrestaShop\Adapter\ContextStateManager; use PrestaShopDatabaseException; use PrestaShopException; use StockAvailable; use Symfony\Component\Translation\TranslatorInterface; use TaxCalculator; use TaxManagerFactory; use Tools PrestaShop\PrestaShop\Adapter\Order\Refund\OrderSlipCreator LIGNE 80 public function create( Order $order, OrderRefundSummary $orderRefundSummary ) { if ($orderRefundSummary->getRefundedAmount() > 0) { $orderSlipCreated = $this->createOrderSlip( $order, $orderRefundSummary->getProductRefunds(), $orderRefundSummary->getRefundedShipping(), $orderRefundSummary->getVoucherAmount(), $orderRefundSummary->isVoucherChosen(), !$orderRefundSummary->isTaxIncluded(), $orderRefundSummary->getPrecision() ); if (!$orderSlipCreated) { throw new OrderException('You cannot generate a partial credit slip.'); } $fullQuantityList = array_map(function ($orderDetail) { return $orderDetail['quantity']; }, $orderRefundSummary->getProductRefunds()); Hook::exec('actionOrderSlipAdd', [ 'order' => $order, 'productList' => $orderRefundSummary->getProductRefunds(), 'qtyList' => $fullQuantityList, ], null, false, true, false, $order->id_shop); // Join PDF Avoir NESSRINE $order_detail_list = $orderRefundSummary->getProductRefunds(); Hook::exec('actionOrderSlipAdd', array('order' => $order, 'productList' => $order_detail_list, 'qtyList' => $fullQuantityList), null, false, true, false, $order->id_shop); // Get id_order_slip based on customer ID and Order ID $orderSlipTemp = OrderSlip::getOrdersSlip((int)($order->id_customer), (int)($order->id), true); // Create objects and PDF $orderSlip = new OrderSlip((int) ($orderSlipTemp[0]['id_order_slip'])); $orderNew = new Order((int)$orderSlip->id_order); $orderNew->products = OrderSlip::getOrdersSlipProducts($orderSlip->id, $orderNew); $pdf = new PDF($orderSlip, PDF::TEMPLATE_ORDER_SLIP, Context::getContext()->smarty); $file_attachement['content'] = $pdf->render(false); $file_attachement['name'] = $pdf->filename; $file_attachement['mime'] = 'application/pdf'; $customer = new Customer((int) $order->id_customer); // @todo: use private method to send mail $params = [ '{lastname}' => $customer->lastname, '{firstname}' => $customer->firstname, '{id_order}' => $order->id, '{order_name}' => $order->getUniqReference(), '{credit-slip-amount}' => $orderRefundSummary->getRefundedAmount(), ]; $orderLanguage = $order->getAssociatedLanguage(); // @todo: use a dedicated Mail class (see #13945) // @todo: remove this @and have a proper error handling @Mail::Send( (int) $orderLanguage->getId(), 'credit_slip', $this->translator->trans( 'New credit slip regarding your order', [], 'Emails.Subject', $orderLanguage->locale ), $params, $customer->email, $customer->firstname . ' ' . $customer->lastname, null, null, $file_attachement, null, _PS_MAIL_DIR_, true, (int) $order->id_shop ); /** @var OrderDetail $orderDetail */ foreach ($orderRefundSummary->getOrderDetails() as $orderDetail) { if ($this->configuration->get('PS_ADVANCED_STOCK_MANAGEMENT')) { StockAvailable::synchronize($orderDetail->product_id); } } } else { throw new InvalidCancelProductException(InvalidCancelProductException::INVALID_AMOUNT); } } Link to comment Share on other sites More sharing options...
sandeeptech Posted December 24, 2023 Share Posted December 24, 2023 @ben chagra Thank you, its working like a charm. use PDF; use Context; use PrestaShop\PrestaShop\Adapter\ContextStateManager;Remember to initiate the above classes and then the below code after actionOrderSlipAdd hook // Join PDF Avoir NESSRINE $order_detail_list = $orderRefundSummary->getProductRefunds(); Hook::exec('actionOrderSlipAdd', array('order' => $order, 'productList' => $order_detail_list, 'qtyList' => $fullQuantityList), null, false, true, false, $order->id_shop); // Get id_order_slip based on customer ID and Order ID $orderSlipTemp = OrderSlip::getOrdersSlip((int)($order->id_customer), (int)($order->id), true); // Create objects and PDF $orderSlip = new OrderSlip((int) ($orderSlipTemp[0]['id_order_slip'])); $orderNew = new Order((int)$orderSlip->id_order); $orderNew->products = OrderSlip::getOrdersSlipProducts($orderSlip->id, $orderNew); $pdf = new PDF($orderSlip, PDF::TEMPLATE_ORDER_SLIP, Context::getContext()->smarty); $file_attachement['content'] = $pdf->render(false); $file_attachement['name'] = $pdf->filename; $file_attachement['mime'] = 'application/pdf'; 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