Change department for customer threads in PrestaShop 1.6

In this quick tip, we will see how to easily modify the PrestaShop back office template, so to be able to change the customer messages’ department whenever we want.

Watch the screencast

Text Version

This tutorial can be applied to ThirtyBees as well!

Part of the functionality we need is in PrestaShop already, all we have to do is add some place where we can submit the change of department type.
Open up AdminCustomerThreadsController.php located in controllers/admin or use an override instead (recommended). We are interested in the renderView method, specifically where it assigns $this->tpl_vars, around line 700 in PrestaShop

        $this->tpl_view_vars = array(
            'id_customer_thread' => $id_customer_thread,
            'thread' => $thread,
            'actions' => $actions,
            'employees' => $employees,
            'current_employee' => $this->context->employee,
            'messages' => $messages,
            'first_message' => $first_message,
            'contact' => $contact,
            'contacts' => $contacts, // <-- This is what we added!
            'next_thread' => $next_thread,
            'orders' => isset($orders) ? $orders : false,
            'customer' => isset($customer) ? $customer : false,
            'products' => isset($products) ? $products : false,
            'total_ok' => isset($total_ok) ?  Tools::displayPrice($total_ok, $this->context->currency) : false,
            'orders_ok' => isset($orders_ok) ? $orders_ok : false,
            'count_ok' => isset($orders_ok) ? count($orders_ok) : false,
            'PS_CUSTOMER_SERVICE_SIGNATURE' => str_replace('\r\n', "\n", Configuration::get('PS_CUSTOMER_SERVICE_SIGNATURE', (int)$thread->id_lang)),
            'timeline_items' => $timeline_items,

Please note: if you use an override, copy the whole method, add the variable as described above, and make sure you change return parent::renderView() to return AdminController::renderView() at the very end! Failing to do so will make it impossible for our new variable to be used in the template, as the parent class would simply override the tpl_vars.

Now that we have the variable containing all contacts, let’s add a form to submit it, in the view.tpl template of that controller. The file we want is located in the theme folder themes\default\template\controllers\customer_threads\helpers\view. Once more, it’s named view.tpl.
You can find any spot you like for the new button, I added it at the very beginning, before the div with class “well”

	<div class="well">
		<form action="{$link->getAdminLink('AdminCustomerThreads')|escape:'html':'UTF-8'}&amp;viewcustomer_thread&amp;id_customer_thread={$id_customer_thread|intval}" method="post" class="form-horizontal">
			<div class="row">
				<div class="col-sm-3">
					<select name="id_contact">
						{foreach from=$contacts item=dept}
							<option value="{$dept.id_contact}" {if $ == $contact}selected="selected"{/if}>
				<div class="col-sm-3">
					<button class="btn btn-default" type="submit">
						{l s='Change Department'}

Save and refresh, we should be done! We didn’t have to add any post processing code, simply because it’s already present, at the very beginning of the postProcess method of the AdminCustomerThreadsController.

You like the tuts and want to say "thank you"? Well, you can always feel free to donate:

  • Allen Iver

    thanks for your share! i like it.

Store Top Sales

You like the tuts and want to say "thank you"? Well, you can always feel free to donate: