Here's the answer:
“estaba comprando su regalo cuando entró en la tienda”
Watch a real native speaker say it:
Here's how it sounds in a textbook:
Fun fact: the hundreds of thousands of people learning Spanish with Memrise get this phrase correct 95.25% of the time!