2016-07-13 14 views
0

ステータスを変更するアイコンを配置することはできますが、表示されたPrintステータスアイコンをクリックすると変更は行われません。私はchangePrintStatusとしてコールバックを配置しましたprestashop 1.6のバックエンドでbool値を変更する方法アイコンをクリックして

変更状況アイコンがクリックされたときにコードが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); 
} 
関連する問題