I too bought my first pigs I owned myself from a pet store and I didn't know better. I do now!
As for your conundrum I think it's more of a theoretical concern rather than a realistic scenario to worry about. I just don't think it will happen where everyone on the planet would suddenly stop buying guinea pigs from pet stores. Instead it would be a more gradual decrease in demand, which decreases the need for supply, which decreases this kind of treatment and breeding of animals. In the scenario where a particular store stops selling animals they would probably just stop buying from the supplier and then sell off the remaining stock and kill any who don't get sold. The supplier would stop breeding as many animals, if any, since they can't make a profit. They might keep the remaining stock or kill them.
The killing element obviously sucks but if the industry continues it will cause more deaths long term than this one scenario and I think the discontinuation scenario is the lesser of two evils. For every one person who doesn't buy a guinea pig at a pet store it is one less demand and one less need for supply. When thousands of people do the same (and thousands of people do) that number of pigs who are not raised in these conditions dwindles. All those thousands of pigs were not born and raised in these awful conditions and those awful people who did this do not see that money for it.
This actually reminds me of something I mentioned on another forum regarding vegetarianism and how what a single person does, does matter. I pulled out some stats for that where one person eats about 7000 animals in their lifetime. There are 7.3 million vegetarians in the US so that's 51.1 billion animals who were never raised and killed, who did not add to excessive water use, environmental destruction, and climate change.
Similarly, there are probably millions of people who adopt rather than buy, the above number gives an indication of what kind of effect it can have when individuals choose to not add to an industry. Every person counts and it all adds up. Pigs will just never get bred as the demand dwindles. There's probably enough accidental litters to continue the species indefinitely. Even so, it's just not realistic to expect the industry to ever die down entirely, at least not in our lifetime. Which is unfortunate but what one person does, still matters. If you don't support these practices, don't give them your money, don't pay these people to abuse animals and voila you will, together with others, prevented thousands of these animals from ever being raised in these kind of conditions.