Prestashop 的back office tab 筆記 - Part 5

之前講到prestashop升級至1.5.x後它的backoffice 改動很太,所以基本上admin tab 也是要重新寫過的呢,如果看看它的change log, 基本上v1.5.0.1把之前的admintab 也換了是controller 呢,所以寫法上也會有一點點的出入,所以之前的筆記23是不太適用於1.5+呢

好首先最主要的改動是我地由之前extends AdminTab變成為AdminController
class AdminFastGetDiscountSettingControllerCore extends AdminController{
...
}

它的constructor 基本上是類似的, 不過之前所用的fieldsDisplay就換成為fields_list
參考example:
public function __construct()
{  
 $this->table = 'product_fast_get_discount';
 $this->className = 'FastGetDiscount';
 $this->lang = false;
 
 $this->identifier = "id_pfgd";
 
 $this->addRowAction('edit');
 $this->addRowAction('delete');
 
 $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?')));
  
 $this->fields_list = array(
  'id_pfgd' => array(
   'title' => $this->l('ID'),
   'align' => 'center',
   'width' => 25
  ),  
  'product_name' => array(
   'title' => $this->l('Name'),
   'align' => 'left',    
   'orderby' => false,
   'filter' => false,
   'search' => false
  ),
  'position' => array(
   'title' => $this->l('No. of Sold'),
   'align' => 'center',
   'width' => 90
  ),
  'reduction' => array(
   'title' => $this->l('Reduction'),
   'align' => 'right',
   'width' => 100
  )
 );   

 parent::__construct();  
}

除此之外之前是利用edit/delete的變數來設定每一行可以做的action, 但在controller的叫法則改變了
// 之前在AdminTab 時用$this->edit=true;
$this->addRowAction('edit');
// 之前在AdminTab 時用$this->delete=true;
$this->addRowAction('delete');

也可以利用bulk_action來設定批量的移除
$this->bulk_actions = array(
 'delete' => array(
  'text' => $this->l('Delete selected'), 
  'confirm' => $this->l('Delete selected items?'))
 );
加入批量的效果

0 回應:

Post a Comment