102 lines
3.1 KiB
PHP
102 lines
3.1 KiB
PHP
<?php
|
|
/*
|
|
*
|
|
* @author Dominik Wójcicki <dominik__w@interia.pl>
|
|
* @copyright 2021 Dominik Wójcicki
|
|
*
|
|
*/
|
|
|
|
use PrestaShop\PrestaShop\Core\Grid\Column\Type\DataColumn;
|
|
use PrestaShop\PrestaShop\Core\Grid\Column\ColumnCollection;
|
|
use Doctrine\DBAL\Query\QueryBuilder;
|
|
|
|
if (!defined('_PS_VERSION_'))
|
|
{
|
|
exit;
|
|
}
|
|
|
|
class OrdersExtraColumns extends Module {
|
|
|
|
public function __construct() {
|
|
$this->name = 'ordersextracolumns';
|
|
$this->tab = 'administration';
|
|
$this->version = '1.0';
|
|
$this->author = 'Dominik Wójcicki';
|
|
$this->need_instance = 0;
|
|
$this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_);
|
|
$this->bootstrap = true;
|
|
parent::__construct();
|
|
$this->displayName = $this->l('Dodatkowe kolumny na liście zamówień');
|
|
$this->description = $this->l('Dodatkowe kolumny na liście zamówień w Back Office');
|
|
$this->confirmUninstall = $this->l('Czy na pewno odinstalować moduł?');
|
|
}
|
|
|
|
public function install()
|
|
{
|
|
Configuration::updateValue('OVERRIDEVIEWS_LIVE_MODE', false);
|
|
if (!parent::install()
|
|
|| !$this -> registerHook ( 'actionOrderGridDefinitionModifier' )
|
|
|| !$this -> registerHook ( 'actionOrderGridQueryBuilderModifier' )
|
|
) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public function uninstall()
|
|
{
|
|
Configuration::deleteByName('OVERRIDEVIEWS_LIVE_MODE');
|
|
return parent::uninstall();
|
|
}
|
|
|
|
public function hookActionOrderGridDefinitionModifier(array $params)
|
|
{
|
|
|
|
/** @var \PrestaShop\PrestaShop\Core\Grid\Definition\GridDefinition */
|
|
$definition = $params['definition'];
|
|
$columns = $definition->getColumns();
|
|
$columns->remove('reference')
|
|
->remove('country_name')
|
|
->remove('new');
|
|
|
|
$filters = $definition->getFilters();
|
|
$filters->remove('reference')
|
|
->remove('country_name')
|
|
->remove('new');
|
|
|
|
|
|
$CarrierColumn = new DataColumn('sposob_dostawy');
|
|
$CarrierColumn->setName($this->trans('Sposób dostawy', [], 'Admin.Global'));
|
|
$CarrierColumn->setOptions([
|
|
'field' => 'sposob_dostawy',
|
|
]);
|
|
|
|
$OrderSourceColumn = new DataColumn('order_source');
|
|
$OrderSourceColumn->setName($this->trans('Źródło zamówienia', [], 'Admin.Global'));
|
|
$OrderSourceColumn->setOptions([
|
|
'field' => 'order_source',
|
|
]);
|
|
|
|
|
|
$columns->addBefore('date_add', $CarrierColumn);
|
|
$columns->addAfter('sposob_dostawy', $OrderSourceColumn);
|
|
|
|
|
|
}
|
|
|
|
|
|
public function hookActionOrderGridQueryBuilderModifier(array $params)
|
|
{
|
|
|
|
$searchQueryBuilder = $params['search_query_builder'];
|
|
$searchQueryBuilder
|
|
->addSelect('o.id_carrier, IF ( o.date_add > \'2023-04-20 19:21:25\', order_source, IF ( module = "x13allegro", "Allegro", "Sklep int." ) ) AS order_source')
|
|
->addSelect('cr.name AS sposob_dostawy')
|
|
->addSelect('CONCAT(LEFT(cu.`firstname`, 50), \' \', cu.`lastname`) AS customer')
|
|
->leftJoin('o', 'ps_carrier', 'cr', 'cr.id_carrier = o.id_carrier')
|
|
;
|
|
|
|
}
|
|
|
|
} |