我正在制作一个PrestaShop 1.6插件,我可以根据客户配置折扣,我的表格如下:
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
);
我如何制作我的控制器课程:
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();
}
}
我的问题是,我不知道如何在$this->fields_list
数组中添加costumer列,以便我可以在列表中显示客户名称。
我该怎么做?我正在使用PrestaShop 1.6.1.12。 谢谢你的帮助
答案 0 :(得分:2)
您需要添加select以连接名称
$this->_select = 'a.*, CONCAT(c.`firstname`, \' \', c.`lastname`) AS `customer`';
然后,代替字段id_customer使用customer:
'customer' => [
'title' => $this->l('Customer'),
'width' => 'auto'
],
答案 1 :(得分: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 '';
}