P
P
Pavel2019-12-27 10:37:01
JavaScript
Pavel, 2019-12-27 10:37:01

How to correctly calculate the total amount?

Hello. Can anyone give me an idea how to correctly calculate the total amount on the product page?

The screenshot shows that the total cost is calculated at the first price, if we order the entire model range, is it possible to somehow take into account the moment that, under some conditions, the total amount should already be calculated at the second price, and so on?
You need at least a direction :)
This is opencart - can someone tell me where to ajax to get this calculation from cms (everything is considered when adding to the cart) - in fact, this is probably the best option?
5e05b2cc0a4a4375578241.png
As a last resort, you can suggest how to transfer all the data (prices - go in a cycle, sizes, price limits) to vue.
I will be immensely grateful to you ...

I will add a bit of code that I use.
This is getting the price at which we consider:

if ( sum <= firstFrom) {
        return parseInt($('.prices-row').find('.price1').text());
    } else if (sum > firstFrom && sum <= secondFrom) {
        return parseInt($('.prices-row').find('.price2').text());
    } else if (sum > secondFrom && sum <= thirdFrom) {
        return parseInt($('.prices-row').find('.price3').text());
    } else if (sum >= thirdFrom ) {
        return parseInt($('.prices-row').find('.price4').text());
    }

This is the calculation itself, when you press the plus
$('#buy-all-total').text(  currentPrice(sum) * ( parseInt($input.val()) * parseInt($('.prices-top .qty-input').length) ) );

where, the current price is multiplied by (number of sets multiplied by the number of goods in the set)
Everything works fine - if you click again when currentPrice() receives an amount of 6000 rubles, it, of course, gives the next discounted price. But, here's how I take it into account on the first click. I do not exclude that my approach is fundamentally wrong, tell me how then to calculate everything correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shamanov, 2019-12-28
@SilenceOfWinter

in php form json with data in insert it into js

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question