Jump to content

Access or Insert value in data array in PaymentModule.php


Recommended Posts

Hello,

 i am using prestashop 8.1.4.

i would like to insert a value in the $data array in PaymentModule.php form my module. This value i need to display on order_conf template to customer, which takes values from this array. But i do not want to override the (validateOrder function)  PaymentModule.php and want to do that from my module that is installed. In this my module i am hooked to actionValidateOrder hook, but the params that i get from this hook are:

 'cart' => $this->context->cart,
                'order' => $order,
                'customer' => $this->context->customer,
                'currency' => $this->context->currency,
                'orderStatus' => $order_status,

So i can't access the $data array as far as i see, as $data is not property of order or cart objects. I also see that there is a hook in this PaymentModule.php called "actionValidateOrderAfter" but the params in this hooks are similair and as far as i think i can't access this array there too. I have made other things in my module but have two generated values that want to send to template order_conf by merging them (array_merge) to $data array. Problem is how to access this array from my module? Can anyone help me?

In my module i have also registered to hook SendMailAlterTemplateVars - but the parameters there are sent only to (mailalerts module) templates - so i can not use them in the order_conf template. 

So how can I access this $data array from hookactionValidateOrder function in my module? Is that possible? Or where from?

Regards,

 

Link to comment
Share on other sites

  • 2 weeks later...

Hello again,

i found the solution. It was actually very close, but I didn't pay enough attention to the SendMailAlterTemplateVars hook. If you register to this hook in the module you can take as a parameter every mail template - core and module teplates. The templates are actually in the params array as a parameter. Just like stated here

/** * @param $param * @return string */

public function hooksendMailAlterTemplateVars($params)

{

$context = Context::getContext();

if ($params['template'] == 'new_order')

***

}

So instead of new_order you can use any other template - order_conf; bankwire ... etc. So this is much easier to use this hook. 

I just thaught initially that I can access only module mail templates within this hook. But it is not - so if someoone needs to do it - here it is.

regards

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