diff --git a/adm/themes/default/template/controllers/orders/helpers/view/view.tpl b/adm/themes/default/template/controllers/orders/helpers/view/view.tpl index b50861b..0cb63b1 100755 --- a/adm/themes/default/template/controllers/orders/helpers/view/view.tpl +++ b/adm/themes/default/template/controllers/orders/helpers/view/view.tpl @@ -170,15 +170,21 @@ {l s='Partial refund'} {/if} - {if !$order->isSynchIntoErp()} - - - {l s='Synchroniser dans Odoo'} - + {if $erp_enabled} + {if !$order->isSynchIntoErp()} + + + {l s='Synchroniser dans Odoo'} + + {else} + + + {l s='Synchronisée'} + + {/if} {else} - - {l s='Synchronisée'} + {l s='Synchronisation désactivée'} {/if} diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 04d8dba..e677228 100755 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -1522,37 +1522,43 @@ class AdminOrdersControllerCore extends AdminController } } elseif (Tools::getValue('syncherp') == 1) { - $id_order = Tools::getValue('id_order', false); - if ($id_order) { - $order = new Order((int)$id_order); - if (!$order->isSynchIntoErp()) { + if (!defined('ERP_ENABLED') || !ERP_ENABLED) { + $this->errors[] = Tools::displayError('La synchro avec Odoo est actuellement désactivée.'); + } + else { - if ($order->getIdErp() === 1) { - $order->deletIdErpIfNotSynch(); - } + $id_order = Tools::getValue('id_order', false); + if ($id_order) { + $order = new Order((int)$id_order); + if (!$order->isSynchIntoErp()) { - $params['id_order'] = $order->id; - $params['newOrderStatus'] = new StdClass(); - - if ($order->hasStatusInHistory(2)) { - $params['newOrderStatus']->id = 2; - } elseif ($order->hasStatusInHistory(10)) { - $params['newOrderStatus']->id = 10; - } elseif ($order->hasStatusInHistory(1)) { - $params['newOrderStatus']->id = 1; - } - - if (!empty($params['newOrderStatus']->id)) { - $erporder = Module::getInstanceByName('erporder'); - if ($erporder) { - return $erporder->hookActionOrderStatusPostUpdate($params); + if ($order->getIdErp() === 1) { + $order->deletIdErpIfNotSynch(); } - } else { - $sql = 'SELECT `name` FROM `'._DB_PREFIX_.'order_state_lang` WHERE `id_order_state` IN (1,2,10) AND id_lang = 1'; - $rows = Db::getInstance()->executeS($sql); - $txt .= implode('", "', array_column($rows, 'name')); - $this->errors[] = Tools::displayError('Pas de synchro possible, la commande doit avoir eu l\'un des status suivants : "'.$txt.'"'); + $params['id_order'] = $order->id; + $params['newOrderStatus'] = new StdClass(); + + if ($order->hasStatusInHistory(2)) { + $params['newOrderStatus']->id = 2; + } elseif ($order->hasStatusInHistory(10)) { + $params['newOrderStatus']->id = 10; + } elseif ($order->hasStatusInHistory(1)) { + $params['newOrderStatus']->id = 1; + } + + if (!empty($params['newOrderStatus']->id)) { + $erporder = Module::getInstanceByName('erporder'); + if ($erporder) { + return $erporder->hookActionOrderStatusPostUpdate($params); + } + } else { + $sql = 'SELECT `name` FROM `'._DB_PREFIX_.'order_state_lang` WHERE `id_order_state` IN (1,2,10) AND id_lang = 1'; + $rows = Db::getInstance()->executeS($sql); + + $txt .= implode('", "', array_column($rows, 'name')); + $this->errors[] = Tools::displayError('Pas de synchro possible, la commande doit avoir eu l\'un des status suivants : "'.$txt.'"'); + } } } } @@ -1759,6 +1765,7 @@ class AdminOrdersControllerCore extends AdminController // Smarty assign $this->tpl_view_vars = array( + 'erp_enabled' => (defined('ERP_ENABLED') && ERP_ENABLED)?true:false, 'order' => $order, 'cart' => new Cart($order->id_cart), 'customer' => $customer,