This product comes in an array and then through forych I deduce
The amount of goods in the cart:
$sum += $value->cart_amount * $value->price
I delete 1 item from the cart using ajax, and the total amount remains the same. (Changes only if the page is reloaded) Do you need to calculate the amount via ajax? and then output? Give or give an example.

    1 answer 1

    Make the Api method in PHP, which will change the value in the database, and then return the new value in the response to the request.

    The JS code will look something like this:

    $http.post('calc-sum', { goods }).then(result => { document.querySelector('#cost-block').innerHTML = result.sum; })

    That is, after processing requests, you insert into the DOM a new value of the amount based on the goods sent.

    • The amount is not recorded in the database. Just considers what's in the basket. - Andrii
    • @Andrii so it does not matter, you just return the amount in the answer body and that's it. - CoonJS
    • I don’t understand how $sum += $value->cart_amount * $value->price transfer to Ajax data this variable to be processed - Andrii