2017-04-06 11 views
1

我正在做的PrestaShop 1.6插件,在那裏我可以配置通過的costumers折扣顯示客戶的名字,我見下表:的Prestashop:內連接列表中的

create table ps_discountbycustomer 
(
    id_discountbycustomer int not null auto_increment 
     primary key, 
    id_customer int not null, 
    date_start datetime not null, 
    date_end datetime not null, 
    use_percentage bit not null, 
    percentage_order float not null, 
    percentage_shipping float not null, 
    value_order float not null, 
    value_shipping float not null 
); 

我的模塊列表: enter image description here

我如何讓我的控制器類:

class AdminDiscountbycustomerController extends AdminController 
{ 

    public function __construct() 
    { 
     $this->bootstrap = true; 
     $this->table = 'discountbycustomer'; 
     $this->className = 'DiscountbycustomerModel'; 
     $this->identifier = 'id_discountbycustomer'; 

     parent::__construct(); 

     $this->lang = false; 

     $this->_join = 'INNER JOIN '._DB_PREFIX_.'customer c ON (a.id_customer = c.id_customer)'; 

     // Building the list of records stored within the "test" table 
     $this->fields_list = array(
//   'id_discountbycustomer' => [ 
//    'title' => $this->l('ID'), 
//    'align' => 'center', 
//    'width' => 25 
//   ], 
      'id_customer' => [ 
       'title' => $this->l('Customer'), 
       'width' => 'auto' 
      ], 
      'date_start' => [ 
       'title' => $this->l('Starts'), 
       'width' => 'auto', 
       'type' => 'date' 
      ], 
      'date_end' => [ 
       'title' => $this->l('Ends'), 
       'width' => 'auto', 
       'type' => 'date' 
      ], 
      'use_percentage' => [ 
       'title' => $this->l('Use Percentage'), 
       'active' => 'use_percentage', 
       'align' => 'text-center', 
       'class' => 'fixed-width-sm' 
      ], 
      'percentage_order' => [ 
       'title' => $this->l('Order %'), 
       'width' => 'auto', 
       'type' => 'float' 
      ], 
      'percentage_shipping' => [ 
       'title' => $this->l('Shipping %'), 
       'width' => 'auto', 
       'type' => 'float' 
      ], 
      'value_order' => [ 
       'title' => $this->l('Order %'), 
       'width' => 'auto', 
       'type' => 'float' 
      ], 
      'value_shipping' => [ 
       'title' => $this->l('Shipping %'), 
       'width' => 'auto', 
       'type' => 'float' 
      ], 
     ); 

     // This adds a multiple deletion button 
     $this->bulk_actions = array(
      'delete' => array(
       'text' => $this->l('Delete selected'), 
       'confirm' => $this->l('Delete selected items?') 
      ) 
     ); 

     parent::__construct(); 
    } 
} 

我的問題是,我不知道我怎麼能在加負荷消費列數組,以便我可以獲取列表中顯示的客戶名稱。

我該怎麼做?我正在使用PrestaShop 1.6.1.12。 感謝您的幫助

回答

2

您需要添加選擇到Concat的名字

$this->_select = 'a.*, CONCAT(c.`firstname`, \' \', c.`lastname`) AS `customer`'; 

然後,而不是場id_customer利用客戶:

'customer' => [ 
    'title' => $this->l('Customer'), 
    'width' => 'auto' 
], 
+0

謝謝!工作得很好! –

1

這很簡單,你只要必須添加一個回調像這樣的列

... 
    'id_customer' => [ 
      'title' => $this->l('Customer'), 
      'width' => 'auto', 
      'callback' => 'getCustomerName' 
     ], 
    ... 

    // Then add this function in the same controller 
    public function getCustomerName($id) { 
    if (!empty($id)) { 
     $customer = new Customer($id); 
     if(Validate::isLoadedObject($customer)) { 
      return $customer->firstname.' '.$customer->lastname; 
     } 
    } 
    return ''; 
    } 
+0

謝謝!這個解決方案有效 –