Update fields availability and Remove Order Status field
This commit is contained in:
@@ -38,7 +38,6 @@
|
||||
var id_lang = '';
|
||||
//var txt_show_carts = '{l s='Show carts and orders for this customer.' js=1}';
|
||||
//var txt_hide_carts = '{l s='Hide carts and orders for this customer.' js=1}';
|
||||
var defaults_order_state = new Array();
|
||||
var customization_errors = false;
|
||||
var pic_dir = '{$pic_dir}';
|
||||
var currency_format = 5;
|
||||
@@ -46,9 +45,6 @@
|
||||
var currency_blank = false;
|
||||
var priceDisplayPrecision = {$smarty.const._PS_PRICE_DISPLAY_PRECISION_|intval};
|
||||
|
||||
{foreach from=$defaults_order_state key='module' item='id_order_state'}
|
||||
defaults_order_state['{$module}'] = '{$id_order_state}';
|
||||
{/foreach}
|
||||
$(document).ready(function() {
|
||||
|
||||
$('#customer').typeWatch({
|
||||
@@ -63,12 +59,6 @@
|
||||
wait: 750,
|
||||
callback: function(){ searchProducts(); }
|
||||
});
|
||||
$('#payment_module_name').change(function() {
|
||||
var id_order_state = defaults_order_state[this.value];
|
||||
if (typeof(id_order_state) == 'undefined')
|
||||
id_order_state = defaults_order_state['other'];
|
||||
$('#id_order_state').val(id_order_state);
|
||||
});
|
||||
$("#id_address_delivery").change(function() {
|
||||
updateAddresses();
|
||||
});
|
||||
@@ -674,14 +664,36 @@
|
||||
$(cart_row).find('.cart_line_total_price').html(data.total_price);
|
||||
}
|
||||
|
||||
function updateCartSummaryData(summaryData) {
|
||||
function updateCartSummaryData(jsonSummary) {
|
||||
$('#total_rooms').html(formatCurrency(parseFloat(jsonSummary.summary.total_rooms + jsonSummary.summary.total_extra_demands + jsonSummary.summary.total_additional_services + jsonSummary.summary.total_additional_services_auto_add), currency_format, currency_sign, currency_blank));
|
||||
$('#total_vouchers').html(formatCurrency(parseFloat(summaryData.summary.total_discounts_tax_exc), currency_format, currency_sign, currency_blank));
|
||||
$('#total_vouchers').html(formatCurrency(parseFloat(jsonSummary.summary.total_discounts_tax_exc), currency_format, currency_sign, currency_blank));
|
||||
$('#total_convenience_fees').html(formatCurrency(parseFloat(jsonSummary.summary.convenience_fee), currency_format, currency_sign, currency_blank));
|
||||
$('#total_without_taxes').html(formatCurrency(parseFloat(jsonSummary.summary.total_price_without_tax - jsonSummary.summary.convenience_fee), currency_format, currency_sign, currency_blank));
|
||||
// $('#total_service_products').html(formatCurrency(parseFloat(jsonSummary.summary.total_service_products), currency_format, currency_sign, currency_blank));
|
||||
$('#total_taxes').html(formatCurrency(parseFloat(summaryData.summary.total_tax), currency_format, currency_sign, currency_blank));
|
||||
$('#total_with_taxes').html(formatCurrency(parseFloat(summaryData.summary.total_price), currency_format, currency_sign, currency_blank));
|
||||
$('#total_taxes').html(formatCurrency(parseFloat(jsonSummary.summary.total_tax), currency_format, currency_sign, currency_blank));
|
||||
$('#total_with_taxes').html(formatCurrency(parseFloat(jsonSummary.summary.total_price), currency_format, currency_sign, currency_blank));
|
||||
|
||||
$('#payment_amount').val(jsonSummary.summary.total_price);
|
||||
if (jsonSummary.summary.is_advance_payment_active) {
|
||||
$('#advance_payment_amount').html(formatCurrency(parseFloat(jsonSummary.summary.advance_payment_amount_ti), currency_format, currency_sign, currency_blank));
|
||||
$('#advance_payment_amount_block').show();
|
||||
} else {
|
||||
$('#advance_payment_amount_block').hide();
|
||||
}
|
||||
|
||||
// toggle payment fields
|
||||
let isFreeOrder = false;
|
||||
if (jsonSummary.summary.is_advance_payment_active && jsonSummary.summary.advance_payment_amount_with_tax == 0) {
|
||||
isFreeOrder = true;
|
||||
} else if (jsonSummary.summary.total_price == 0) {
|
||||
isFreeOrder = true;
|
||||
}
|
||||
|
||||
if (isFreeOrder) {
|
||||
$('#send_email_to_customer, [name="is_full_payment"], #payment_amount, #payment_type, #payment_module_name, #payment_transaction_id').closest('.form-group').hide(200);
|
||||
} else {
|
||||
$('#send_email_to_customer, [name="is_full_payment"], #payment_amount, #payment_type, #payment_module_name, #payment_transaction_id').closest('.form-group').show(200);
|
||||
}
|
||||
}
|
||||
|
||||
function displayQtyInStock(id)
|
||||
@@ -1609,9 +1621,19 @@
|
||||
|
||||
$(document).on('change', 'input[name="is_full_payment"]', function() {
|
||||
if (parseInt($('input[name="is_full_payment"]:checked').val())) {
|
||||
$('#payment_amount').closest('.form-group').hide(200);
|
||||
$('#payment_amount').attr('disabled', true);
|
||||
} else {
|
||||
$('#payment_amount').closest('.form-group').show(200);
|
||||
$('#payment_amount').attr('disabled', false);
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on('keyup', '#payment_amount', function() {
|
||||
let paymentAmount = parseFloat($('#payment_amount').val().trim());
|
||||
|
||||
if (paymentAmount != 0) {
|
||||
$('#payment_type, #payment_transaction_id').closest('.form-group').show(200);
|
||||
} else {
|
||||
$('#payment_type, #payment_transaction_id').closest('.form-group').hide(200);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -2102,7 +2124,7 @@
|
||||
<textarea name="order_message" id="order_message" rows="3" cols="45"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="form-group" {if $order_total <= 0}style="display: none;"{/if}>
|
||||
{if !$PS_CATALOG_MODE}
|
||||
<div class="col-lg-9 col-lg-offset-3">
|
||||
<a href="javascript:void(0);" id="send_email_to_customer" class="btn btn-default">
|
||||
@@ -2116,7 +2138,50 @@
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="form-group">
|
||||
{if isset($smarty.post.is_full_payment)}
|
||||
{assign var=is_full_payment value=((bool) $smarty.post.is_full_payment)}
|
||||
{else}
|
||||
{assign var=is_full_payment value=true}
|
||||
{/if}
|
||||
<div class="form-group" {if $order_total <= 0}style="display: none;"{/if}>
|
||||
<label class="control-label col-lg-3">{l s="Full payment"}</label>
|
||||
<div class="col-lg-9">
|
||||
<span class="switch prestashop-switch fixed-width-lg">
|
||||
<input type="radio" name="is_full_payment" id="is_full_payment_on" value="1" {if $is_full_payment}checked="checked"{/if}>
|
||||
<label for="is_full_payment_on">{l s="Yes"}</label>
|
||||
<input type="radio" name="is_full_payment" id="is_full_payment_off" value="0" {if !$is_full_payment}checked="checked"{/if}>
|
||||
<label for="is_full_payment_off">{l s="No"}</label>
|
||||
<a class="slide-button btn"></a>
|
||||
</span>
|
||||
<p class="help-block">{l s='Keep this option enabled for full payment and disable it to take partial payment of the order.'}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group" {if $order_total <= 0}style="display: none;"{/if}>
|
||||
<label class="control-label required col-lg-3">{l s='Payment amount'}</label>
|
||||
<div class="col-lg-9">
|
||||
<div class="input-group fixed-width-xxl">
|
||||
<span class="input-group-addon">{$currency->sign}</span>
|
||||
<input type="text" name="payment_amount" id="payment_amount" value="{if isset($smarty.post.payment_amount)}{$smarty.post.payment_amount}{elseif $is_full_payment}{$order_total}{/if}" {if $is_full_payment}disabled{/if} />
|
||||
</div>
|
||||
<p class="help-block" id="advance_payment_amount_block" {if isset($is_advance_payment_active) && $is_advance_payment_active}style="display: block;"{else}style="display: none;"{/if}>
|
||||
<span>{l s='Advance payment amount: '}</span>
|
||||
<span id="advance_payment_amount">{displayPrice price=$advance_payment_amount_ti currency=$currency->id}</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group" {if $order_total <= 0}style="display: none;"{/if}>
|
||||
<label class="control-label col-lg-3">{l s='Payment source'}</label>
|
||||
<div class="col-lg-9">
|
||||
<select class="fixed-width-xxl" name="payment_type" id="payment_type">
|
||||
{foreach from=$payment_types item=payment_type}
|
||||
<option value="{$payment_type.value}" {if isset($smarty.post.payment_type) && $payment_type.value == $smarty.post.payment_type}selected="selected"{/if}>
|
||||
{$payment_type.name}
|
||||
</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group" {if $order_total <= 0}style="display: none;"{/if}>
|
||||
<label class="control-label col-lg-3 required">{l s='Payment method'}</label>
|
||||
<div class="col-lg-9">
|
||||
<input name="payment_module_name" id="payment_module_name" list="payment_module_name_list" class="form-control fixed-width-xxl" {if isset($smarty.post.payment_module_name) && $smarty.post.payment_module_name}value="{$smarty.post.payment_module_name}"{/if}>
|
||||
@@ -2130,60 +2195,12 @@
|
||||
</datalist>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="control-label col-lg-3">{l s='Payment source'}</label>
|
||||
<div class="col-lg-9">
|
||||
<select class="fixed-width-xxl" name="payment_type" id="payment_type">
|
||||
{foreach from=$payment_types item=payment_type}
|
||||
<option value="{$payment_type.value}" {if isset($smarty.post.payment_type) && $payment_type.value == $smarty.post.payment_type}selected="selected"{/if}>
|
||||
{$payment_type.name}
|
||||
</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="form-group" {if $order_total <= 0}style="display: none;"{/if}>
|
||||
<label class="control-label col-lg-3">{l s='Transaction ID'}</label>
|
||||
<div class="col-lg-9">
|
||||
<input type="text" class="fixed-width-xxl" name="payment_transaction_id" id="payment_transaction_id" value="{if isset($smarty.post.payment_transaction_id)}{$smarty.post.payment_transaction_id}{/if}" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="control-label col-lg-3">{l s="Full payment"}</label>
|
||||
<div class="col-lg-9">
|
||||
<span class="switch prestashop-switch fixed-width-lg">
|
||||
<input type="radio" name="is_full_payment" id="is_full_payment_on" value="1" {if (isset($smarty.post.is_full_payment) && $smarty.post.is_full_payment == '1') || !isset($smarty.post.is_full_payment)}checked="checked"{/if}>
|
||||
<label for="is_full_payment_on">{l s="Yes"}</label>
|
||||
<input type="radio" name="is_full_payment" id="is_full_payment_off" value="0" {if isset($smarty.post.is_full_payment) && $smarty.post.is_full_payment == '0'}checked="checked"{/if}>
|
||||
<label for="is_full_payment_off">{l s="No"}</label>
|
||||
<a class="slide-button btn"></a>
|
||||
</span>
|
||||
<p class="help-block">{l s='Keep this option enabled for full payment and disable it to take partial payment of the order.'}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group" {if (isset($smarty.post.is_full_payment) && $smarty.post.is_full_payment == '1') || !isset($smarty.post.is_full_payment)}style="display: none;"{/if}>
|
||||
<label class="control-label required col-lg-3">{l s='Payment amount'}</label>
|
||||
<div class="col-lg-9">
|
||||
<div class="input-group fixed-width-xxl">
|
||||
<span class="input-group-addon">{$currency->sign}</span>
|
||||
<input type="text" name="payment_amount" id="payment_amount" value="{if isset($smarty.post.payment_amount)}{$smarty.post.payment_amount}{/if}" />
|
||||
</div>
|
||||
<p class="help-block" id="advance_payment_amount_block" style="display: none;">
|
||||
<span>{l s='Advance payment amount: '}</span>
|
||||
<span id="advance_payment_amount"></span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="control-label col-lg-3">{l s='Order status'}</label>
|
||||
<div class="col-lg-9">
|
||||
<select class="fixed-width-xxl" name="id_order_state" id="id_order_state">
|
||||
{foreach from=$order_states item='order_state'}
|
||||
<option value="{$order_state.id_order_state}" {if isset($smarty.post.id_order_state) && $order_state.id_order_state == $smarty.post.id_order_state}selected="selected"{/if}>{$order_state.name}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-lg-9 col-lg-offset-3">
|
||||
<button type="submit" name="submitAddOrder" class="btn btn-default" />
|
||||
|
||||
@@ -302,6 +302,14 @@ class AdminOrdersControllerCore extends AdminController
|
||||
$this->context->smarty->assign('cart_normal_data', $normalCartProduct);
|
||||
}
|
||||
|
||||
$objHotelAdvancedPayment = new HotelAdvancedPayment();
|
||||
$this->context->smarty->assign(array(
|
||||
'order_total' => $cart->getOrderTotal(true),
|
||||
'is_advance_payment_active' => $objHotelAdvancedPayment->isAdvancePaymentAvailableForCurrentCart(),
|
||||
'advance_payment_amount_te' => $cart->getOrderTotal(false, Cart::ADVANCE_PAYMENT),
|
||||
'advance_payment_amount_ti' => $cart->getOrderTotal(true, Cart::ADVANCE_PAYMENT),
|
||||
));
|
||||
|
||||
if (empty($cart_detail_data) && empty($normalCartProduct)) {
|
||||
// if no rooms added in the cart and user visits add order page then redirect to BOOK NOW page
|
||||
Tools::redirectAdmin($this->context->link->getAdminLink('AdminHotelRoomsBooking'));
|
||||
@@ -314,9 +322,6 @@ class AdminOrdersControllerCore extends AdminController
|
||||
unset($this->toolbar_btn['save']);
|
||||
$this->addJqueryPlugin(array('autocomplete', 'fancybox', 'typewatch'));
|
||||
|
||||
$defaults_order_state = array(
|
||||
'awaiting_payment' => (int)Configuration::get('PS_OS_AWAITING_PAYMENT'),
|
||||
'other' => (int)Configuration::get('PS_OS_PAYMENT_ACCEPTED'));
|
||||
$payment_modules = array();
|
||||
foreach (PaymentModule::getInstalledPaymentModules() as $p_module) {
|
||||
$payment_modules[] = Module::getInstanceById((int)$p_module['id_module']);
|
||||
@@ -342,8 +347,6 @@ class AdminOrdersControllerCore extends AdminController
|
||||
'langs' => Language::getLanguages(true, Context::getContext()->shop->id),
|
||||
'payment_modules' => $payment_modules,
|
||||
'payment_types' => $paymentTypes,
|
||||
'order_states' => OrderState::getOrderStates((int)Context::getContext()->language->id),
|
||||
'defaults_order_state' => $defaults_order_state,
|
||||
'show_toolbar' => $this->show_toolbar,
|
||||
'toolbar_btn' => $this->toolbar_btn,
|
||||
'toolbar_scroll' => $this->toolbar_scroll,
|
||||
@@ -954,127 +957,151 @@ class AdminOrdersControllerCore extends AdminController
|
||||
} else {
|
||||
$this->errors[] = Tools::displayError('The invoice for edit note was unable to load. ');
|
||||
}
|
||||
} elseif (Tools::isSubmit('submitAddOrder')
|
||||
&& ($id_cart = Tools::getValue('id_cart'))
|
||||
&& ($id_order_state = Tools::getValue('id_order_state'))
|
||||
) {
|
||||
} elseif (Tools::isSubmit('submitAddOrder') && ($id_cart = Tools::getValue('id_cart'))) {
|
||||
if ($this->tabAccess['edit'] === '1') {
|
||||
$moduleName = trim(Tools::getValue('payment_module_name'));
|
||||
$paymentType = Tools::getValue('payment_type');
|
||||
$paymentTransactionId = trim(Tools::getValue('payment_transaction_id'));
|
||||
$isFullPayment = Tools::getValue('is_full_payment');
|
||||
$paymentAmount = trim(Tools::getValue('payment_amount'));
|
||||
|
||||
if (!$moduleName) {
|
||||
$this->errors[] = Tools::displayError('Please enter Payment method.');
|
||||
} elseif ($moduleName && !Validate::isGenericName($moduleName)) {
|
||||
$this->errors[] = Tools::displayError('Payment method is invalid. Please enter a valid payment method.');
|
||||
}
|
||||
|
||||
if (!$paymentType) {
|
||||
$this->errors[] = Tools::displayError('Please select a Payment source.');
|
||||
} elseif ($paymentType && !Validate::isUnsignedInt($paymentType)) {
|
||||
$this->errors[] = Tools::displayError('Payment source is invalid. Please select payment source.');
|
||||
}
|
||||
|
||||
if ($paymentTransactionId && !Validate::isString($paymentTransactionId)) {
|
||||
$this->errors[] = Tools::displayError('Payment amount is invalid. Please enter correct amount.');
|
||||
}
|
||||
|
||||
if (!$isFullPayment) {
|
||||
if ($paymentAmount == '') {
|
||||
$this->errors[] = Tools::displayError('Please enter valid Payment amount of the order.');
|
||||
} elseif ($paymentAmount && !Validate::isPrice($paymentAmount)) {
|
||||
$this->errors[] = Tools::displayError('Payment amount is invalid. Please enter correct amount.');
|
||||
}
|
||||
}
|
||||
|
||||
if (!count($this->errors)) {
|
||||
$payment_module = new BoOrder();
|
||||
$payment_module->displayName = $moduleName;
|
||||
$payment_module->payment_type = $paymentType;
|
||||
|
||||
$cart = new Cart((int)$id_cart);
|
||||
Context::getContext()->currency = new Currency((int)$cart->id_currency);
|
||||
Context::getContext()->customer = new Customer((int)$cart->id_customer);
|
||||
|
||||
$bad_delivery = false;
|
||||
if (($bad_delivery = (bool)!Address::isCountryActiveById((int)$cart->id_address_delivery))
|
||||
|| !Address::isCountryActiveById((int)$cart->id_address_invoice)
|
||||
) {
|
||||
if ($bad_delivery) {
|
||||
$this->errors[] = Tools::displayError('This booking address country is not active.');
|
||||
} else {
|
||||
$this->errors[] = Tools::displayError('This invoice address country is not active.');
|
||||
}
|
||||
$objCart = new Cart($id_cart);
|
||||
if (Validate::isLoadedObject($objCart)) {
|
||||
if ($objCart->is_advance_payment) {
|
||||
$orderTotal = $objCart->getOrderTotal(true, Cart::ADVANCE_PAYMENT);
|
||||
} else {
|
||||
$amountPaid = $cart->getOrderTotal(true, Cart::BOTH);
|
||||
$orderTotal = $objCart->getOrderTotal(true, Cart::BOTH);
|
||||
}
|
||||
|
||||
// Validate data if required
|
||||
if ($orderTotal > 0) {
|
||||
$moduleName = trim(Tools::getValue('payment_module_name'));
|
||||
$paymentType = Tools::getValue('payment_type');
|
||||
$paymentTransactionId = trim(Tools::getValue('payment_transaction_id'));
|
||||
$isFullPayment = Tools::getValue('is_full_payment');
|
||||
$paymentAmount = trim(Tools::getValue('payment_amount'));
|
||||
|
||||
if (!$isFullPayment) {
|
||||
$amountPaid = Tools::ps_round($paymentAmount, 6);
|
||||
}
|
||||
|
||||
$employee = new Employee((int)Context::getContext()->cookie->id_employee);
|
||||
$payment_module->validateOrder(
|
||||
(int)$cart->id,
|
||||
(int)$id_order_state,
|
||||
$amountPaid,
|
||||
$payment_module->displayName,
|
||||
$this->l('Manual order -- Employee:').' '.
|
||||
substr($employee->firstname, 0, 1).'. '.$employee->lastname,
|
||||
$paymentTransactionId ? array('transaction_id' => $paymentTransactionId) : array(),
|
||||
null,
|
||||
false,
|
||||
$cart->secure_key
|
||||
);
|
||||
|
||||
// add order payment if required
|
||||
$objOrderState = new OrderState($id_order_state);
|
||||
if (!$objOrderState->logable && !$objOrderState->paid) {
|
||||
$objOrder = new Order($payment_module->currentOrder);
|
||||
|
||||
if ($objOrder->hasInvoice()) {
|
||||
$invoices = $objOrder->getInvoicesCollection();
|
||||
|
||||
$dateTimeNow = date('Y-m-d H:i:s');
|
||||
foreach ($invoices as $invoice) {
|
||||
$objOrder->addOrderPayment(
|
||||
$amountPaid,
|
||||
$payment_module->displayName,
|
||||
$paymentTransactionId,
|
||||
new Currency($objOrder->id_currency),
|
||||
$dateTimeNow,
|
||||
$invoice,
|
||||
$paymentType
|
||||
);
|
||||
}
|
||||
if ($paymentAmount == '') {
|
||||
$this->errors[] = Tools::displayError('Please enter valid Payment amount of the order.');
|
||||
} elseif ($paymentAmount && !Validate::isPrice($paymentAmount)) {
|
||||
$this->errors[] = Tools::displayError('Payment amount is invalid. Please enter correct amount.');
|
||||
} else {
|
||||
$objOrder->addOrderPayment(
|
||||
$amountPaid,
|
||||
$payment_module->displayName,
|
||||
$paymentTransactionId,
|
||||
new Currency($objOrder->id_currency),
|
||||
date('Y-m-d H:i:s'),
|
||||
null,
|
||||
$paymentType
|
||||
);
|
||||
$paymentAmount = (float) $paymentAmount;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->context->cookie->id_cart)) {
|
||||
unset($this->context->cookie->id_cart);
|
||||
}
|
||||
if (isset($this->context->cookie->id_guest)) {
|
||||
unset($this->context->cookie->id_guest);
|
||||
if ($paymentAmount >= 0) {
|
||||
if (!$moduleName) {
|
||||
$this->errors[] = Tools::displayError('Please enter Payment method.');
|
||||
} elseif ($moduleName && !Validate::isGenericName($moduleName)) {
|
||||
$this->errors[] = Tools::displayError('Payment method is invalid. Please enter a valid payment method.');
|
||||
}
|
||||
}
|
||||
|
||||
if ($payment_module->currentOrder) {
|
||||
Tools::redirectAdmin(self::$currentIndex.'&id_order='.$payment_module->currentOrder.'&vieworder'.'&token='.$this->token.'&conf=3');
|
||||
if ($paymentAmount > 0) {
|
||||
if (!$paymentType) {
|
||||
$this->errors[] = Tools::displayError('Please select a Payment source.');
|
||||
} elseif ($paymentType && !Validate::isUnsignedInt($paymentType)) {
|
||||
$this->errors[] = Tools::displayError('Payment source is invalid. Please select payment source.');
|
||||
}
|
||||
|
||||
if ($paymentTransactionId && !Validate::isString($paymentTransactionId)) {
|
||||
$this->errors[] = Tools::displayError('Payment amount is invalid. Please enter correct amount.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!count($this->errors)) {
|
||||
$this->context->currency = new Currency((int) $objCart->id_currency);
|
||||
$this->context->customer = new Customer((int) $objCart->id_customer);
|
||||
|
||||
// Set payment module details
|
||||
$objPaymentModule = new BoOrder();
|
||||
if ($orderTotal > 0) {
|
||||
$objPaymentModule->payment_type = $paymentType;
|
||||
$objPaymentModule->displayName = $moduleName;
|
||||
} else {
|
||||
$objPaymentModule->name = 'free_order';
|
||||
$objPaymentModule->displayName = $this->l('Free order');
|
||||
}
|
||||
|
||||
// Set order state
|
||||
if ($orderTotal > 0) {
|
||||
if ($isFullPayment) {
|
||||
$idOrderState = Configuration::get('PS_OS_PAYMENT_ACCEPTED');
|
||||
} else {
|
||||
if ($paymentAmount <= 0) {
|
||||
$idOrderState = Configuration::get('PS_OS_AWAITING_PAYMENT');
|
||||
} elseif (($paymentAmount > 0) && ($paymentAmount < $orderTotal)) {
|
||||
$idOrderState = Configuration::get('PS_OS_PARTIAL_PAYMENT_ACCEPTED');
|
||||
} else {
|
||||
$idOrderState = Configuration::get('PS_OS_PAYMENT_ACCEPTED');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$idOrderState = Configuration::get('PS_OS_PAYMENT_ACCEPTED');
|
||||
}
|
||||
|
||||
// Set amount paid
|
||||
if ($orderTotal > 0) {
|
||||
if ($isFullPayment) {
|
||||
$amountPaid = $orderTotal;
|
||||
} else {
|
||||
$amountPaid = $paymentAmount;
|
||||
}
|
||||
} else {
|
||||
$amountPaid = 0;
|
||||
}
|
||||
|
||||
// Set transaction ID
|
||||
if ($orderTotal > 0) {
|
||||
if ($paymentTransactionId) {
|
||||
$paymentTransactionId = array('transaction_id' => $paymentTransactionId);
|
||||
} else {
|
||||
$paymentTransactionId = array();
|
||||
}
|
||||
} else {
|
||||
$paymentTransactionId = null;
|
||||
}
|
||||
|
||||
$bad_delivery = false;
|
||||
if (($bad_delivery = (bool)!Address::isCountryActiveById((int)$objCart->id_address_delivery))
|
||||
|| !Address::isCountryActiveById((int)$objCart->id_address_invoice)
|
||||
) {
|
||||
if ($bad_delivery) {
|
||||
$this->errors[] = Tools::displayError('This booking address country is not active.');
|
||||
} else {
|
||||
$this->errors[] = Tools::displayError('This invoice address country is not active.');
|
||||
}
|
||||
} else {
|
||||
$amountPaid = Tools::ps_round($amountPaid, 6);
|
||||
$objEmployee = new Employee($this->context->cookie->id_employee);
|
||||
|
||||
$objPaymentModule->validateOrder(
|
||||
$objCart->id,
|
||||
$idOrderState,
|
||||
$amountPaid,
|
||||
$objPaymentModule->displayName,
|
||||
$this->l('Manual order -- Employee:').' '.substr($objEmployee->firstname, 0, 1).'. '.$objEmployee->lastname,
|
||||
$paymentTransactionId,
|
||||
null,
|
||||
false,
|
||||
$objCart->secure_key
|
||||
);
|
||||
|
||||
if (isset($this->context->cookie->id_cart)) {
|
||||
unset($this->context->cookie->id_cart);
|
||||
}
|
||||
if (isset($this->context->cookie->id_guest)) {
|
||||
unset($this->context->cookie->id_guest);
|
||||
}
|
||||
|
||||
if ($objPaymentModule->currentOrder) {
|
||||
Tools::redirectAdmin(self::$currentIndex.'&id_order='.$objPaymentModule->currentOrder.'&vieworder'.'&token='.$this->token.'&conf=3');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// if errors render add order form
|
||||
$_GET['addorder'] = '1';
|
||||
$_GET['cart_id'] = $id_cart;
|
||||
}
|
||||
} else {
|
||||
// if errors render add order form
|
||||
$_GET['addorder'] = '1';
|
||||
$_GET['cart_id'] = $id_cart;
|
||||
$this->errors[] = Tools::displayError('Cart can not be loaded.');
|
||||
}
|
||||
} else {
|
||||
$this->errors[] = Tools::displayError('You do not have permission to add this.');
|
||||
|
||||
Reference in New Issue
Block a user