When the stock market is falling, you may not exactly feel like buying stocks. But it's actually a great moment to invest. That's because you frequently can get in on top companies for a bargain. During these times, investors worry about companies linked to consumer spending. So, retailers and others dependent on the consumer's wallet often suffer the most.

The strongest of these companies are also the ones with potential to soar once spending recovers. And some retailers -- those with unique business models, for example -- actually hold up pretty well in difficult markets. Here are two no-brainer ones that make great buys during a market plunge.

1. Amazon

Amazon (AMZN -0.09%) is a top company that's suffering now but has what it takes to surge once the economic situation improves.

A few elements have weighed on Amazon over the past year or so. Two have to do with the company itself. Amazon took a valuation loss on its stock investment in Rivian Automotive. And Amazon found itself with excess capacity after rapidly doubling its fulfillment network. The third element hurting Amazon is the general economic situation, including rising inflation.

The good news is all of these headwinds are temporary. And Amazon has taken the necessary steps to manage them. Importantly, the company is improving its cost structure, a move that should boost growth over the long haul.

In today's down market, Amazon's valuation has dropped to a bargain level. The company is trading at its lowest in relation to sales since 2015. During these difficult market times, Amazon's e-commerce and cloud-computing customers have cut spending. And that, along with higher costs due to inflation, has hurt Amazon's earnings.

AMZN PS Ratio Chart

AMZN PS Ratio data by YCharts

Once the market rebounds, though, the stock may take off. That's because Amazon should benefit from its leadership in e-commerce and cloud computing -- two markets forecast to grow in the double digits this decade. So, Amazon is the sort of stock that could find itself in the doldrums during a market plunge but has what it takes to climb over the long term.

2. Costco

Costco's (COST 1.15%) business model makes it an excellent stock to buy during a market decline. That's because the warehouse giant's earnings generally hold up well during tough times for three reasons: First, Costco's membership fees are what drives the company's profit.

Membership fees are high margin. Unlike Costco's products, they don't require logistics, storage, or other extras that add to expenses. Costco also has a great track record when it comes to keeping and growing membership. Generally, membership renewal rates worldwide top 90%.

Costco also has made great gains in the area of executive membership -- its higher-priced membership level. Today, these members account for 45% of paid members and 73% of sales globally.

Second, once people have paid for an annual membership, they'll want to get their money's worth, so they'll continue shopping regardless of the economic backdrop. Costco's earnings growth demonstrates that.

COST Revenue (Annual) Chart

COST Revenue (Annual) data by YCharts

Finally, Costco's bargain prices mean it actually is to shoppers' advantage to shop more than ever at Costco during tough times. Since Costco buys and sells in bulk -- and generates profit through membership fees -- it can afford to offer customers dirt cheap prices.

In spite of Costco's profile for success in tough economic times, the stock won't necessarily soar during these times. Investors still tend to shy away from companies linked to consumer spending. And that offers a buying opportunity.

Last year, Costco fell about 19%. And right now, the stock trades for 33 times forward-earnings estimates -- down from more than 45 last year. So, a down market may be the perfect time to get in on this solid consumer goods player.