aguiu Posted July 9, 2017 Share Posted July 9, 2017 (edited) I have created a field called "Hora Recogida" (pickup time) in my orders database, (only for internal usage). This time is shown in Orders List of my backoffice (adminOrdersController.php): 'hora_recogida' => array( 'title' => $this->l('Hora Recogida'), 'width' => 90, 'align' => 'center', 'type' => 'time', 'filter_key' => 'a!hora_recogida' ), code for save it (adminOrdersController.php): public function postProcess() { parent::postProcess(); $order = new Order(Tools::getValue('id_order')); if (Tools::isSubmit('submitHora_recogida') && isset($order)) //gestion Hora_recogida { $hora_recogida=Tools::getValue('hora_recogida',''); $res =false; $valid=true;//dejamos preparado por si hay que validar alguna cosa if(!$valid){ $this->errors[] = Tools::displayError('Error de formato'); }else{ $order->hora_recogida=$hora_recogida; $res = $order->update(); } if ($res) Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=4&token='.$this->token); else $this->errors[] = Tools::displayError('Un error ha pasado al guardar la hora de recogida'); } } i change it from view.tpl: <div id="hora_recogida_order_panel" class="panel hidden-print" style="height: 100px;"> <div class="panel-heading"> <i class="icon-calendar-o"></i> {l s="Hora de recogida"} </div> <form action="{$currentIndex|escape:'html':'UTF-8'}&vieworder&token={$smarty.get.token}" method="post"> <div class="form-group"> <div class="col-lg-10" style="height: 30px;" > <button name="submitHora_recogida" class="btn btn-primary pull-right" id="submitHora_recogida" type="submit"> {l s='Guardar'} </button> <textarea class="form-control fixed-width-sm" maxlength="8" rows="1" cols="20" name="hora_recogida" >{if isset($smarty.post.hora_recogida)}{$smarty.post.hora_recogida}{else}{$order->hora_recogida}{/if}</textarea> <input type="hidden" name="id_order" value="{$order->id}" /> </div> </div> </form> </div> The problem is the time format, 00:00:00 (hh:mm:ss). I need to view it in format 00:00 (hh:mm), in order list and in view.tpl. I also needs when save the time from view.tpl it's validate that the time format is right, because now i input for example an text and nothing is validated (no error is showing). I also need that when the time is 0 nothing is shown (in backoffice order list), i don't want to see 00:00. Edited July 9, 2017 by aguiu (see edit history) Link to comment Share on other sites More sharing options...
Scully Posted July 10, 2017 Share Posted July 10, 2017 The syntax of formatting times in TPL is: {$smarty.now|date_format:"%H:%M:%S"} so the change would look like this: if isset($smarty.post.hora_recogida)}{$smarty.post.hora_recogida|date_format:"%H:%M"}{else}{$order->hora_recogida}{/if} Link to comment Share on other sites More sharing options...
Scully Posted July 10, 2017 Share Posted July 10, 2017 And for the validation of the input in format HH:MM - to be implemented in the Controller. Untested code: if(!preg_match('/^(?:[01][0-9]|2[0-3]):[0-5][0-9]$/',$input)) { $this->errors[] = Tools::displayError('Invalid pick up time.'); } Link to comment Share on other sites More sharing options...
aguiu Posted July 15, 2017 Author Share Posted July 15, 2017 The syntax of formatting times in TPL is: {$smarty.now|date_format:"%H:%M:%S"} so the change would look like this: if isset($smarty.post.hora_recogida)}{$smarty.post.hora_recogida|date_format:"%H:%M"}{else}{$order->hora_recogida}{/if} That not works still hh:mm:ss is showing Link to comment Share on other sites More sharing options...
aguiu Posted July 15, 2017 Author Share Posted July 15, 2017 (edited) And for the validation of the input in format HH:MM - to be implemented in the Controller. Untested code: if(!preg_match('/^(?:[01][0-9]|2[0-3]):[0-5][0-9]$/',$input)) { $this->errors[] = Tools::displayError('Invalid pick up time.'); } The right one for 24h time is !preg_match('/(2[0-4]|[01][1-9]|10)[0-5][0-9])/',$hora_recogida) Edited July 15, 2017 by aguiu (see edit history) Link to comment Share on other sites More sharing options...
aguiu Posted July 15, 2017 Author Share Posted July 15, 2017 I have the pick up time field in backoffice order list, when the field is empty it shows 00:00:00. Is possible to show the field empty when really is empty? not shows 00:00:00 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