przez martens » 30 sty 2015, o 15:20
Macie jakiś pomysł co mogę mieć nie tak?
Podsyłam skrypt. Może ktoś znajdzie coś, co jest nie tak.
<script type="text/javascript"><!--
function price_format(n)
{
c = <?php echo (empty($currency['decimals']) ? "0" : $currency['decimals'] ); ?>;
d = '<?php echo $currency['decimal_point']; ?>'; // decimal separator
t = '<?php echo $currency['thousand_point']; ?>'; // thousands separator
s_left = '<?php echo $currency['symbol_left']; ?>';
s_right = '<?php echo $currency['symbol_right']; ?>';
n = n * <?php echo $currency['value']; ?>;
//sign = (n < 0) ? '-' : '';
//extracting the absolute value of the integer part of the number and converting to string
i = parseInt(n = Math.abs(n).toFixed(c)) + '';
j = ((j = i.length) > 3) ? j % 3 : 0;
return s_left + (j ? i.substr(0, j) + t : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : '') + s_right;
}
function calculate_tax(price)
{
<?php // Process Tax Rates
if (isset($tax_rates) && $tax) {
foreach ($tax_rates as $tax_rate) {
if ($tax_rate['type'] == 'F') {
echo 'price += '.$tax_rate['rate'].';';
} elseif ($tax_rate['type'] == 'P') {
echo 'price += (price * '.$tax_rate['rate'].') / 100.0;';
}
}
}
?>
return price;
}
function process_discounts(price, quantity)
{
<?php
foreach ($dicounts_unf as $discount) {
echo 'if ((quantity >= '.$discount['quantity'].') && ('.$discount['price'].' < price)) price = '.$discount['price'].';'."\n";
}
?>
return price;
}
animate_delay = 20;
main_price_final = calculate_tax(Number($('#formated_price').attr('data-price')));
main_price_start = calculate_tax(Number($('#formated_price').attr('data-price')));
main_step = 0;
main_timeout_id = 0;
function animateMainPrice_callback() {
main_price_start += main_step;
if ((main_step > 0) && (main_price_start > main_price_final)){
main_price_start = main_price_final;
} else if ((main_step < 0) && (main_price_start < main_price_final)) {
main_price_start = main_price_final;
} else if (main_step == 0) {
main_price_start = main_price_final;
}
$('#formated_price').html( price_format(main_price_start) );
if (main_price_start != main_price_final) {
main_timeout_id = setTimeout(animateMainPrice_callback, animate_delay);
}
}
function animateMainPrice(price) {
main_price_start = main_price_final;
main_price_final = price;
main_step = (main_price_final - main_price_start) / 10;
clearTimeout(main_timeout_id);
main_timeout_id = setTimeout(animateMainPrice_callback, animate_delay);
}
<?php if ($special) { ?>
special_price_final = calculate_tax(Number($('#formated_special').attr('data-price')));
special_price_start = calculate_tax(Number($('#formated_special').attr('data-price')));
special_step = 0;
special_timeout_id = 0;
function animateSpecialPrice_callback() {
special_price_start += special_step;
if ((special_step > 0) && (special_price_start > special_price_final)){
special_price_start = special_price_final;
} else if ((special_step < 0) && (special_price_start < special_price_final)) {
special_price_start = special_price_final;
} else if (special_step == 0) {
special_price_start = special_price_final;
}
$('#formated_special').html( price_format(special_price_start) );
if (special_price_start != special_price_final) {
special_timeout_id = setTimeout(animateSpecialPrice_callback, animate_delay);
}
}
function animateSpecialPrice(price) {
special_price_start = special_price_final;
special_price_final = price;
special_step = (special_price_final - special_price_start) / 10;
clearTimeout(special_timeout_id);
special_timeout_id = setTimeout(animateSpecialPrice_callback, animate_delay);
}
<?php } ?>
function recalculateprice()
{
var main_price = Number($('#formated_price').attr('data-price'));
var input_quantity = Number($('input[name="quantity"]').attr('value'));
var special = Number($('#formated_special').attr('data-price'));
var tax = 0;
if (isNaN(input_quantity)) input_quantity = 0;
// Process Discounts.
<?php if ($special) { ?>
special = process_discounts(special, input_quantity);
<?php } else { ?>
main_price = process_discounts(main_price, input_quantity);
<?php } ?>
tax = process_discounts(tax, input_quantity);
<?php if ($points) { ?>
var points = Number($('#formated_points').attr('data-points'));
$('.option input:checked').each(function() {
points += Number($(this).attr('data-points'));
});
$('.option option:selected').each(function() {
points += Number($(this).attr('data-points'));
});
$('#formated_points').html(data-points);
<?php } ?>
var option_price = 0;
$('.option input:checked,option:selected').each(function() {
if ($(this).attr('price_prefix') == '=') {
option_price += Number($(this).attr('data-price'));
main_price = 0;
special = 0;
}
});
$('.option input:checked,option:selected').each(function() {
if ($(this).attr('price_prefix') == '+') {
option_price += Number($(this).attr('data-price'));
}
if ($(this).attr('price_prefix') == '-') {
option_price -= Number($(this).attr('data-price'));
special -= Number($(this).attr('data-price'));
tax -= Number($(this).attr('data-price'));
}
if ($(this).attr('price_prefix') == '*') {
option_price *= Number($(this).attr('data-price'));
main_price *= Number($(this).attr('data-price'));
special *= Number($(this).attr('data-price'));
}
});
special += option_price;
main_price += option_price;
<?php if ($special) { ?>
tax = special;
<?php } else { ?>
tax = main_price;
<?php } ?>
// Process TAX.
main_price = calculate_tax(main_price);
special = calculate_tax(special);
// ?????????????????, ???? ????? ????? ???? ? ?????????? ?? ??????????
//main_price *= input_quantity;
//special *= input_quantity;
//tax *= input_quantity;
// Display Main Price
//$('#formated_price').html( price_format(main_price) );
animateMainPrice(main_price);
<?php if ($special) { ?>
//$('#formated_special').html( price_format(special) );
animateSpecialPrice(special);
<?php } ?>
<?php if ($tax) { ?>
$('#formated_tax').html( price_format(tax) );
<?php } ?>
}
$(document).ready(function() {
$('.option input[type="checkbox"]').bind('change', function() { recalculateprice(); });
$('.option input[type="radio"]').bind('change', function() { recalculateprice(); });
$('.option select').bind('change', function() { recalculateprice(); });
$quantity = $('input[name="quantity"]');
$quantity.data('val', $quantity.val());
(function() {
if ($quantity.val() != $quantity.data('val')){
$quantity.data('val',$quantity.val());
recalculateprice();
}
setTimeout(arguments.callee, 250);
})();
recalculateprice();
});
//--></script>
Dzięki za pomoc.