Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save floriancourgey/cb63fd5abd93e1109fcf624a68307403 to your computer and use it in GitHub Desktop.
Save floriancourgey/cb63fd5abd93e1109fcf624a68307403 to your computer and use it in GitHub Desktop.
Edit your invoices in Prestashop 1.7 via a Custom Module & Admin Controller
<?php
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_order)
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'],
'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',
],
];
$this->addRowAction('edit');
$this->addRowAction('details');
$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',],
['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'),]
];
$this->addRowAction('delete');
$this->bulk_actions = [
'delete' => [
'text' => 'Delete',
'icon' => 'icon-power-off'
],
];
}
public function renderForm(){
$invoice = $this->object; // get invoice
$order = $invoice->getOrder(); // get order
$customer = $order->getCustomer(); // get customer
$currency = new Currency($order->id_currency); // get currency
// add some info in an HTML string
$info = '<div class="panel">';
$info .= '<div class="panel-heading"><i class="icon-list-ul"></i> Order informations</div>';
$info .= "Order reference: {$order->reference}<br/>";
$info .= "Customer: {$customer->firstname} {$customer->lastname}<br/>";
$info .= "Total_paid : ".Tools::displayPrice($order->total_paid, $currency)."<br/>";
$info .= "Get total paid : ".Tools::displayPrice($order->getTotalPaid(), $currency)."<br/>";
$info .= "Payment: {$order->payment}<br/>";
$info .= "Order state : {$order->getCurrentOrderState()->name[$this->context->language->id]}";
$info .= '</div>';
// push the HTML to $this->content
$this->content .= $info;
return parent::renderForm();
}
public function access($action, $disable = false){
return true;
}
}
<?php
if (!defined('_PS_VERSION_')) {exit;}
class My_Module extends Module {
public function __construct() {
$this->name = 'my_module';
$this->tab = 'administration';
$this->version = '1.0.0';
$this->author = 'Florian Courgey';
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('PrestaShop Module by FC');
$this->description = $this->l('Improve your store by [...]');
$this->ps_versions_compliancy = ['min' => '1.7', 'max' => _PS_VERSION_];
}
}
@floriancourgey
Copy link
Author

floriancourgey commented Jul 7, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment