It's no secret that 2022 has been a challenging year for e-commerce stocks. 

After a boom during the pandemic, consumer shopping habits are shifting back to brick-and-mortar channels and services like travel and restaurants, meaning the surging growth that many of these companies experienced in 2020 and 2021 has ground to a halt.

However, e-commerce still looks like a good bet over the long term. Online sales in the U.S. only make up about 15% of total retail sales according to the Census Bureau, meaning there's still a lot of market share left for e-commerce companies to gain, and the category is likely to return to steady growth once the current headwinds abate. With that in mind, here are three top e-commerce stocks to buy right now.

1. MercadoLibre

E-commerce is a global phenomenon, and MercadoLibre (MELI -0.45%) offers an excellent way to get exposure outside the U.S.

Since its 2007 initial public offering, the stock has returned over 5,000% as it's consistently put up high growth and expanded from its core e-commerce marketplace into adjacent businesses, much like Amazon has. The company entered digital payments with Mercado Pago, which is arguably its biggest business. It's also gotten into shipping through Mercado Envios, lending with Mercado Credito, and even asset management through Mercado Fondo, showing it's more than just an online retailer.

What's also impressive about the company is that it hasn't experienced the kind of slowdown that most American e-commerce companies have this year. Revenue in the second quarter jumped 57% on a currency-neutral basis to $2.6 billion with strong growth in both retail and payments. Gross merchandise volume, or the total dollar value of goods sold on the platform, rose 26% to $8.6 billion, while total payment volume through Mercado Pago jumped 84% to $30.2 billion. Profitability is also ramping up as operating income reached $250 million in the quarter, or a 9.6% margin. 

MercadoLibre has proven itself by fending off competition from Amazon, and its network of payments, logistics, and e-commerce businesses reinforce each other and give it a competitive advantage.

The stock is still down more than 50% from its peak during the pandemic so it has a lot of room to run if it continues to deliver these levels of growth.

2. GXO Logistics

Investors typically think of online retailers when they think of e-commerce, but there are other ways to gain exposure to the category, including logistics companies like GXO Logistics (GXO 2.93%). Spun off from XPO Logistics last year, GXO doesn't exclusively focus on e-commerce, but processing online orders and returns for e-commerce and omnichannel retailers has been a significant growth engine for the company and makes up most of its business today.

As a stand-alone company, GXO has delivered impressive growth in a mostly mature industry, especially at a time when so many businesses are experiencing macroeconomic headwinds. In its second quarter, organic revenue rose 20% to $2.2 billion, and the company posted adjusted earnings before interest, taxes, depreciation, and amortization (EBITDA) of $176 million, up 17% year over year.

GXO is the biggest pure-play contract logistics company in the world, and it expects to continue to deliver strong growth both organically and through acquisitions as it penetrates a fragmented industry. The company has advantages in automation and technology, including innovations like collaborative robots that help its customers save money and ship goods more efficiently.

The company looks well positioned to benefit from both the secular growth in e-commerce and its own competitive advantages in logistics.

3. Farfetch

Like a number of e-commerce stocks, Farfetch (FTCH 3.45%) has gotten beaten up this year with the stock down 85% from its peak during the pandemic. Looking at its recent results, it's easy to see why shares of the online luxury fashion company have plunged.  

In the second quarter, gross merchandise volume increased just 1.3%, or 7.6% in constant currency, to $1.02 billion, while revenue rose 10.7%, or 20.7% in constant currency, to $579.3 million. On the bottom line, its adjusted EBITDA loss deepened to $24.2 million.

Farfetch is facing a number of headwinds, including the loss of sales in Russia after it pulled out of that market, lockdowns in China, a strong U.S. dollar, high inflation in much of the world, and difficult comparisons with the earlier stages of the pandemic.

Despite those headwinds, Farfetch's competitive strengths remain intact as the company has a broad assortment of luxury brands on its website. It has also received investments from Alibaba and Cartier parent Richemont, which have helped it in China and other parts of the world. Through Farfetch Platform Solutions, the company also has a software suite to help luxury brands run their own e-commerce businesses, making it something like Shopify for the luxury sector.

Though its recent numbers look weak, they should improve as the headwinds in e-commerce fade and the Chinese market reopens from COVID-induced lockdowns. If the company can get back to its pre-pandemic growth trajectory, the current discount on the stock price won't last for long.