Skip to content

Commit

Permalink
https://github.com/opencart/opencart/issues/11458
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkerr committed Nov 17, 2024
1 parent 4b2b362 commit fa01d5e
Show file tree
Hide file tree
Showing 4 changed files with 259 additions and 74 deletions.
20 changes: 4 additions & 16 deletions upload/admin/view/template/sale/order_info.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2032,20 +2032,14 @@ $('#button-shipping-methods').on('click', function() {
});
$('#modal-shipping-method').on('change', 'input[name=\'choose_shipping\']', function() {
var element = this;
var html = '';
var code = $(element).val();
var code = $(this).val();
if (shipping_method[code]) {
$('#input-shipping-method-name').val(shipping_method[code]['name']);
$('#input-shipping-method-code').val(shipping_method[code]['code']);
$('#input-shipping-method-cost').val(shipping_method[code]['cost']);
$('#input-shipping-method-tax-class').val(shipping_method[code]['tax_class_id']);
}
$('#form-shipping-method').html(html);
});
$('#form-shipping-method').on('submit', function(e) {
Expand Down Expand Up @@ -2179,18 +2173,12 @@ $('#button-payment-methods').on('click', function() {
});
$('#modal-payment-method').on('change', 'input[name=\'choose_payment\']', function() {
var element = this;
var html = '';
var code = $(element).val();
var code = $(this).val();
if (payment_method[code]) {
$('#input-payment-method-name').val(payment_method[code]['name'])
$('#input-payment-method-code').val(payment_method[code]['code'])
$('#input-payment-method-name').val(payment_method[code]['name']);
$('#input-payment-method-code').val(payment_method[code]['code']);
}
$('#form-payment-method').html(html);
});
$('#form-payment-method').on('submit', function(e) {
Expand Down
261 changes: 242 additions & 19 deletions upload/admin/view/template/sale/subscription_info.twig
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,9 @@
</div>
</div>
</div>

<script type="text/javascript"><!--
var customer = [];
$('#input-customer').autocomplete({
'source': function(request, response) {
$.ajax({
Expand Down Expand Up @@ -652,6 +653,17 @@ $('#input-customer').autocomplete({
},
'select': function(item) {
$('#input-customer').val(item['label']);
if (item) {
var customer = item;
}
}
});
$('#form-customer').on('submit', function(e) {
e.preventDefault();
if (customer) {
$('#input-customer-id').val(item['value']);
$('#input-firstname').val(item['firstname']);
$('#input-lastname').val(item['lastname']);
Expand All @@ -667,7 +679,21 @@ $('#input-customer').autocomplete({
$('#input-shipping-address').html(html);
$('#customer-value').html('<a href="index.php?route=customer/customer.form&user_token={{ user_token }}&customer_id=' + $('#input-customer-id').val() + '" target="_blank">' + $('#input-firstname').val() + ' ' + $('#input-lastname').val() + '</a>');
} else {
$('#input-customer-id').val('');
$('#input-firstname').val('');
$('#input-lastname').val('');
$('#input-customer-group').val(item['customer_group_id']);
html = '<option value="0">{{ text_none|escape('js') }}</option>';
$('#input-payment-address').html(html);
$('#input-shipping-address').html(html);
$('#customer-value').html('');
}
$('#modal-customer').modal('hide');
});
$('#input-product').autocomplete({
Expand Down Expand Up @@ -895,7 +921,71 @@ $('#form-product-add').on('submit', function(e) {
if (json['success']) {
$('#form-product-add').prepend('<div class="alert alert-success alert-dismissible"><i class="fa-solid fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="btn-close" data-bs-dismiss="alert"></button></div>');
cart_render(json['products'], json['totals'], json['shipping_required']);
html = '<tr>';
html += ' <td><a href="index.php?route=catalog/product.form&user_token={{ user_token }}&product_id=' + product['product_id'] + '" target="_blank">' + product['name'] + '</a>' + (!product['stock'] ? ' <span class="text-danger">***</span>' : '');
html += ' <div id="error-product-' + order_product_row + '-product" class="invalid-feedback mt-0"></div>';
html += '<ul class="list-unstyled mb-0">';
html += '<li>';
html += ' <small> - {{ text_model|escape('js') }}: ' + product['model'] + '</small>';
html += '</li>';
for (j = 0; j < product['option'].length; j++) {
option = product['option'][j];
html += '<li>';
html += ' <small> - ' + option['name'] + ': ' + option['value'] + '</small>';
html += ' <div id="error-product-' + order_product_row + '-option-' + option['product_option_id'] + '" class="invalid-feedback mt-0"></div>';
html += '</li>';
}
if (product['subscription']) {
html += '<li>';
html += ' <small> - {{ text_subscription|escape('js') }}: ' + product['subscription'] + '</small>';
html += ' <div id="error-product-' + order_product_row + '-subscription" class="invalid-feedback mt-0"></div>';
html += '</li>';
}
if (product['reward']) {
html += '<li>';
html += ' <small> - {{ text_points|escape('js') }}: ' + product['reward'] + '</small>';
html += '</li>';
}
html += '</ul>';
html += '<input type="hidden" name="product[' + order_product_row + '][product_id]" value="' + product['product_id'] + '"/>';
html += '<input type="hidden" name="product[' + order_product_row + '][quantity]" value="' + product['quantity'] + '"/>';
for (j = 0; j < product['option'].length; j++) {
option = product['option'][j];
if (option['type'] == 'select' || option['type'] == 'radio') {
html += '<input type="hidden" name="product[' + order_product_row + '][option][' + option['product_option_id'] + ']" value="' + option['product_option_value_id'] + '"/>';
}
if (option['type'] == 'checkbox') {
html += '<input type="hidden" name="product[' + order_product_row + '][option][' + option['product_option_id'] + '][]" value="' + option['product_option_value_id'] + '"/>';
}
if (option['type'] == 'text' || option['type'] == 'textarea' || option['type'] == 'file' || option['type'] == 'date' || option['type'] == 'datetime' || option['type'] == 'time') {
html += '<input type="hidden" name="product[' + order_product_row + '][option][' + option['product_option_id'] + ']" value="' + option['value'] + '"/>';
}
}
html += ' <input type="hidden" name="product[' + order_product_row + '][subscription_plan_id]" value="' + product['subscription_plan_id'] + '"/>';
html += ' </td>';
html += ' <td class="text-end">' + product['quantity'] + '</td>';
html += ' <td class="text-end">' + product['price_text'] + '</td>';
html += ' <td class="text-end">' + product['total_text'] + '</td>';
html += ' <td class="text-end"><button type="button" data-bs-toggle="tooltip" title="{{ button_remove|escape('js') }}" class="btn btn-danger"><i class="fa-solid fa-minus-circle"></i></button></td>';
html += '</tr>';
order_product_row++;
$('#order-product').html(html);
}
},
error: function(xhr, ajaxOptions, thrownError) {
Expand All @@ -907,11 +997,11 @@ $('#form-product-add').on('submit', function(e) {
// Remove product
$('#order-product').on('click', 'button', function(e) {
$(this).parent().parent().remove();
// Refresh products and totals
$('#button-refresh').trigger('click');
});
// Payment Address
var payment_address = [];
$('#input-payment-address').on('change', function(e) {
var element = this;
Expand All @@ -932,7 +1022,9 @@ $('#input-payment-address').on('change', function(e) {
}
if (json['address_id']) {
var payment_address = json;
payment_address = json;
} else {
payment_address = [];
}
},
error: function(xhr, ajaxOptions, thrownError) {
Expand Down Expand Up @@ -977,6 +1069,8 @@ $('#form-payment-address').on('submit', function(e) {
});
// Shipping Address
var shipping_address = [];
$('#input-shipping-address').on('change', function() {
var element = this;
Expand All @@ -997,7 +1091,9 @@ $('#input-shipping-address').on('change', function() {
}
if (json['address_id']) {
var shipping_address = json;
shipping_address = json;
} else {
shipping_address = [];
}
},
error: function(xhr, ajaxOptions, thrownError) {
Expand Down Expand Up @@ -1124,20 +1220,14 @@ $('#button-shipping-methods').on('click', function() {
});
$('#modal-shipping-method').on('change', 'input[name=\'choose_shipping\']', function() {
var element = this;
var html = '';
var code = $(element).val();
var code = $(this).val();
if (shipping_method[code]) {
html += '<input type="hidden" name="shipping_method_name" value="' + shipping_method[code]['name'] + '" id="input-shipping-method-name"/>';
html += '<input type="hidden" name="shipping_method_code" value="' + shipping_method[code]['code'] + '" id="input-shipping-method-code"/>';
html += '<input type="hidden" name="shipping_method_cost" value="' + shipping_method[code]['cost'] + '" id="input-shipping-method-cost"/>';
html += '<input type="hidden" name="shipping_method_tax_class_id" value="' + shipping_method[code]['tax_class_id'] + '" id="input-shipping-method-tax-class"/>';
$('#input-shipping-method-name').val(shipping_method[code]['name']);
$('#input-shipping-method-code').val(shipping_method[code]['code']);
$('#input-shipping-method-cost').val(shipping_method[code]['cost']);
$('#input-shipping-method-tax-class').val(shipping_method[code]['tax_class_id']);
}
$('#form-shipping-method').html(html);
});
$('#form-shipping-method').on('submit', function(e) {
Expand Down Expand Up @@ -1183,8 +1273,141 @@ $('#form-shipping-method').on('submit', function(e) {
$('#modal-shipping-method .modal-body').prepend('<div class="alert alert-success alert-dismissible"><i class="fa-solid fa-circle-check"></i> ' + json['success'] + ' <button type="button" class="btn-close" data-bs-dismiss="alert"></button></div>');
$('#shipping-method-value').html($('#input-shipping-method-name').val());
}
},
error: function(xhr, ajaxOptions, thrownError) {
console.log(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
});
// Payment Method
var payment_method = [];
$('#button-payment-methods').on('click', function() {
var element = this;
$.ajax({
url: 'index.php?route=sale/order.call&user_token={{ user_token }}&call=payment_methods&store_id=' + $('#input-store').val() + '&language=' + $('#input-language').val() + '&currency=' + $('#input-currency').val(),
type: 'post',
data: $('#form-customer, #form-cart, #form-shipping-address, #form-shipping-method, #form-payment-address, #form-payment-method, #collapse-order form').serialize(),
dataType: 'json',
contentType: 'application/x-www-form-urlencoded',
beforeSend: function() {
$(element).button('loading');
},
complete: function() {
$(element).button('reset');
},
success: function(json) {
$('.alert-dismissible').remove();
if (typeof json['error'] == 'string') {
$('#alert').prepend('<div class="alert alert-danger alert-dismissible"><i class="fa-solid fa-circle-exclamation"></i> ' + json['error'] + ' <button type="button" class="btn-close" data-bs-dismiss="alert"></button></div>');
}
if (typeof json['error'] == 'object') {
if (json['error']['warning']) {
$('#alert').prepend('<div class="alert alert-danger alert-dismissible"><i class="fa-solid fa-circle-exclamation"></i> ' + json['error']['warning'] + ' <button type="button" class="btn-close" data-bs-dismiss="alert"></button></div>');
}
for (key in json['error']) {
$('#input-' + key.replaceAll('_', '-')).addClass('is-invalid').find('.form-control, .form-select, .form-check-input, .form-check-label').addClass('is-invalid');
$('#error-' + key.replaceAll('_', '-')).html(json['error'][key]).addClass('d-block');
}
}
var html = '';
if (json['payment_methods']) {
var k = 0;
for (i in json['payment_methods']) {
html += '<p><strong>' + json['payment_methods'][i]['name'] + '</strong></p>';
if (!json['payment_methods'][i]['error']) {
for (j in json['payment_methods'][i]['option']) {
payment_method[json['payment_methods'][i]['option'][j]['code']] = json['payment_methods'][i]['option'][j];
html += '<div class="form-check">';
html += ' <input type="radio" name="choose_payment" value="' + json['payment_methods'][i]['option'][j]['code'] + '" id="input-payment-method-' + k + '"';
if (json['payment_methods'][i]['option'][j]['code'] == $('#input-payment-method-code').val()) {
html += ' checked';
}
html += '/>';
html += ' <label for="input-payment-method-' + k + '">' + json['payment_methods'][i]['option'][j]['name'] + '</label>';
html += '</div>';
k++;
}
} else {
html += '<div class="alert alert-danger">' + json['payment_methods'][i]['error'] + '</div>';
}
}
$('#payment-methods').html(html);
$('#modal-payment-method').modal('show');
}
},
error: function(xhr, ajaxOptions, thrownError) {
console.log(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
});
$('#modal-payment-method').on('change', 'input[name=\'choose_payment\']', function() {
var code = $(this).val();
if (payment_method[code]) {
$('#input-payment-method-name').val(payment_method[code]['name']);
$('#input-payment-method-code').val(payment_method[code]['code']);
}
});
$('#form-payment-method').on('submit', function(e) {
e.preventDefault();
var element = this;
$.ajax({
url: 'index.php?route=sale/order.call&user_token={{ user_token }}&call=payment_method&store_id=' + $('#input-store').val() + '&language=' + $('#input-language').val() + '&currency=' + $('#input-currency').val(),
type: 'post',
data: $('#form-customer, #form-cart, #form-shipping-address, #form-shipping-method, #form-payment-address, #form-payment-method, #collapse-order form').serialize(),
dataType: 'json',
contentType: 'application/x-www-form-urlencoded',
beforeSend: function() {
$('#button-payment-method').button('loading');
},
complete: function() {
$('#button-payment-method').button('reset');
},
success: function(json) {
console.log(json);
$('.alert-dismissible').remove();
if (typeof json['error'] == 'string') {
$('#modal-payment-method .modal-body').prepend('<div class="alert alert-danger alert-dismissible"><i class="fa-solid fa-circle-exclamation"></i> ' + json['error'] + ' <button type="button" class="btn-close" data-bs-dismiss="alert"></button></div>');
}
if (typeof json['error'] == 'object') {
if (json['error']['warning']) {
$('#modal-payment-method .modal-body').prepend('<div class="alert alert-danger alert-dismissible"><i class="fa-solid fa-circle-exclamation"></i> ' + json['error']['warning'] + ' <button type="button" class="btn-close" data-bs-dismiss="alert"></button></div>');
}
for (key in json['error']) {
$('#input-' + key.replaceAll('_', '-')).addClass('is-invalid').find('.form-control, .form-select, .form-check-input, .form-check-label').addClass('is-invalid');
$('#error-' + key.replaceAll('_', '-')).html(json['error'][key]).addClass('d-block');
}
}
if (json['success']) {
$('#modal-payment-method .modal-body').prepend('<div class="alert alert-success alert-dismissible"><i class="fa-solid fa-circle-check"></i> ' + json['success'] + ' <button type="button" class="btn-close" data-bs-dismiss="alert"></button></div>');
cart_render(json['products'], json['totals'], json['shipping_required']);
$('#payment-method-value').html($('#input-payment-method-name').val());
}
},
error: function(xhr, ajaxOptions, thrownError) {
Expand Down
Loading

0 comments on commit fa01d5e

Please sign in to comment.