Walmart's (WMT 0.92%) stock got slammed Tuesday after the retailer slashed its profit guidance for the second quarter and the full year.

Mirroring earlier comments from Target and other retailers, Walmart said that inflation in areas like food and fuel was weighing on general merchandise categories like apparel and home goods. According to the retail giant, consumers are cutting back their spending on discretionary categories because prices for consumer staples have risen so much.

Walmart actually said sales growth was stronger than expected, with comparable sales at U.S. stores up 6% in the quarter, compared to its earlier guidance of 4% to 5%, due to higher prices in categories like food. It also called for overall net sales to increase by 7.5% in the quarter. However, the bottom line is clearly taking a hit from bloated inventory, supply chain challenges, inflation, and consumer spending challenges. Management called for operating income to decline 13% to 14% in the second quarter and 10% to 12% for the full year, excluding divestitures. 

The stock price fell 7.6% on the news, echoing a plunge back in May when the company came up short on the bottom line due to the impact of inflation.

A retail recession

Taken at face value, Walmart's guidance cut seems to imply that consumers are reeling from higher prices and cutting back in other areas, but the performance of consumer discretionary companies like McDonald's and Chipotle Mexican Grill dispels that notion. 

McDonald's, the world's biggest restaurant chain, reported comparable sales up 3.7% in the U.S., though operating income fell due to inflation in labor and commodities as well as restaurant closures in Russia and Ukraine. Chipotle, meanwhile, posted 10.1% comparable sales growth and expanded its operating margin from 13% to 15.3%, delivering strong profit growth even in an inflationary environment.

What McDonald's and Chipotle's sales growth seems to indicate is that consumers are still spending, but their spending has shifted from the pandemic era when they were stocking up on home goods and other products to help them manage through the depths of the stay-at-home period.

That, in combination with a spike in inventory due to supply chain challenges, is the main cause of Walmart's declining profits. 

Why the stock could be a smart buy

It's not surprising to see Walmart stock down on the guidance cut, but the challenges the company is facing are temporary in nature. The company's inventory levels will eventually normalize as price cuts to clear inventory are a major reason for falling profits, and macroeconomic factors like inflation will also moderate. 

Meanwhile, Walmart's strength in groceries, which represents a majority of sales from its U.S. stores, gives it an advantage over general merchandise retailers like department stores, who are likely dealing with similar inventory gluts in areas like apparel but can't offset it with grocery sales.

Recessions are generally tough on retailers, but Walmart tends to outperform during economic downturns because of its reputation for everyday low prices. A recession could actually be good for Walmart over the long term. And the supply chain and inflation challenges across the retail industry also give Walmart an opportunity to gain market share, given its strength in groceries. 

Additionally, since the challenges Walmart is facing are short-term, the company is likely to be in a better position a year from now when its inventory levels and consumer spending patterns have normalized.

Walmart stock fell to a two-year low on the news and now trades at a forward price-to-earnings ratio of 17.5. Once its performance starts to rebound, the stock could have significant upside potential given its growth in e-commerce, advertising, and competitive advantages like economies of scale and low prices.