Skip to content
This repository has been archived by the owner on Mar 17, 2020. It is now read-only.

[*] MO mondialrelay : taking account weight coefficiency #12

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
274 changes: 137 additions & 137 deletions AdminMondialRelay.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -30,141 +30,141 @@

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);
}

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');
}

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->displayOrdersTable();
$this->displayhistoriqueForm();
}
}
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);
}

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');
}

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->displayOrdersTable();
$this->displayhistoriqueForm();
}
}
}
Loading