From 7919942bb2a55c934b9cb89bb9e05c1752dd6893 Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Fri, 11 Aug 2017 15:28:44 +0200 Subject: [PATCH] Gestion du BAT --- www/modules/addfileorder/addfileorder.php | 8 ++-- .../admin/AdminOrderPreferencesController.php | 28 ++++++++++++++ .../front/OrderDetailController.php | 33 +++++++++++++++- .../modules/addfileorder/addfileorder.php | 37 ++++++++++++++++++ .../views/templates/hook/addfileorder.tpl | 38 +++++++++++++++++++ www/themes/chocolatdemariage/order-detail.tpl | 2 +- 6 files changed, 140 insertions(+), 6 deletions(-) create mode 100644 www/override/controllers/admin/AdminOrderPreferencesController.php create mode 100644 www/override/modules/addfileorder/addfileorder.php create mode 100644 www/themes/chocolatdemariage/modules/addfileorder/views/templates/hook/addfileorder.tpl diff --git a/www/modules/addfileorder/addfileorder.php b/www/modules/addfileorder/addfileorder.php index 506e9bd3..fe89e272 100644 --- a/www/modules/addfileorder/addfileorder.php +++ b/www/modules/addfileorder/addfileorder.php @@ -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; diff --git a/www/override/controllers/admin/AdminOrderPreferencesController.php b/www/override/controllers/admin/AdminOrderPreferencesController.php new file mode 100644 index 00000000..e5641f58 --- /dev/null +++ b/www/override/controllers/admin/AdminOrderPreferencesController.php @@ -0,0 +1,28 @@ +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')), + ); + } +} diff --git a/www/override/controllers/front/OrderDetailController.php b/www/override/controllers/front/OrderDetailController.php index f82de066..cbac7bd0 100644 --- a/www/override/controllers/front/OrderDetailController.php +++ b/www/override/controllers/front/OrderDetailController.php @@ -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); + } + } + } + } } diff --git a/www/override/modules/addfileorder/addfileorder.php b/www/override/modules/addfileorder/addfileorder.php new file mode 100644 index 00000000..95c50725 --- /dev/null +++ b/www/override/modules/addfileorder/addfileorder.php @@ -0,0 +1,37 @@ +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'); + } +} \ No newline at end of file diff --git a/www/themes/chocolatdemariage/modules/addfileorder/views/templates/hook/addfileorder.tpl b/www/themes/chocolatdemariage/modules/addfileorder/views/templates/hook/addfileorder.tpl new file mode 100644 index 00000000..0bd633ba --- /dev/null +++ b/www/themes/chocolatdemariage/modules/addfileorder/views/templates/hook/addfileorder.tpl @@ -0,0 +1,38 @@ +
+
+
+ +
+ {if $dirExist} + {foreach from=$files item=file} +
+ +
+ {/foreach} +
+ {else} +
+
+
+ {l s='Aucun document ajouté à votre commande' mod='addfilesorder'} +
+
+
+ {/if} + + {if $files|@count > 0 && $isBatsend && !$isBatvalidate} +
+
+ + +
+
+ {/if} + + {if $isBatvalidate} +
{l s='B.A.T. Validé'}
+ {/if} +
+
\ No newline at end of file diff --git a/www/themes/chocolatdemariage/order-detail.tpl b/www/themes/chocolatdemariage/order-detail.tpl index c0e39fcb..fe9b75fb 100644 --- a/www/themes/chocolatdemariage/order-detail.tpl +++ b/www/themes/chocolatdemariage/order-detail.tpl @@ -185,7 +185,7 @@
{hook h='displayOrderDetail' mod='addfileorder'}
- + {if !$is_guest}
{/if}