Gestion du BAT

This commit is contained in:
Michael RICOIS 2017-08-11 15:28:44 +02:00
parent d3b113411b
commit 7919942bb2
6 changed files with 140 additions and 6 deletions

View File

@ -29,7 +29,7 @@ class AddFileOrder extends Module
public function hookDisplayHeader($params)
{
Tools::addCSS($this->_path.'views/css/addfileorder.css', 'all');
Tools::addJS($this->_path.'views/js/addfileorder.js', 'all');
Tools::addJS($this->_path.'views/js/addfileorder.js', 'all');
}
public function hookDisplayAdminOrder($params)
@ -61,7 +61,7 @@ class AddFileOrder extends Module
return $this->display(__FILE__, 'views/templates/admin/addfileorder.tpl');
}
public function hookdisplayOrderDetail($params)
public function hookDisplayOrderDetail($params)
{
$id_order = Tools::getValue('id_order');
@ -107,7 +107,7 @@ class AddFileOrder extends Module
return 0;
}
private function getFileOrderCustomer($orderNumber)
protected function getFileOrderCustomer($orderNumber)
{
$files = array();
if ($this->checkOrderDir($orderNumber)) {
@ -170,7 +170,7 @@ class AddFileOrder extends Module
return false;
}
private function checkOrderDir($orderNumber)
protected function checkOrderDir($orderNumber)
{
if (file_exists(_PS_ROOT_DIR_.'/../files/order_'.(int) $orderNumber) === false) {
return false;

View File

@ -0,0 +1,28 @@
<?php
class AdminOrderPreferencesController extends AdminOrderPreferencesControllerCore
{
public function __construct()
{
parent::__construct();
$this->fields_options['bat'] = array(
'title' => $this->l('Bon A Tirer'),
'icon' => 'icon-gogs',
'fields' => array(
'PS_BATSEND_ID_ORDER_STATE' => array(
'title' => $this->l('Order State ID when merchant add file'),
'validation' => 'isInt',
'cast' => 'intval',
'type' => 'text',
),
'PS_BATVALIDATE_ID_ORDER_STATE' => array(
'title' => $this->l('Order State ID when customer validate'),
'validation' => 'isInt',
'cast' => 'intval',
'type' => 'text',
),
),
'submit' => array('title' => $this->l('Save')),
);
}
}

View File

@ -87,6 +87,37 @@ class OrderDetailController extends OrderDetailControllerCore
}
}
}
}
// Validation du BAT
if (Tools::isSubmit('submitValidateBAT')) {
$id_order = (int)Tools::getValue('id_order');
$order = new Order($id_order);
$new_order_state = Configuration::get('PS_BATVALIDATE_ID_ORDER_STATE');
$order_state = new OrderState($new_order_state);
if (!Validate::isLoadedObject($order_state)) {
$this->errors[] = Tools::displayError('The new order status is invalid.');
} else {
// Check OrderHistory
$orderHistory = $order->getHistory($id_lang);
if (count($history) > 0) {
foreach($orderHistory as $h) {
if ($h['id_order_state'] == $new_order_state) {
$this->errors[] = Tools::displayError('The order has already been assigned this status.');
break;
}
}
}
// Create new OrderHistory
if (count($this->errors) == 0) {
$history = new OrderHistory();
$history->id_order = $order->id;
$history->changeIdOrderState($new_order_state, $order);
$history->add(true);
}
}
}
}
}

View File

@ -0,0 +1,37 @@
<?php
class AddFileOrderOverride extends AddFileOrder
{
public function hookdisplayOrderDetail($params)
{
$id_order = Tools::getValue('id_order');
$id_lang = $this->context->language->id;
$order = new Order($id_order);
$orderHistory = $order->getHistory($id_lang);
$isBatsend = false;
$isBatvalidate = false;
if (count($orderHistory) > 0) {
foreach ($orderHistory as $h) {
if ($h['id_order_state'] == Configuration::get('PS_BATSEND_ID_ORDER_STATE')) {
$isBatsend = true;
}
if ($h['id_order_state'] == Configuration::get('PS_BATVALIDATE_ID_ORDER_STATE')) {
$isBatvalidate = true;
}
}
}
$this->context->smarty->assign(array(
'dirExist' => $this->checkOrderDir($id_order),
'files' => $this->getFileOrderCustomer($id_order),
'isBatsend' => $isBatsend,
'isBatvalidate' => $isBatvalidate,
'batsend_id_order_state' => Configuration::get('PS_BATSEND_ID_ORDER_STATE'),
'batvalidate_id_order_state' => Configuration::get('PS_BATVALIDATE_ID_ORDER_STATE'),
));
return $this->display(__FILE__, 'views/templates/hook/addfileorder.tpl');
}
}

View File

@ -0,0 +1,38 @@
<div class="order-info">
<div class="table-div">
<div class="table-head">
<div class="md8 sm8 hidden-xs hidden-xxs">{l s='Document lié à votre commande' mod='addfilesorder'}</div>
</div>
{if $dirExist}
{foreach from=$files item=file}
<div class="table-row">
<div class="lg4 md4 sm4 xs5 xxs5">
<a href="{$file['download']}">{$file['name']}</a>
</div>
</div>
{/foreach}
<div class="clearfix"></div>
{else}
<div id="add_file_empty">
<div class="table-row">
<div class="lg8 md8 sm7 xs7 xxs7">
{l s='Aucun document ajouté à votre commande' mod='addfilesorder'}
</div>
</div>
</div>
{/if}
{if $files|@count > 0 && $isBatsend && !$isBatvalidate}
<div>
<form name="bat" action="{$link->getPageLink('order-detail')}" method="post">
<input type="hidden" name="id_order" value="{$order->id}" />
<input type="submit" name="submitValidateBAT" value="{l s='Valider votre B.A.T.'}" />
</form>
</div>
{/if}
{if $isBatvalidate}
<div class="alert alert-success">{l s='B.A.T. Validé'}</div>
{/if}
</div>
</div>

View File

@ -185,7 +185,7 @@
</div>
<div>{hook h='displayOrderDetail' mod='addfileorder'}</div>
<!-- Contenu de la commande -->
{if !$is_guest}
<form action="{$link->getPageLink('order-follow', true)|escape:'html':'UTF-8'}" method="post">{/if}