Whenever I am facing a problem like this my approach is to think "how would I do it manually?"

Afterall, computers are only useful for performing simple tasks (we can do ourselves) at a very fast rate.

In this case, I would expect that when I am viewing my cart (all the goods I have assembled to buy) the total would be available. And so, it seems the time to devise a total is [only] when you are displaying the entire cart of items. In that view/page which displays the cart you can add the individual prices (and calculate tax, shipping, etc).