Jump to content

$params empty in actionPDFInvoiceRender Hook


Recommended Posts

Hello,

[NOOBIE QUESTION]
I've been seraching for a way to get customer details and order details inside the hook "actionPDFInvoiceRender " it always end up with an empty object....

I really dont get it, I tried diffrent way to get these information from the hook, this->getContext() etc... I JUST CANT get these information.

So basically my question is how to retrieve customer's details and order's details in this hook ?

This snippet :

public function hookactionPDFInvoiceRender($hookArgs)
{

    $order = new Order((int)$hookArgs['id_order']);

    var_dump($hookArgs); die();
}

Shows

 

/var/www/html/modules/jba_qr/jba_qr.php:161:
array (size=4)
  'order_invoice_list' => 
    object(PrestaShopCollection)[842]
      protected 'classname' => string 'OrderInvoice' (length=12)
      protected 'id_lang' => null
      protected 'definition' => 
        array (size=4)
          'table' => string 'order_invoice' (length=13)
          'primary' => string 'id_order_invoice' (length=16)
          'fields' => 
            array (size=18)
              ...
          'classname' => string 'OrderInvoice' (length=12)
      protected 'query' => 
        object(DbQuery)[839]
          protected 'query' => 
            array (size=9)
              ...
      protected 'results' => 
        array (size=0)
          empty
      protected 'is_hydrated' => boolean false
      protected 'iterator' => int 0
      protected 'total' => null
      protected 'page_number' => int 0
      protected 'page_size' => int 0
      protected 'fields' => 
        array (size=1)
          'id_order' => 
            array (size=4)
              ...
      protected 'alias' => 
        array (size=1)
          '' => string 'a0' (length=2)
      protected 'alias_iterator' => int 1
      protected 'join_list' => 
        array (size=0)
          empty
      protected 'association_definition' => 
        array (size=0)
          empty
  'cookie' => 
    object(Cookie)[13]
      protected '_content' => 
        array (size=13)
          'date_add' => string '2021-08-28 23:00:25' (length=19)
          'id_lang' => int 1
          'detect_language' => string '1' (length=1)
          'shopContext' => string 's-1' (length=3)
          'id_employee' => string '1' (length=1)

It is probably super-easy to get theses information but I already lost like 3 hours to find a way to retrieve them.....

 

Link to comment
Share on other sites

    /**
     * @param array{cookie: Cookie, cart: Cart, altern: int, order_invoice_list: OrderInvoice[]} $params
     */
    public function hookActionPDFInvoiceRender(array $params)
    {
        if (isset($params['order_invoice_list'])) {
            foreach ($params['order_invoice_list'] as $orderInvoice) {
                if (Validate::isLoadedObject($orderInvoice)) {
                    $order = new Order((int) $orderInvoice->id_order);

                    if (Validate::isLoadedObject($order)) {
                        $orderDetails = $order->getOrderDetailList();
                        $customer = new Customer((int) $order->id_customer);
                        if (Validate::isLoadedObject($customer)) {
                            $firstname = $customer->firstname;
                        }
                    }
                }
            }
        }
    }

 

Edited by Janett (see edit history)
  • Like 1
Link to comment
Share on other sites

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