Я выполнил шаги учебника, чтобы создать модуль для редактирования счетов, а именно: https://blog.floriancourgey.com/2018/04/edit-your-invoices-in-prestashop
Но модуль позволяет обновлять информацию только в полях, которые появляются в одна таблица.
Дело в том, что мне нужно добавить новое поле, которое принадлежит другой таблице и сохраняется в обеих таблицах. Таблица, в которой хранится информация о модуле, - это ps_order_invoice, а таблица, которую я также хочу сохранить, одно поле invoice_number, - это ps_orders.
class AdminCustomInvoicesController extends ModuleAdminController {
public function __construct(){
parent::__construct();
$this->bootstrap = true; // use Bootstrap CSS
$this->table = 'order_invoice'; // SQL table name, will be prefixed with _DB_PREFIX_
$this->identifier = 'id_order_invoice'; // SQL column to be used as primary key
$this->className = 'OrderInvoice'; // PHP class name
$this->allow_export = true; // allow export in CSV, XLS..
$this->_orderBy = 'date_add'; // default SQL ORDER BY
$this->page_header_toolbar_title = 'Invoices'; // toolbar title
$this->_select = 'concat(upper(c.lastname), " ", c.firstname) as customer';
$this->_join = '
JOIN '._DB_PREFIX_.'orders o ON (o.id_order = a.id_orderes)
JOIN '._DB_PREFIX_.'customer c ON (c.id_customer = o.id_customer)
';
$this->fields_list = [
'id_order_invoice' => ['title' => $this->trans('ID', [], 'Admin.Global'),'class' => 'fixed-width-xs'],
'number' => ['title' => $this->trans('Number', [], 'Admin.Global'),'class' => 'fixed-width-xs'],
//I want add this new field(invoice_number) in another table ps_orders
'invoice_number' => ['title' => $this->trans('Invoice Number', [], 'Admin.Global'),'class' => 'fixed-width-xs'],
'date_add' => ['title' => $this->trans('Date', [], 'Admin.Global'), 'type'=>'datetime'],
'customer' => ['title' => $this->trans('Customer', [], 'Admin.Global')],
'total_products_wt' => ['title' => $this->trans('Total products', [], 'Admin.Global'),
'align' => 'text-right',
'type' => 'price',
],
'total_shipping_tax_incl' => ['title' => $this->trans('Total shipping', [], 'Admin.Global'),
'align' => 'text-right',
'type' => 'price',
],
'total_paid_tax_incl' => ['title' => $this->trans('Total paid', [], 'Admin.Global'),
'align' => 'text-right',
'type' => 'price',
],
];
Я также добавил в field_list
$this->fields_form = [
'legend' => ['title' => $this->l('Custom Invoice'),'icon' => 'icon-list-ul'],
'input' => [
['name' => 'date_add','type' => 'datetime','label' => 'Date add',],
['name'=>'number','type'=>'text','required' => true,'label' => 'Number',],
//Here I add new field from ps_orders
['name'=>'invoice_number','type'=>'text','required' => true,'label' => 'Invoice number',],
['name'=>'note','type'=>'textarea','label' => 'Note',],
['name'=>'delivery_number','type'=>'text','label'=>'Delivery number'],
['name'=>'delivery_date','type'=>'datetime','label'=>'Delivery date'],
['name'=>'total_discount_tax_excl','type'=>'text','label'=>'Total amount of discounts (no tax)'],
['name'=>'total_discount_tax_incl','type'=>'text','label'=>'Total amount of discounts (with tax)'],
['name'=>'total_shipping_tax_excl','type'=>'text','label'=>'Total cost of shipping (no tax)'],
['name'=>'total_shipping_tax_incl','type'=>'text','label'=>'Total cost of shipping (with tax)'],
['name'=>'total_products','type'=>'text','label'=>'Total cost of products (no tax)'],
['name'=>'total_products_wt','type'=>'text','label'=>'Total cost of products (with tax)'],
['name'=>'total_wrapping_tax_excl','type'=>'text','label'=>'Total cost of wrapping (no tax)'],
['name'=>'total_wrapping_tax_incl','type'=>'text','label'=>'Total cost of wrapping (with tax)'],
['name'=>'total_paid_tax_excl','type'=>'text','label'=>'Total paid (no tax)'],
['name'=>'total_paid_tax_incl','type'=>'text','label'=>'Total paid (with tax)'],
['name'=>'shop_address','type'=>'textarea','label'=>'Shop address'],
],
'submit' => ['title' => $this->trans('Save', [], 'Admin.Actions'),]
];
Как мне добавить поле invoice_number к этому модулю, чтобы оно обновлялось в таблице ps_orders, когда я помещаю данные и в то же время остальные вещи, которые выполняет модуль?