For this kind of functionality I would create a template function or operator which fetches the information from the bakset. You can also cache this information in the session or use the cache block function.
There is already written one template function which returns the basket as an array. This function is defined in the shop module and is called basket. We've used this function in a similar setup as you describe.