Now, the models that the somewhat sophisticated supermarkets use don't fit on a spreadsheet, and really try to guess which items really are people's favorites, look at profit margins, and risks of people just going to a different supermarket altogether because the competitor down the street still has your favorite, or charges 30% less for it. They check what happens when a product isn't in stock, or when a competitor has a significant discount. It's a difficult optimization problem, given all the differences among people's shopping lists.
Having a favorite product get discontinued sucks: It happens to me at least a couple of times a year, and sometimes straight from the manufacturer, so I can't even buy it online. But don't imagine that every supermarket out there is run by teams swimming in money. It's an extremely competitive business with many players, and there's not that much of a difference between the way the small chains run their operations today and having to close down because the lower prices of a larger competitor dropped sales just enough that they are losing money.