Autokalkulacja cen

Miejsce na wszelkie dyskusje odnośnie problemów technicznych i ewentualnych pytań z rozbudowaniem systemu w plikach i skryptach Opencart, a które nie dotyczą instalacji.

Autokalkulacja cen

Postprzez martens » 30 sty 2015, o 10:12

Witam
Posiadam Opencart w wersji 1.5.6.4 i mam zainstalowany skrypt do autokalkulacji ceny na stronie z produktem.
Oparte to jest na vqmod. (wersji 2.5.1).
Wszystko działa w porządku.
Postanowiłem przejść na nową wersję opencarta 2.0.1.1 i niestety mój skrypt przestał działać.
Pozmieniałem w pliku, aby było dostosowane do nowszej wersji, ale to nic nie spowodowało.
Żadne błędy nie są pokazywane.
Czy możecie mi powiedzieć, jakie są różnice pomiędzy tymi 2 wersjami?
Dlaczego może mi to nie działać?
Proszę o pomoc.
Pozdrawiam
Krzysztof
martens
 
Posty: 12
Dołączył(a): 25 cze 2013, o 09:01

Re: Autokalkulacja cen

Postprzez staniapl » 30 sty 2015, o 11:29

Po pierwsze
Pamiętaj, że wersja > 2 nie można uznać za stabilną (przynajmniej dla mnie), jak również z tego co wiem ma trochę inną infrastrukturę plików.

Po drugie
Czy masz zainstalowany vqmod menager pod wersję 2 ? - trzeba pamiętać, że błędy (nieodnalezione linie) z modyfikacji Vqmod nie zapisują się w dzienniku błędów !
Po trzecie
jeśli używasz vqmod menagera i nie widzisz błędów, sprawdź czy w modyfikacji są zapisy error log - możliwe, że skrypt się nie wykonuje nie informując o błędach.
Avatar użytkownika
staniapl
 
Posty: 631
Dołączył(a): 13 lut 2012, o 19:47
Lokalizacja: Zambr?w, Nowe Piekuty

Re: Autokalkulacja cen

Postprzez martens » 30 sty 2015, o 11:35

Witaj
Jak dałem skrypt bezpośrednio do wersji 2 to pojawiły się błędy, które usunąłem.
Teraz nie ma nic. Poza tym zainstalowałem vqmoda dla opencarta v 2.0.1.1 oraz vqmenagera v.3.0
Mam jeszcze inny skrypt, który mi działa bez problemu.
I co może być nie tak?
martens
 
Posty: 12
Dołączył(a): 25 cze 2013, o 09:01

Re: Autokalkulacja cen

Postprzez 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.
martens
 
Posty: 12
Dołączył(a): 25 cze 2013, o 09:01

Re: Autokalkulacja cen

Postprzez martens » 2 lut 2015, o 12:30

Witam
Czy ktoś jest w stanie mi pomóc w moim problemie?
Na pewno jest mały myk, ale nie mogę go znaleźć.
Czekam na pomoc.
Pozdrawiam
martens
 
Posty: 12
Dołączył(a): 25 cze 2013, o 09:01

Re: Autokalkulacja cen

Postprzez staniapl » 2 lut 2015, o 23:45

Ja bym zrobił tak,
wrzuć ten skrypt do catalog/view/theme/szablon/template/product/product.tpl gdzieś na dole strony

potem w firebugu zobacz jakie błędy zwraca konsola i będzie wiadomo co się dzieję
Avatar użytkownika
staniapl
 
Posty: 631
Dołączył(a): 13 lut 2012, o 19:47
Lokalizacja: Zambr?w, Nowe Piekuty

Re: Autokalkulacja cen

Postprzez martens » 3 lut 2015, o 11:25

Witaj
Dzięki za informację.
Zrobiłem jak napisałeś, ale Firebud pokazuje mi tylko ostrzeżenia.
Nie ma żadnych błędów.
I gdzie szukać przyczyny?
Pozdrawiam
martens
 
Posty: 12
Dołączył(a): 25 cze 2013, o 09:01


Powrót do Pomoc techniczna przy Opencart

Kto przegląda forum

Użytkownicy przeglądający ten dział: Brak zidentyfikowanych użytkowników i 0 gości