Walmart (NYSE:WMT) reported better-than-expected results for its second quarter as the coronavirus pandemic continued to have a major impact on consumer behavior. The retail giant experienced a surge in online orders as more people shopped from home, with e-commerce sales growing 97% year over year.

But one number that stood out, in particular, was the company's 63 basis point expansion in gross margin. Management pointed to a positive mix shift to general merchandise categories and fewer markdowns as reasons for the improvement.

The combination of strengthening gross margins and accelerating online sales growth shows what's possible for Walmart's e-commerce operations. But the company is poised to run into a massive headwind, and margins might shrink in the back half of the year.

Walmart store sign lit up at night.

Image source: Walmart

Pushing the online business toward profitability

Just as it did a quarter ago, management noted in its earnings release that its U.S. e-commerce losses had declined. The improving trend in e-commerce last quarter was closely tied to greater general merchandise sales, rather than grocery sales, which have largely fueled Walmart's e-commerce growth over the last couple of years.

Marc Lore, head of Walmart's domestic e-commerce unit, has long said groceries are practically a loss leader for the retailer's online business. The real money is in general merchandise, third-party seller services, and advertising. That's also where Amazon (NASDAQ:AMZN) makes its money in retail. So as Walmart expanded its online sales via the grocery category, it was also expanding its losses. 

The improved product mix showed up in Walmart's earnings results, but it still has a long way to go to reach e-commerce profitability. The company is working to increase its site's third-party sales, including via a recent partnership with Shopify, and it's improving its ad products and technology for vendors.

Third-party merchants account for more than half of Amazon's gross merchandise volume. The services that it sells them, including commissions on product listings and fulfillment services, generated $18.2 billion for the e-tailer last quarter. Meanwhile, revenue from Amazon's "other" category, which consists primarily of advertising, climbed by 41% to $4.2 billion despite a weak advertising environment. The growth of those line items has led to considerable margin expansion for Amazon over the last few years.

That's the model Lore is pursuing, but it starts with expanding the types of items Walmart shoppers are buying online.

The good times might not last

Management tempered investors' enthusiasm during the earnings call, noting that comparable-store sales growth slowed considerably in July to 4% from its pace earlier in the quarter. (In the U.S., its comparable sales grew 9.3% for the full quarter.) That slowing growth was particularly surprising after Costco recently reported 13.3% growth in comparable sales for July, an acceleration from the previous two months.

Walmart CFO Brett Biggs pointed to federal stimulus spending as a key driver of its results in the early part of the quarter. And with both the nature and the timeline of additional stimulus actions uncertain, Walmart can't count on the government putting extra money into people's pockets to keep fueling sales growth.

Additionally, management said the back-to-school sales season has been "choppy" as school districts across the country delay their reopenings or move to virtual classes. Parents don't need to buy as many backpacks, school uniforms, or new outfits for their kids if they aren't physically going to school.

Walmart+ is coming

The retail giant has high hopes that Walmart+, a new subscription service focused on same-day grocery delivery, will reinvigorate sales growth again. It planned to launch the service widely in July, but it has delayed that twice now as it focuses on adjusting to the impacts of the COVID-19 pandemic.

The program is designed to make customers more loyal to Walmart, similarly to how Amazon Prime created tens of millions of Amazon loyalists. Management hopes that offering consumers discounts on the things they buy repeatedly (groceries and fuel) will translate into them doing more of their general merchandise shopping at Walmart. 

Its second-quarter results indicate that people are indeed willing to buy more high-margin, non-grocery items from Walmart and Walmart.com. The retailer's new subscription service may be one way to encourage more of that behavior. But to expand its footprint in that space, it will likely have to take some of those sales away from Amazon, which has a 15-year head start with its loyalty program.

This article represents the opinion of the writer, who may disagree with the “official” recommendation position of a Motley Fool premium advisory service. We’re motley! Questioning an investing thesis -- even one of our own -- helps us all think critically about investing and make decisions that help us become smarter, happier, and richer.