Allow Custom payment method on new order creation
This commit is contained in:
@@ -22,12 +22,12 @@
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*}
|
||||
<select class="fixed-width-xxl" name="payment_module_name" id="payment_module_name">
|
||||
{if !$PS_CATALOG_MODE}
|
||||
{foreach from=$payment_modules item='module'}
|
||||
<option value="{$module->name}" data-payment-type="{$module->payment_type}" {if isset($smarty.post.payment_module_name) && $module->name == $smarty.post.payment_module_name}selected="selected"{/if}>{$module->displayName}</option>
|
||||
|
||||
<datalist id="payment_module_name_list">
|
||||
{if $PS_CATALOG_MODE}
|
||||
<option value="{l s='Back office order'}" data-name="{l s='Back office order'}" data-payment-type="{OrderPayment::PAYMENT_TYPE_PAY_AT_HOTEL}">
|
||||
{/if}
|
||||
{foreach from=$payment_modules item=payment_module}
|
||||
<option value="{$payment_module->displayName}" data-name="{$payment_module->name}">
|
||||
{/foreach}
|
||||
{else}
|
||||
<option value="{l s='Back office order'}">{l s='Back office order'}</option>
|
||||
{/if}
|
||||
</select>
|
||||
</datalist>
|
||||
|
||||
@@ -359,7 +359,8 @@
|
||||
if (data.result)
|
||||
{
|
||||
$('#cart_detail_form').show();//line added by webkul
|
||||
$('#payment_module_name').replaceWith(data.view)
|
||||
$('#payment_method_options').replaceWith(data.view)
|
||||
$('#payment_module_name_display').val('')
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -1586,10 +1587,28 @@
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on('change', '#payment_module_name', function() {
|
||||
let paymentType = $(this).find(':selected').attr('data-payment-type');
|
||||
if ($('select#payment_type option[value="' + paymentType + '"]').length) {
|
||||
$('#payment_type').val(paymentType);
|
||||
$(document).on('keyup', '#payment_module_name_display', function() {
|
||||
let paymentMethod = $('#payment_module_name_display').val().trim().toLowerCase();
|
||||
|
||||
let selectedMethod;
|
||||
$('#payment_module_name_list option').each(function (index, element) {
|
||||
if ($(element).attr('data-name').toLowerCase() == paymentMethod
|
||||
|| $(element).val().toLowerCase() == paymentMethod
|
||||
) {
|
||||
selectedMethod = element;
|
||||
}
|
||||
});
|
||||
|
||||
if ($(selectedMethod).length) {
|
||||
$('#payment_module_name').val($(selectedMethod).attr('data-name'));
|
||||
|
||||
// set Payment source
|
||||
let paymentType = $(selectedMethod).attr('data-payment-type');
|
||||
if ($('select#payment_type option[value="' + paymentType + '"]').length) {
|
||||
$('#payment_type').val(paymentType);
|
||||
}
|
||||
} else {
|
||||
$('#payment_module_name').val($('#payment_module_name_display').val());
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1723,7 +1742,7 @@
|
||||
</div> -->*}<!-- by webkul to hide unnessesary content -->
|
||||
</div>
|
||||
|
||||
<form class="form-horizontal" action="{$link->getAdminLink('AdminOrders')|escape:'html':'UTF-8'}&submitAdd{$table|escape:'html':'UTF-8'}=1" method="post" autocomplete="off" style="display:none" id="cart_detail_form">
|
||||
<form class="form-horizontal" action="{$link->getAdminLink('AdminOrders')|escape:'html':'UTF-8'}&submitAdd{$table|escape:'html':'UTF-8'}=1" method="post" style="display:none" id="cart_detail_form">
|
||||
<div class="panel" id="products_part" style="display:none;">
|
||||
<div class="panel-heading">
|
||||
<i class="icon-shopping-cart"></i>
|
||||
@@ -2095,17 +2114,18 @@
|
||||
{/if}
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="control-label col-lg-3">{l s='Payment method'}</label>
|
||||
<label class="control-label col-lg-3 required">{l s='Payment method'}</label>
|
||||
<div class="col-lg-9">
|
||||
<select class="fixed-width-xxl" name="payment_module_name" id="payment_module_name">
|
||||
{if !$PS_CATALOG_MODE}
|
||||
{foreach from=$payment_modules item='module'}
|
||||
<option value="{$module->name}" data-payment-type="{$module->payment_type}" {if isset($smarty.post.payment_module_name) && $module->name == $smarty.post.payment_module_name}selected="selected"{/if}>{$module->displayName}</option>
|
||||
{/foreach}
|
||||
{else}
|
||||
<option value="boorder">{l s='Back office order'}</option>
|
||||
<input name="payment_module_name_display" id="payment_module_name_display" list="payment_module_name_list" class="form-control fixed-width-xxl" {if isset($smarty.post.payment_module_name_display) && $smarty.post.payment_module_name_display}value="{$smarty.post.payment_module_name_display}"{/if}>
|
||||
<input type="hidden" name="payment_module_name" id="payment_module_name" {if isset($smarty.post.payment_module_name) && $smarty.post.payment_module_name}value="{$smarty.post.payment_module_name}"{/if}>
|
||||
<datalist id="payment_module_name_list">
|
||||
{if $PS_CATALOG_MODE}
|
||||
<option value="{l s='Back office order'}" data-name="{l s='Back office order'}" data-payment-type="{OrderPayment::PAYMENT_TYPE_PAY_AT_HOTEL}">
|
||||
{/if}
|
||||
</select>
|
||||
{foreach from=$payment_modules item=payment_module}
|
||||
<option value="{$payment_module->displayName}" data-name="{$payment_module->name}" data-payment-type="{$payment_module->payment_type}">
|
||||
{/foreach}
|
||||
</datalist>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
|
||||
@@ -954,13 +954,21 @@ 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')) &&
|
||||
($module_name = Tools::getValue('payment_module_name')) &&
|
||||
($id_order_state = Tools::getValue('id_order_state')) && Validate::isModuleName($module_name)) {
|
||||
} elseif (Tools::isSubmit('submitAddOrder')
|
||||
&& ($id_cart = Tools::getValue('id_cart'))
|
||||
&& ($id_order_state = Tools::getValue('id_order_state'))
|
||||
) {
|
||||
if ($this->tabAccess['edit'] === '1') {
|
||||
$moduleName = trim(Tools::getValue('payment_module_name'));
|
||||
$paymentType = Tools::getValue('payment_type');
|
||||
$paymentTransactionId = trim(Tools::getValue('payment_transaction_id'));
|
||||
$paymentAmount = Tools::getValue('payment_amount');
|
||||
$paymentAmount = trim(Tools::getValue('payment_amount'));
|
||||
|
||||
if (!$moduleName) {
|
||||
$this->errors[] = Tools::displayError('Please enter Payment method.');
|
||||
} elseif ($moduleName && !((Validate::isModuleName($moduleName) && ($paymentModuleInstance = Module::getInstanceByName($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.');
|
||||
@@ -977,10 +985,11 @@ class AdminOrdersControllerCore extends AdminController
|
||||
}
|
||||
|
||||
if (!count($this->errors)) {
|
||||
if (!Configuration::get('PS_CATALOG_MODE')) {
|
||||
$payment_module = Module::getInstanceByName($module_name);
|
||||
if ($paymentModuleInstance) {
|
||||
$payment_module = $paymentModuleInstance;
|
||||
} else {
|
||||
$payment_module = new BoOrder();
|
||||
$payment_module->displayName = $moduleName;
|
||||
}
|
||||
|
||||
$payment_module->payment_type = $paymentType;
|
||||
@@ -4680,6 +4689,7 @@ class AdminOrdersControllerCore extends AdminController
|
||||
}
|
||||
|
||||
$this->context->smarty->assign(array(
|
||||
'PS_CATALOG_MODE' => Configuration::get('PS_CATALOG_MODE'),
|
||||
'payment_modules' => $payment_modules,
|
||||
));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user