SlimDeluxe Posted October 11, 2015 Share Posted October 11, 2015 Hi, I am having problems with attaching content to the displayAdminOrder hook. It displays just fine when I open the order (see attachment #1). But when I press the Capture button in a form I have, the resulting page is missing all the content from the view order page that appears before this hook is called (attachment #2). If I re-open the order it again displays normally. I tried displayAdminOrderLeft too, with the same results... (everything before it is cut off) I've check Paymill and PayPal modules and they basicall use the code to display the TPL, so I am really lost why does it not work for me. Here's my hook public function hookdisplayAdminOrder($params) { if (! $this->active) { return; } $id_order = (int)$params['id_order']; /* @var $order OrderCore */ $order = new Order($id_order); if (! Validate::isLoadedObject($order) || $order->module !== $this->name) { return; } if (Tools::isSubmit('megapos_capture')) { $tx_code = Tools::getValue('tx_code'); if ($tx_code) { $tx = Transaction::fetchByCode($tx_code); if (Validate::isLoadedObject($tx)) { try { $client = MegaposTools::getClient(); $params = array( 'store-id' => MegaposTools::getStoreParam(), 'transaction-id' => $tx->tx_code, 'amount' => $tx->amount ); $rs = $client->processTransaction($params); $tx->setState($rs->{'active-state'}->type); if ($tx->state === 'PROCESSED') { $msg = $this->l('Funds successfully captured!'); $msg_error = false; } else { $msg = $this->l('Could not capture funds.') .' '. $this->l('Error returned by processing centre: '); $msg_error = true; } } catch (Exception $ex) { $msg = $this->l('Could not capture funds.') .' '. $this->l('Initialization error: '). $ex->getMessage(); $msg_error = true; } $this->context->smarty->assign(array( 'megapos_msg' => $msg, 'megapos_error' => $msg_error )); } } } $this->context->smarty->assign(array( 'list_tx' => Transaction::fetchListByOrderId($order->id) )); return $this->display(__FILE__, 'admin_vieworder_tx.tpl'); } And here's the TPL: <div id="formTransactionsPanel" class="panel"> <div class="panel-heading"> <i class="icon-credit-card"></i> {l s="Transactions"} <span class="badge">{$list_tx|@count}</span> </div> {if isset($megapos_msg)} <div class="alert {if ! $megapos_error}alert-success{else}alert-danger{/if}"> {$megapos_msg} </div> {/if} <div class="table-responsive"> <table class="table"> <thead> <tr> <th><span class="title_box ">{l s='Date'}</span></th> <th><span class="title_box ">{l s='Transaction ID' mod=megapos}</span></th> <th><span class="title_box ">{l s='Amount'}</span></th> <th><span class="title_box ">{l s='State'}</span></th> <th><span class="title_box ">{l s='Updated'}</span></th> <th></th> </tr> </thead> <tbody> {foreach $list_tx as $tx} <tr class="{if $tx->isPending()}warning{elseif $tx->hasFailed()}danger{/if}"> <td>{dateFormat date=$tx->date_add full=true}</td> <td>{$tx->tx_code}</td> {*<td>{$payment->transaction_id|escape:'html':'UTF-8'}</td>*} <td>{displayPrice price=$tx->amount currency=$tx->getCurrencyId()}</td> <td>{$tx->state}</td> <td> {if $tx->date_upd} {dateFormat date=$tx->date_upd full=true} {else} ∅ {/if} </td> <td class="actions"> <form method="POST"> <input name="tx_code" type="hidden" value="{$tx->tx_code}"/> {if $tx->needsCapture()} <button name="megapos_capture" class="btn btn-success" type="submit" onclick="if (!confirm('{l s='Are you sure you want to capture the specified amount?' mod=megapos}'))return false;"> <i class="icon-check"></i> {l s='Capture' mod=megapos} </button> {/if} </form> </td> </tr> {foreachelse} <tr> <td class="list-empty hidden-print" colspan="6"> <div class="list-empty-msg"> <i class="icon-warning-sign list-empty-icon"></i> {l s='No transactions have been initialized' mod=megapos} </div> </td> </tr> {/foreach} </tbody> </table> </div> </div> Link to comment Share on other sites More sharing options...
amina1236 Posted March 13, 2021 Share Posted March 13, 2021 On 10/11/2015 at 11:28 AM, SlimDeluxe said: Hi, I am having problems with attaching content to the displayAdminOrder hook. It displays just fine when I open the order (see attachment #1). But when I press the Capture button in a form I have, the resulting page is missing all the content from the view order page that appears before this hook is called (attachment #2). If I re-open the order it again displays normally. I tried displayAdminOrderLeft too, with the same results... (everything before it is cut off) I've check Paymill and PayPal modules and they basicall use the code to display the TPL, so I am really lost why does it not work for me. Here's my hook public function hookdisplayAdminOrder($params) { if (! $this->active) { return; } $id_order = (int)$params['id_order']; /* @var $order OrderCore */ $order = new Order($id_order); if (! Validate::isLoadedObject($order) || $order->module !== $this->name) { return; } if (Tools::isSubmit('megapos_capture')) { $tx_code = Tools::getValue('tx_code'); if ($tx_code) { $tx = Transaction::fetchByCode($tx_code); if (Validate::isLoadedObject($tx)) { try { $client = MegaposTools::getClient(); $params = array( 'store-id' => MegaposTools::getStoreParam(), 'transaction-id' => $tx->tx_code, 'amount' => $tx->amount ); $rs = $client->processTransaction($params); $tx->setState($rs->{'active-state'}->type); if ($tx->state === 'PROCESSED') { $msg = $this->l('Funds successfully captured!'); $msg_error = false; } else { $msg = $this->l('Could not capture funds.') .' '. $this->l('Error returned by processing centre: '); $msg_error = true; } } catch (Exception $ex) { $msg = $this->l('Could not capture funds.') .' '. $this->l('Initialization error: '). $ex->getMessage(); $msg_error = true; } $this->context->smarty->assign(array( 'megapos_msg' => $msg, 'megapos_error' => $msg_error )); } } } $this->context->smarty->assign(array( 'list_tx' => Transaction::fetchListByOrderId($order->id) )); return $this->display(__FILE__, 'admin_vieworder_tx.tpl'); } And here's the TPL: <div id="formTransactionsPanel" class="panel"> <div class="panel-heading"> <i class="icon-credit-card"></i> {l s="Transactions"} <span class="badge">{$list_tx|@count}</span> </div> {if isset($megapos_msg)} <div class="alert {if ! $megapos_error}alert-success{else}alert-danger{/if}"> {$megapos_msg} </div> {/if} <div class="table-responsive"> <table class="table"> <thead> <tr> <th><span class="title_box ">{l s='Date'}</span></th> <th><span class="title_box ">{l s='Transaction ID' mod=megapos}</span></th> <th><span class="title_box ">{l s='Amount'}</span></th> <th><span class="title_box ">{l s='State'}</span></th> <th><span class="title_box ">{l s='Updated'}</span></th> <th></th> </tr> </thead> <tbody> {foreach $list_tx as $tx} <tr class="{if $tx->isPending()}warning{elseif $tx->hasFailed()}danger{/if}"> <td>{dateFormat date=$tx->date_add full=true}</td> <td>{$tx->tx_code}</td> {*<td>{$payment->transaction_id|escape:'html':'UTF-8'}</td>*} <td>{displayPrice price=$tx->amount currency=$tx->getCurrencyId()}</td> <td>{$tx->state}</td> <td> {if $tx->date_upd} {dateFormat date=$tx->date_upd full=true} {else} ∅ {/if} </td> <td class="actions"> <form method="POST"> <input name="tx_code" type="hidden" value="{$tx->tx_code}"/> {if $tx->needsCapture()} <button name="megapos_capture" class="btn btn-success" type="submit" onclick="if (!confirm('{l s='Are you sure you want to capture the specified amount?' mod=megapos}'))return false;"> <i class="icon-check"></i> {l s='Capture' mod=megapos} </button> {/if} </form> </td> </tr> {foreachelse} <tr> <td class="list-empty hidden-print" colspan="6"> <div class="list-empty-msg"> <i class="icon-warning-sign list-empty-icon"></i> {l s='No transactions have been initialized' mod=megapos} </div> </td> </tr> {/foreach} </tbody> </table> </div> </div> On 10/11/2015 at 11:28 AM, SlimDeluxe said: Validate::isLoadedObject($order) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now