[ Поиск ] - [ Пользователи ] - [ Календарь ]
Полная Версия: Динамическая смена цены на странице
walters
Всем привет, столкнулся с задачей связанной с обновлением цены в интернет магазине.

Суть скрипта: есть стандартная цена товара например 300 и при выборе какой то опции из списка цена должна поменять например если выбрать ( 40 см (-50) ) то цена становится 250.

Есть код который работает отлично, но он работает в случае если только 1 товар на странице а нужно чтобы он работал например с 10 товарами на одной странице.


<div class="feat-opt" id="option_68" >
<div
id="option_232" class="option-68">
<select
name="option[232]">
<option
value="29" points="0" price_prefix="+" price="0.0000">60 см (+0.0000)
</option>
<option
value="30" points="0" price_prefix="-" price="50.0000">40 см (-50.0000)
</option>
<option
value="31" points="0" price_prefix="-" price="150.0000">30 см (-150.0000)
</option>
</select>
</div>
</div>

<div
class="price">
<span
class="pricespire" id="formated_price_68" price="350.000">350.00</span>
</div>




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)
{
return price;
}

function process_discounts(price, quantity)
{
return price;
}


animate_delay = 20;

main_price_final = calculate_tax(Number($('#formated_price_68').attr('price')));
main_price_start = calculate_tax(Number($('#formated_price_68').attr('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_68').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);
}


function recalculateprice()
{
var main_price = Number($('#formated_price_68').attr('price'));
var input_quantity = 0;
var special = 0;
var tax = 0;
var option_price = 0;

$('.option-68 input:checked,option:selected').each(function() {
if ($(this).attr('price_prefix') == '=') {
option_price += Number($(this).attr('price'));
main_price = 0;
special = 0;
}
}
);

$('.option-68 input:checked,option:selected').each(function() {
if ($(this).attr('price_prefix') == '+') {
option_price += Number($(this).attr('price'));
}
if ($(this).attr('price_prefix') == '-') {
option_price -= Number($(this).attr('price'));
}
if ($(this).attr('price_prefix') == 'u') {
pcnt = 1.0 + (Number($(this).attr('price')) / 100.0);
option_price *= pcnt;
main_price *= pcnt;
special *= pcnt;
}
if ($(this).attr('price_prefix') == '*') {
option_price *= Number($(this).attr('price'));
main_price *= Number($(this).attr('price'));
special *= Number($(this).attr('price'));
}
}
);

special += option_price;
main_price += option_price;
animateMainPrice(main_price);

}

$(document).ready(function() {
$('.option-68 select').bind('change', function() { recalculateprice(); });
recalculateprice();
});




Помогите пожалуйста решить проблему.
Спасибо.
Быстрый ответ:

 Графические смайлики |  Показывать подпись
Здесь расположена полная версия этой страницы.
Invision Power Board © 2001-2025 Invision Power Services, Inc.