Skip to content

Commit

Permalink
https://github.com/opencart/opencart/issues/2965
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkerr committed May 25, 2015
1 parent 6e95c48 commit 3826c8d
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 66 deletions.
4 changes: 2 additions & 2 deletions upload/admin/controller/sale/order.php
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ public function getForm() {
$data['comment'] = $order_info['comment'];
$data['affiliate_id'] = $order_info['affiliate_id'];
$data['affiliate'] = $order_info['affiliate_firstname'] . ' ' . $order_info['affiliate_lastname'];
$data['currency_id'] = $order_info['currency_id'];
$data['currency_code'] = $order_info['currency_code'];
} else {
$data['order_id'] = 0;
$data['store_id'] = '';
Expand Down Expand Up @@ -843,7 +843,7 @@ public function getForm() {
$data['comment'] = '';
$data['affiliate_id'] = '';
$data['affiliate'] = '';
$data['currency_id'] = $order_info['currency_id'];
$data['currency_code'] = $this->config->get('config_currency');

$data['coupon'] = '';
$data['voucher'] = '';
Expand Down
112 changes: 48 additions & 64 deletions upload/admin/view/template/sale/order_form.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-currency"><?php echo $entry_currency; ?></label>
<div class="col-sm-10">
<select name="currency" id="input-currency" class="form-control">
<?php foreach ($currencies as $currency) { ?>
<?php if ($currency['code'] == $currency_code) { ?>
<option value="<?php echo $currency['code']; ?>" selected="selected"><?php echo $currency['title']; ?></option>
<?php } else { ?>
<option value="<?php echo $currency['code']; ?>"><?php echo $currency['title']; ?></option>
<?php } ?>
<?php } ?>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-customer"><?php echo $entry_customer; ?></label>
<div class="col-sm-10">
Expand Down Expand Up @@ -597,10 +611,6 @@
</div>
</div>
</div>




<div class="tab-pane" id="tab-shipping">
<div class="form-group">
<label class="col-sm-2 control-label" for="input-shipping-address"><?php echo $entry_address; ?></label>
Expand Down Expand Up @@ -812,7 +822,6 @@
</div>
</div>
</div>

<div class="tab-pane" id="tab-total">
<div class="table-responsive">
<table class="table table-bordered">
Expand All @@ -831,26 +840,9 @@
</tr>
</tbody>
</table>
</div> <fieldset>
</div>
<fieldset>
<legend><?php echo $text_order; ?></legend>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-currency"><?php echo $entry_currency; ?></label>
<div class="col-sm-10">
<div class="input-group">
<select name="currency" id="input-currency" class="form-control">
<?php foreach ($currencies as $currency) { ?>
<?php if ($currency['currency_id'] == $currency_id) { ?>
<option value="<?php echo $currency['currency_id']; ?>" selected="selected"><?php echo $currency['title']; ?></option>
<?php } else { ?>
<option value="<?php echo $currency['currency_id']; ?>"><?php echo $currency['title']; ?></option>
<?php } ?>
<?php } ?>
</select>
<span class="input-group-btn">
<button type="button" id="button-currency" data-loading-text="<?php echo $text_loading; ?>" class="btn btn-primary"><?php echo $button_apply; ?></button>
</span></div>
</div>
</div>
<div class="form-group required">
<label class="col-sm-2 control-label" for="input-shipping-method"><?php echo $entry_shipping_method; ?></label>
<div class="col-sm-10">
Expand Down Expand Up @@ -940,7 +932,6 @@
</div>
</div>
</fieldset>

<div class="row">
<div class="col-sm-6 text-left">
<button type="button" onclick="$('select[name=\'shipping_method\']').prop('disabled') ? $('a[href=\'#tab-payment\']').tab('show') : $('a[href=\'#tab-shipping\']').tab('show');" class="btn btn-default"><i class="fa fa-arrow-left"></i> <?php echo $button_back; ?></button>
Expand Down Expand Up @@ -1141,6 +1132,38 @@ $('#button-refresh').on('click', function() {
});
});
// Currency
$('select[name=\'currency\']').on('change', function() {
$.ajax({
url: 'index.php?route=sale/order/api&token=<?php echo $token; ?>&api=api/currency&store_id=' + $('select[name=\'store_id\'] option:selected').val(),
type: 'post',
data: 'currency=' + $('select[name=\'currency\'] option:selected').val(),
dataType: 'json',
beforeSend: function() {
$('select[name=\'currency\']').after(' <i class="fa fa-circle-o-notch fa-spin"></i>');
},
complete: function() {
$('.fa-spin').remove();
},
success: function(json) {
$('.alert, .text-danger').remove();
$('.form-group').removeClass('has-error');
if (json['error']) {
$('#content > .container-fluid').prepend('<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> ' + json['error'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');
// Highlight any found errors
$('select[name=\'currency\']').parent().parent().parent().addClass('has-error');
}
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
});
$('select[name=\'currency\']').trigger('change');
// Customer
$('input[name=\'customer\']').autocomplete({
'source': function(request, response) {
Expand Down Expand Up @@ -2052,43 +2075,6 @@ $('#button-shipping-address').on('click', function() {
});
});
// Shipping Method
$('#button-currency').on('click', function() {
$.ajax({
url: 'index.php?route=sale/order/api&token=<?php echo $token; ?>&api=api/currency&store_id=' + $('select[name=\'store_id\'] option:selected').val(),
type: 'post',
data: 'currency=' + $('select[name=\'currency\'] option:selected').val(),
dataType: 'json',
beforeSend: function() {
$('#button-currency').button('loading');
},
complete: function() {
$('#button-currency').button('reset');
},
success: function(json) {
$('.alert, .text-danger').remove();
$('.form-group').removeClass('has-error');
if (json['error']) {
$('#content > .container-fluid').prepend('<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> ' + json['error'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');
// Highlight any found errors
$('select[name=\'currency\']').parent().parent().parent().addClass('has-error');
}
if (json['success']) {
$('#content > .container-fluid').prepend('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');
// Refresh products, vouchers and totals
$('#button-refresh').trigger('click');
}
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
});
// Shipping Method
$('#button-shipping-method').on('click', function() {
$.ajax({
Expand Down Expand Up @@ -2409,8 +2395,6 @@ $('.datetime').datetimepicker({
$('.time').datetimepicker({
pickDate: false
});
//--></script>
<script type="text/javascript">
// Sort the custom fields
Expand Down
30 changes: 30 additions & 0 deletions upload/catalog/controller/api/currency.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
class ControllerApiCurrency extends Controller {
public function index() {
$this->load->language('api/currency');

$json = array();

if (!isset($this->session->data['api_id'])) {
$json['error'] = $this->language->get('error_permission');
} else {
$this->load->model('localisation/currency');

$currency_info = $this->model_localisation_currency->getCurrencyByCode($this->request->post['currency']);

if ($currency_info) {
$this->currency->set($this->request->post['currency']);

unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);

$json['success'] = $this->language->get('text_success');
} else {
$json['error'] = $this->language->get('error_currency');
}
}

$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}
7 changes: 7 additions & 0 deletions upload/catalog/language/english/api/currency.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
// Text
$_['text_success'] = 'Success: Your currency has been changed!';

// Error
$_['error_permission'] = 'Warning: You do not have permission to access the API!';
$_['error_currency'] = 'Warning: Currency code is invalid!';

0 comments on commit 3826c8d

Please sign in to comment.