2016-07-13 1 views
0

인쇄 상태를 변경하고 상태를 변경하려면 아이콘을 배치 할 수 있지만 표시된 인쇄 상태 아이콘을 클릭하면 변경이 발생하지 않습니다. 이미지에서 changePrintStatus로 콜백을 배치했습니다.prestashop 1.6 백 엔드에서 아이콘을 클릭하여 부울 값을 변경하는 방법

변경 상태 아이콘을 클릭하면 코드가 initProcess()에 도달합니다. 그런 다음 정확히 무슨 일이 발생해야합니까? 또는 다른 함수/재정의 함수를 호출해야합니까? ?

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(); 
      } 

     } 










    } 

답변

1

내가 처리 기능을 잃어버린 (나는 우리가 고객의 활성 상태를 변경 고객 목록에서와 동일한 기능을 수행 할 마찬가지로 나는 내 사용자 지정 모듈 여기를 수행 할) :

**하지만 $ this-> action = 'change_print_val'; 및 이름은 프로세스가 내 경우에 비슷해야합니다. processChangePrintVal

따라서 조치가 $ this-> action = 'change_printStatus_val'인 경우; 다음 프로세스 이름은 내가 기능 아래에 추가 **

processChangePrintStatusVal해야

/** 
* 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); 
} 
관련 문제