2016-07-13 3 views
0

Ich möchte meinen Druckstatus ändern, ich kann das Symbol platzieren, um den Status zu ändern, aber die Änderung tritt nicht auf, wenn ich auf das Druckstatus-Symbol klicke Im Bild habe ich den Callback als changePrintStatusWie man einen bool Wert in prestashop ändert 1.6 back end by icon klicken

der Code erreicht initProcess(), wenn das Change-Status-Symbol geklickt wird, Aber danach was genau muss passieren ?? Oder muss ich eine andere Funktion/override-Funktion aufrufen ? (Ich habe das gleiche wie in Kundenliste machen wollen, wo wir aktiv Status der Kunden ändern, in ähnlicher Weise möchte ich hier für meine benutzerdefinierten Modul tun)

enter image description here

<?php 

    require_once(_PS_MODULE_DIR_.'eticketprinting/eticketprinting.php'); 
    require_once(_PS_MODULE_DIR_.'eticketprinting/classes/Eticket.php'); 

    class EticketController extends ModuleAdminController 
    { 
      public $module; 
      public $html; 
      public $tabName = 'renderForm'; 

     public function __construct() 
     { 
      $this->tab = 'eticket'; 
      $this->module = new eticketprinting(); 
       $this->addRowAction('edit'); 
      //$this->addRowAction('edit'); 
      // $this->addRowAction('view'); // to display the view 
      //$this->addRowAction('delete'); 
      $this->explicitSelect = false; 
      $this->context = Context::getContext(); 
      $this->id_lang = $this->context->language->id; 
      $this->lang = false; 
      $this->ajax = 1; 
      $this->path = _MODULE_DIR_.'eticketprinting'; 
      $this->default_form_language = $this->context->language->id; 
      $this->table = _DB_KITS_PREFIX_.'print_eticket'; 
      $this->className = 'Eticket'; 
      $this->identifier = 'id_print_eticket'; 
      $this->allow_export = true; 
      $this->_select = ' 
      id_print_eticket, 
      ticket_id, 
      ticket_no, 
      product_id, 
      print_status, 
      date_add, 
      date_upd 
      '; 
      $this->name = 'EticketController'; 
      $this->bootstrap = true; 
      $this->initTabModuleList(); 
      $this->initToolbar(); 
      $this->initPageHeaderToolbar(); 
      // $this->initFieldList(); 

      //$this->initContent(); 
      parent::__construct(); 
      $this->fields_list = 
      array(
      'id_print_eticket' => array(
      'title' => $this->l('E-Ticket Print ID'), 
      'width' => 25, 
      'type' => 'text', 
      ), 
      'ticket_id' => array(
      'title' => $this->l('Ticket- ID'), 
      'width' => 140, 
      'type' => 'text', 
      ), 
      'ticket_no' => array(
      'title' => $this->l('Ticket No'), 
      'width' => 140, 
      'type' => 'text', 
      ), 
      'product_id' => array(
      'title' => $this->l('Product ID'), 
      'width' => 100, 
      'type' => 'text',  
      ), 
      'print_status' => array(
      'title' => $this->l('Print Status'), 
      'align' => 'center', 
      'type' => 'bool', 
      'callback' => 'changePrintStatus',    
      'orderby' => false,  
      ), 
      'date_add' => array(
      'title' => $this->l('Date Add'), 
      'width' => 140, 
      'type' => 'text', 
      ), 
      'date_upd' => array(
      'title' => $this->l('Date Update'), 
      'width' => 140, 
      'type' => 'text', 
      ), 
     ); 

     } 

     public function changePrintStatus($value, $eticket) 
     { 
     return '<a class="list-action-enable '.($value ? 'action-enabled' : 'action-disabled').'" href="index.php?'.htmlspecialchars('tab=Eticket&id_print_eticket=' 
     .(int)$eticket['id_print_eticket'].'&changePrintVal&token='.Tools::getAdminTokenLite('Eticket')).'"> 
     '.($value ? '<i class="icon-check"></i>' : '<i class="icon-remove"></i>'). 
     '</a>'; 
     } 


     public function initProcess() 
     { 
     parent::initProcess(); 
     //d($this->id_object); 
     if (Tools::isSubmit('changePrintVal') && $this->id_object) { 
       if ($this->tabAccess['edit'] === '1') { 
        //d("reached here"); 
        $this->action = 'change_print_val'; 
       } else { 
        $this->errors[] = Tools::displayError('You do not have permission to change this.'); 
       } 

      } 
     } 

     public function postProcess() 
     { 
      //When generate pdf button is clicked 
     if (Tools::isSubmit('submitAddeticket')) { 
       if (!Validate::isDate(Tools::getValue('date_from'))) { 
        $this->errors[] = $this->l('Invalid "From" date'); 
       } 

       if (!Validate::isDate(Tools::getValue('date_to'))) { 
        $this->errors[] = $this->l('Invalid "To" date'); 
       } 
       if (!Validate::isInt(Tools::getValue('id_product')) || Tools::getValue('id_product')=='') { 
        $this->errors[] = $this->l('Invalid Product/select a product '); 
       } 

       if (!count($this->errors)) { 
        if (count(Ticket::getByProductNDateInterval(Tools::getValue('id_product'),Tools::getValue('date_from'), Tools::getValue('date_to')))) { 

         //d($this->context->link->getAdminLink('AdminPdf')); 
    Tools::redirectAdmin($this->context->link->getAdminLink('AdminPdf').'&submitAction=generateEticketPDF&id_product='.urlencode(Tools::getValue('id_product')).'&date_from='.urlencode(Tools::getValue('date_from')).'&date_to='.urlencode(Tools::getValue('date_to'))); 
        } 

        $this->errors[] = $this->l('No tickets has been found or Ticket Generated Already for this period for Product ID:'.Tools::getValue('id_product').' (Change the Print Status generate the E-Ticket Again)'); 
       } 
      } else { 
       parent::postProcess(); 
      } 

     } 










    } 

Antwort

1

ich die Prozessfunktion fehlt:

** Beachten Sie aber, dass $ this-> action = 'change_print_val'; und Name f der Prozess muss in meinem Fall ähnlich sein processChangePrintVal

Also, wenn Aktion ist $ this-> action = 'change_printStatus_val'; dann müssen Prozessname processChangePrintStatusVal **

sein I Below-Funktion hinzugefügt

/** 
* Toggle the Eticket Print Status flag- Here the update action occurs 
*/ 
public function processChangePrintVal() 
{ 
$eticket = new Eticket($this->id_object); 
if (!Validate::isLoadedObject($eticket)) { 
$this->errors[] = Tools::displayError('An error occurred while updating Eticket Print Status information.'); 
} 
$eticket->print_status = $eticket->print_status ? 0 : 1; 
if (!$eticket->update()) { 
$this->errors[] = Tools::displayError('An error occurred while Eticket Print Status customer information.'); 
} 
Tools::redirectAdmin(self::$currentIndex.'&token='.$this->token); 
} 
Verwandte Themen