Jump to content

Attach credit slip PDF to customer email


jaxTus

Recommended Posts

Hi,

 

I'm trying to create the credit slip PDF in AdminOrdersController.php at line 846 after Hook::exec('actionOrderSlipAdd' to then attached to the proceeding @Mail::Send

 

Can anyone help by telling me how to get the credit slip object for new PDF();

 

$pdf = new PDF(NEED_CREDIT_SLIP_OBJECT, PDF::TEMPLATE_ORDER_SLIP, $this->context->smarty);
$file_attachement['content'] = $pdf->render(false);
$file_attachement['name'] = 'credit-slip-'.sprintf('%06d', $order->id).'.pdf';
$file_attachement['mime'] = 'application/pdf';
Edited by jaxTus (see edit history)
Link to comment
Share on other sites

A hint from /controllers/admin/AdminPdfController.php

    public function processGenerateOrderSlipPDF()
    {
        $orderSlip = new OrderSlip((int)Tools::getValue('id_order_slip'));
        $order = new Order((int)$orderSlip->id_order);
        if (!Validate::isLoadedObject($order))
            die(Tools::displayError('The order cannot be found within your database.'));
        $order->products = OrderSlip::getOrdersSlipProducts($orderSlip->id, $order);

        $this->generatePDF($orderSlip, PDF::TEMPLATE_ORDER_SLIP);
    }
Link to comment
Share on other sites

So I now have the following but it is failing on validate:isLoadedObject with 'The order cannot be found within your database.'

I assume I need to change (int)Tools::getValue('id_order_slip') as $orderSlip->id_order is null and causing the database lookup error.

 

How else can I get the id_order_slip after it is created?

 

$orderSlip = new OrderSlip((int)Tools::getValue('id_order_slip'));
$order = new Order((int)$orderSlip->id_order);
if (!Validate::isLoadedObject($order))
die(Tools::displayError('The order cannot be found within your database.'));
$order->products = OrderSlip::getOrdersSlipProducts($orderSlip->id, $order);
 
$pdf = new PDF($orderSlip, PDF::TEMPLATE_ORDER_SLIP, $this->context->smarty);
$file_attachement['content'] = $pdf->render(false);
$file_attachement['name'] = 'credit-slip-'.sprintf('%06d', $orderSlip->id).'.pdf';
$file_attachement['mime'] = 'application/pdf';
Link to comment
Share on other sites

  • 1 year later...

I had the same problem. Here my solution which worked for me:

               

                // 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);
                if (!Validate::isLoadedObject($orderNew))
                die(Tools::displayError('The order cannot be found within your database.'));
                $orderNew->products = OrderSlip::getOrdersSlipProducts($orderSlip->id, $orderNew);
 
                $pdf = new PDF($orderSlip, PDF::TEMPLATE_ORDER_SLIP, $this->context->smarty);
                $file_attachement['content'] = $pdf->render(false);
                $file_attachement['name'] = 'ZSGT-'.sprintf('%06d', $orderSlip->id).'.pdf';
                $file_attachement['mime'] = 'application/pdf';

  • Like 1
Link to comment
Share on other sites

  • 4 years later...
  • 5 months later...

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...