* @copyright 2007-2015 PrestaShop SA * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ require_once(dirname(__FILE__).'/classes/MRCreateTickets.php'); require_once(dirname(__FILE__).'/mondialrelay.php'); class AdminMondialRelay extends AdminTab { private $mondialrelay = null; public $post_errors = array(); public function __construct() { $this->mondialrelay = new MondialRelay(); $this->table = 'mr_selected'; parent::__construct(); $this->context = Context::getContext(); $datas = array( 'display_header' => true, 'display_header_javascript' => true, 'display_footer' => true, ); $this->context->smarty->assign($datas); } /** * @Override * display orders by sales */ private function displaySalesTable() { global $currentIndex; $mr_carriers = array(); foreach (Db::getInstance()->executeS(' SELECT `id_carrier` FROM `'._DB_PREFIX_.'mr_method` ') as $row) { $mr_carriers[] = (int) $row['id_carrier']; } $details = MondialRelay::getAccountDetail(); $id_sales = array(); foreach (Db::getInstance()->executeS(' SELECT DISTINCT p.`id_sale` FROM `'._DB_PREFIX_.'privatesale` p LEFT JOIN `'._DB_PREFIX_.'product_ps_cache` ppc ON ppc.`id_sale` = p.`id_sale` LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON od.`product_id` = ppc.`id_product` LEFT JOIN `'._DB_PREFIX_.'order_state_current` ost ON ost.`id_order` = od.`id_order` LEFT JOIN `'._DB_PREFIX_.'orders` o ON o.`id_order` = od.`id_order` WHERE ost.`id_order_state` = '.(int) $details['MR_ORDER_STATE'].' AND o.`id_carrier` IN ('.implode(', ', $mr_carriers).') ') as $row){ $id_sales[] = (int) $row['id_sale']; } $sales = Db::getInstance()->executeS(' SELECT p.`id_sale`, cl.`name` FROM `'._DB_PREFIX_.'privatesale` p LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON cl.`id_category` = p.`id_category` WHERE cl.id_lang = '.(int) $this->context->language->id.' AND p.`id_sale` IN ('.implode(', ', $id_sales).') '); $html = '
'.$this->l('Liste des ventes').'
'; echo $html; } private function displayOrdersTable() { $order_state = new OrderState((int)(Configuration::get('MONDIAL_RELAY_ORDER_STATE')), $this->context->language->id); $orders = MondialRelay::getOrders(array(), MondialRelay::NO_FILTER, $this->mondialrelay->account_shop['MR_WEIGHT_COEFFICIENT']); // Simulate a ticket generation $MRCreateTicket = new MRCreateTickets(array( 'orderIdList' => null, 'totalOrder' => null, 'weightList' => null ), $this->mondialrelay ); if (is_array($orders) && count($orders)) foreach ($orders as &$order) { $order['display_total_price'] = Tools::displayPrice($order['total'], new Currency($order['id_currency'])); $order['display_shipping_price'] = Tools::displayPrice($order['shipping'], new Currency($order['id_currency'])); if (version_compare(_PS_VERSION_, '1.5.5', '<')) $order['display_date'] = Tools::displayDate($order['date'], $this->context->language->id); else $order['display_date'] = Tools::displayDate($order['date']); $order['weight'] = (!empty($order['mr_weight']) && $order['mr_weight'] > 0) ? $order['mr_weight'] : $order['order_weight']; } $controller = (_PS_VERSION_ < '1.5') ? 'AdminContact' : 'AdminStores'; $this->context->smarty->assign(array( 'MR_token_admin_module' => Tools::getAdminToken('AdminModules'.(int)(Tab::getIdFromClassName('AdminModules')).(int)$this->context->employee->id), 'MR_token_admin_contact' => array( 'controller_name' => $controller, 'token' => Tools::getAdminToken($controller.(int)(Tab::getIdFromClassName($controller)).(int)$this->context->employee->id)), 'MR_token_admin_orders' => Tools::getAdminToken('AdminOrders'.(int)(Tab::getIdFromClassName('AdminOrders')).(int)$this->context->employee->id), 'MR_order_state_name' => $order_state->name, 'MR_orders' => $orders, 'MR_PS_IMG_DIR_' => _PS_IMG_DIR_, 'MR_errors_type' => $MRCreateTicket->checkPreValidation()) ); unset($order_state); echo $this->mondialrelay->fetchTemplate('/views/templates/admin/', 'generate_tickets'); } public function displayhistoriqueForm() { $query = 'SELECT * FROM `'._DB_PREFIX_.'mr_history` ORDER BY `id` DESC ;'; $history = Db::getInstance()->executeS($query); foreach ($history as &$item) $item['url_10x15'] = str_replace('format=A4', 'format=10x15', $item['url_a4']); $this->context->smarty->assign(array( 'MR_histories' => $history) ); echo $this->mondialrelay->fetchTemplate('/views/templates/admin/', 'history'); } public function displaySettings($post_action) { $curr_order_state = new OrderState((int)$this->mondialrelay->account_shop['MR_ORDER_STATE']); $order_state = array( 'id_order_state' => $this->mondialrelay->account_shop['MR_ORDER_STATE'], 'name' => $curr_order_state->name[$this->context->language->id] ); $this->context->smarty->assign(array( 'MR_token_admin_mondialrelay' => Tools::getAdminToken('AdminMondialRelay'.(int)(Tab::getIdFromClassName('AdminMondialRelay')).(int)$this->context->employee->id), 'MR_account_set' => MondialRelay::isAccountSet(), 'MR_order_state' => $order_state, 'MR_orders_states_list' => OrderState::getOrderStates($this->context->language->id), 'MR_form_action' => $post_action, 'MR_error_list' => $this->post_errors )); echo $this->mondialrelay->fetchTemplate('/views/templates/admin/', 'settings'); } public function postProcess() { $post_action = array( 'type' => Tools::getValue('MR_action_name'), 'message_success' => $this->l('Action Succeed'), 'had_errors' => false ); parent::postProcess(); if (Tools::isSubmit('submit_order_state')) if (($order_state = (int)Tools::getValue('id_order_state'))) { $this->mondialrelay->account_shop['MR_ORDER_STATE'] = $order_state; if ($this->mondialrelay->updateAccountShop()) $post_action['message_success'] = $this->l('Order State has been updated'); else $this->post_errors[] = $this->l('Cannot Update the account shop'); } /* * @Override sale submit process */ if (Tools::isSubmit('mr_submitSale') && Tools::getValue('mr_id_sale')){ $id_sale = (int) Tools::getValue('mr_id_sale'); $this->processShippingSale($id_sale); } if (count($this->post_errors)) $post_action['had_errors'] = true; return $post_action; } public function display() { $post_action = count($_POST) ? $this->postProcess() : null; $this->displaySettings($post_action); if (MondialRelay::isAccountSet() && (int)$this->mondialrelay->account_shop['MR_ORDER_STATE']) { $this->displaySalesTable(); // $this->displayOrdersTable(); // $this->displayhistoriqueForm(); } } /** * @Override */ public function processShippingSale($id_sale){ } }