Implemented prices conversion management
This commit is contained in:
@@ -115,7 +115,7 @@
|
||||
<div class="form-group {if $error}has-error{/if}">
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" id="use_exchange_rate_box" name="{$name}" value="1" {if $value != 0}checked="checked"{/if}>
|
||||
<input type="checkbox" data-pse-id="{$default_product_sale_element_id}" class="use_exchange_rate_box" name="{$name}" value="1" {if $value != 0}checked="checked"{/if}>
|
||||
{$label}
|
||||
</label>
|
||||
</div>
|
||||
@@ -129,19 +129,21 @@
|
||||
<label for="price_without_tax" class="control-label">{$label} : </label>
|
||||
|
||||
<div class="input-group">
|
||||
<input {if !$show_pricing_fields}readonly{/if} data-price-type="without-tax" data-rel-price="price_with_tax" type="text" id="price_without_tax" required="required" name="{$name}" class="automatic_price_field form-control" value="{$value}" title="{$label}" placeholder="{intl l='Price excl. taxes'}">
|
||||
<input {if !$show_pricing_fields}readonly{/if} data-pse-id="{$default_product_sale_element_id}" data-price-type="price-without-tax" data-rel-price="price_with_tax" type="text" id="price_without_tax" required="required" name="{$name}" class="price_field automatic_price_field form-control" value="{$value}" title="{$label}" placeholder="{intl l='Price excl. taxes'}">
|
||||
<span class="input-group-addon">{$currency_symbol}</span>
|
||||
</div>
|
||||
</div>
|
||||
{/form_field}
|
||||
|
||||
<div class="form-group">
|
||||
<label for="price_with_tax" class="control-label">{intl l="Product price including taxes"} : </label>
|
||||
<div class="input-group">
|
||||
<input {if !$show_pricing_fields}readonly{/if} data-price-type="with-tax" data-rel-price="price_without_tax" type="text" id="price_with_tax" name="price_with_tax" class="automatic_price_field form-control" value="" title="{intl l='Product price including taxes'}" placeholder="{intl l='Price incl. taxes'}">
|
||||
<span class="input-group-addon">{$currency_symbol}</span>
|
||||
</div>
|
||||
</div>
|
||||
{form_field form=$form field='price_with_tax'}
|
||||
<div class="form-group">
|
||||
<label for="price_with_tax" class="control-label">{intl l="Product price including taxes"} : </label>
|
||||
<div class="input-group">
|
||||
<input {if !$show_pricing_fields}readonly{/if} data-pse-id="{$default_product_sale_element_id}" data-price-type="price-with-tax" data-rel-price="price_without_tax" type="text" id="price_with_tax" name="{$name}" class="price_field automatic_price_field form-control" value="{$value}" title="{$value}" placeholder="{intl l='Price incl. taxes'}">
|
||||
<span class="input-group-addon">{$currency_symbol}</span>
|
||||
</div>
|
||||
</div>
|
||||
{/form_field}
|
||||
|
||||
{module_include location='product_details_pricing_form'}
|
||||
</div>
|
||||
@@ -203,19 +205,21 @@
|
||||
<label for="sale_price_without_tax" class="control-label">{$label} : </label>
|
||||
|
||||
<div class="input-group">
|
||||
<input {if !$show_pricing_fields}readonly{/if} data-price-type="without-tax" data-rel-price="sale_price_with_tax" type="text" id="sale_price_without_tax" required="required" name="{$name}" class="automatic_price_field form-control" value="{$value}" title="{$label}" placeholder="{intl l='Product price'}">
|
||||
<input {if !$show_pricing_fields}readonly{/if} data-pse-id="{$default_product_sale_element_id}" data-price-type="sale-price-without-tax" data-rel-price="sale_price_with_tax" type="text" id="sale_price_without_tax" required="required" name="{$name}" class="price_field automatic_price_field form-control" value="{$value}" title="{$label}" placeholder="{intl l='Product price'}">
|
||||
<span class="input-group-addon">{$currency_symbol}</span>
|
||||
</div>
|
||||
</div>
|
||||
{/form_field}
|
||||
|
||||
{form_field form=$form field='sale_price_with_tax'}
|
||||
<div class="form-group">
|
||||
<label for="sale_price_with_tax" class="control-label">{intl l="Sale price including taxes"} : </label>
|
||||
<label for="sale_price_with_tax" class="control-label">{$label} : </label>
|
||||
<div class="input-group">
|
||||
<input {if !$show_pricing_fields}readonly{/if} data-price-type="with-tax" data-rel-price="sale_price_without_tax" type="text" id="sale_price_with_tax" name="sale_price_with_tax" class="automatic_price_field form-control" value="" title="{intl l='Sale price including taxes'}" placeholder="{intl l='Sale price incl. taxes'}">
|
||||
<input {if !$show_pricing_fields}readonly{/if} data-pse-id="{$default_product_sale_element_id}" data-price-type="sale-price-with-tax" data-rel-price="sale_price_without_tax" type="text" id="sale_price_with_tax" name="sale_price_with_tax" class="price_field automatic_price_field form-control" value="{$value}" title="{$label}" placeholder="{intl l='Sale price incl. taxes'}">
|
||||
<span class="input-group-addon">{$currency_symbol}</span>
|
||||
</div>
|
||||
</div>
|
||||
{/form_field}
|
||||
|
||||
{form_field form=$form field='onsale'}
|
||||
<div class="form-group {if $error}has-error{/if}">
|
||||
|
||||
@@ -275,48 +275,83 @@ $(function() {
|
||||
});
|
||||
|
||||
// In details tab, process exchange rate usage checkbox changes
|
||||
$('use_exchange_rate_box').change(function(ev) {
|
||||
$('.')
|
||||
$('.use_exchange_rate_box').change(function(ev) {
|
||||
|
||||
if ($(this).is(':checked')) {
|
||||
|
||||
var pse_id = $(this).data('pse-id');
|
||||
|
||||
$('.price_field').prop('readonly', true);
|
||||
|
||||
// Reload prices
|
||||
$.ajax({
|
||||
url : '{url path="/admin/product/load-converted-prices"}',
|
||||
data : {
|
||||
product_sale_element_id : pse_id,
|
||||
currency_id : {$edit_currency_id}
|
||||
},
|
||||
type : 'get',
|
||||
dataType : 'json',
|
||||
success : function(json) {
|
||||
console.log(json);
|
||||
|
||||
$('input[data-pse-id="'+pse_id+'"][data-price-type="price-with-tax"]').val(json.price_with_tax);
|
||||
$('input[data-pse-id="'+pse_id+'"][data-price-type="price-without-tax"]').val(json.price_without_tax);
|
||||
$('input[data-pse-id="'+pse_id+'"][data-price-type="sale-price-with-tax"]').val(json.sale_price_with_tax);
|
||||
$('input[data-pse-id="'+pse_id+'"][data-price-type="sale-price-without-tax"]').val(json.sale_price_without_tax);
|
||||
},
|
||||
error : function(jqXHR, textStatus, errorThrown) {
|
||||
alert("{intl l='Failed to get converted prices. Please try again.'} (" +errorThrown+ ")");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
else {
|
||||
$('.price_field').prop('readonly', false)
|
||||
}
|
||||
});
|
||||
|
||||
function update_price(price, price_type, dest_field_id) {
|
||||
var tax_rule_id = $('#tax_rule_field').val();
|
||||
|
||||
if (tax_rule_id != "") {
|
||||
|
||||
var operation;
|
||||
|
||||
if (price_type.indexOf('with-tax') != -1)
|
||||
operation = 'from_tax';
|
||||
else if (price_type.indexOf('without-tax') != -1)
|
||||
operation = 'to_tax';
|
||||
else
|
||||
operation = '';
|
||||
|
||||
$.ajax({
|
||||
url : '{url path="/admin/product/calculate-price"}',
|
||||
data : {
|
||||
price : price,
|
||||
action : operation,
|
||||
product_id : {$product_id}
|
||||
},
|
||||
type : 'get',
|
||||
dataType : 'json',
|
||||
success : function(json) {
|
||||
$('#' + dest_field_id).val(json.result);
|
||||
},
|
||||
error : function(jqXHR, textStatus, errorThrown) {
|
||||
alert("{intl l='Failed to get prices. Please try again.'} (" +errorThrown+ ")");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Automatic update of price fields: any change in the taxed (resp. untaxed) price
|
||||
// will update the untaxed (resp. taxed) one
|
||||
$('.automatic_price_field').typeWatch({
|
||||
captureLength: 1,
|
||||
callback: function () {
|
||||
|
||||
var tax_rule_id = $('#tax_rule_field').val();
|
||||
|
||||
if (tax_rule_id != "") {
|
||||
var priceType = $(this).data('price-type');
|
||||
var dest_field_id = $(this).data('rel-price');
|
||||
|
||||
var operation;
|
||||
|
||||
if (priceType == 'with-tax')
|
||||
operation = 'from_tax';
|
||||
else if (priceType == 'without-tax')
|
||||
operation = 'to_tax';
|
||||
else
|
||||
operation = '';
|
||||
|
||||
$.ajax({
|
||||
url : '{url path="/admin/product/calculate-price"}',
|
||||
data : {
|
||||
price : $(this).val(),
|
||||
action : operation,
|
||||
tax_rule_id : $('#tax_rule_field').val()
|
||||
},
|
||||
type : 'get',
|
||||
dataType : 'json',
|
||||
success : function(json) {
|
||||
$('#' + dest_field_id).val(json.result);
|
||||
}
|
||||
});
|
||||
}
|
||||
update_price($(this).val(), $(this).data('price-type'), $(this).data('rel-price'));
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user