Hi,
I have to finish the update of a Prestashop module to print shipping labels (it was working on PS < 1.7.7).
I'm not the original developper of this module.
I have many years of experience as a PHP developer, but never touched a Prestashop instance... and I have to admit I'm quite lost on how to solve this issue !
The module adds two buttons :
- one on the back-office/order page (see screenshot)
- one on the back-office/orders page (see screenshot)
The button on the order page is added with a button.tpl file.
Main module class :
public function hookActionAdminControllerSetMedia() { ... $ajax_link = $link->getModuleLink('unikshipping', 'FrontAjaxUnik', $parameters); Media::addJsDef(array( 'ajax_controller' => $ajax_link, 'token_key'=>$this->token_key )); ... }
FrontAjaxUnik.php :
public function displayAjaxUnikAction() { $UnikShipping = new UnikShipping(); $order_id = Tools::getValue('order_id'); echo $UnikShipping->shipOrderButton($order_id); }
Main module class :
public function shipOrderButton($id) { ... return $this->context->smarty ->fetch(_PS_MODULE_DIR_.'/unikshipping/views/templates/admin/unik_shipping/button.tpl'); }
button.tpl :
<span class='btn-group-action'> <span class='btn-group'> <button style ='margin-right:4px; padding: 6px 2px!important;' type ='button' class='btn btn-default' onclick='$.ajax({ url: "{$ajax_controller|escape:'htmlall':'UTF-8'}", data: { order_id: "{$id|escape:'htmlall':'UTF-8'}", }, ... '>{$btname|escape:'htmlall':'UTF-8'}</button> </span> </span>
This button is working perfectly !
But the button on the orders page is added with a mymodule_button.html.twig file.
Main module class:
public function hookActionOrderGridDefinitionModifier(array $params) { ... $definition = $params['definition']; $definition ->getColumns() ->addAfter( 'date_add', (new HtmlTypeColumn('wk_button')) ->setName($this->l('Unik Shipping')) ->setOptions([ 'ModuleClass' => new UnikShipping(), 'custom_text' => $this->ship_trans ]) ); }
class HtmlTypeColumn extends AbstractColumn :
public function getType() { return 'mymodule_button'; }
mymodule_button.html.twig :
<a href="https://www.google.com" class="btn btn-primary pointer"> <i class="icon-user"></i> {{ column.options.custom_text }} </a>
Basically, I have to replace the google.com href with an Ajax call, but I need the order id to do that and I have no clue on how the get it !
I tried Googling "prestashop twig get order id" and "prestashop twig get var" but couldn't sort it out.