The recent gun violence at Walmart stores, with 20 killed by a gunman in El Paso, Texas, on Saturday and two killed in Mississippi days before, has drawn attention to the company’s complicated history with gun sales.

Firearms have long made up a key part of Walmart’s business. In addition to being the world’s largest retailer, the multinational company is often referred to as the world’s largest gun retailer.

Sam Walton, the founder of Walmart, was big on guns. An avid hunter, he opened his flagship store in Bentonville, Arkansas, specifically so he could be close to his in-laws’ quail-hunting ranch. Remington shotguns were his favourite, as retailer Field & Stream once noted. He was such a devout fan that the gun-maker issued a commemorative model in his name after he died.

But its relationship with firearm sales has been fickle in the 26 years since it made the landmark decision to stop carrying handguns. As economic and political winds have shifted, so have Walmart’s gun policies, though the general trend has been towards more restrictions.

In July, Walmart announced it would stop selling guns in New Mexico after a new state law went into effect.

El Paso mass shooting: 20 killed at Walmart store Show all 39 1 /39 El Paso mass shooting: 20 killed at Walmart store El Paso mass shooting: 20 killed at Walmart store CCTV images of the gunman identified as Patrick Crusius The 21 year old, as he entered the Cielo Vista Walmart store in El Paso. The gunman was armed with an assault rifle and opened fire on shoppers at a packed Walmart store, killing 20. KTSM 9/AFP/Getty El Paso mass shooting: 20 killed at Walmart store Law enforcement agencies respond The Texas city’s police chief said the assault on a Walmart store on Saturday, which left another 26 people wounded, was being investigated as a potential hate crime. AFP/Getty El Paso mass shooting: 20 killed at Walmart store Shoppers exit with their hands up Shoppers exit with their hands up after a mass shooting at a Walmart in El Paso, Texas, U.S. August 3, 2019. REUTERS/Jorge Salgado NO RESALES. NO ARCHIVES. STRINGER Reuters El Paso mass shooting: 20 killed at Walmart store FBI released a picture of gunman Patrick Crusius The police officially identified the 21-year-old white male from Allen, Texas, a Dallas suburb some 650 miles east of El Paso. FBI/AP El Paso mass shooting: 20 killed at Walmart store A woman reacts after the mass shooting The attack came just minutes after a far-right manifesto appeared online. If authentic, it would make it the third mass shooting this year announced in advance on the website, which often features far-right and racist content. Reuters El Paso mass shooting: 20 killed at Walmart store Law enforcement responds to the active shooter The racist four-page document, titled “The Inconvenient Truth”, calls the Walmart attack “a response to the Hispanic invasion of Texas” and expresses support for the gunman who killed 51 people at two mosques in Christchurch, New Zealand earlier this year. AFP/Getty El Paso mass shooting: 20 killed at Walmart store A shopper hiding with an old lady behind the return and exchanges counter as the shooting began. Aaron Castaneda/Reuters El Paso mass shooting: 20 killed at Walmart store Ambulances in the car park near the scene It is ranked as the eighth-deadliest mass shooting in modern US history, after a 1984 shooting in San Ysidro, California, that claimed 21 lives. AP El Paso mass shooting: 20 killed at Walmart store Kendall Long (left) comforts Kianna Long (right) who was in the freezer section of Walmart. EPA El Paso mass shooting: 20 killed at Walmart store epa07755367 Police stand at attention after a shooting at a Walmart in El Paso, Texas, USA, 03 August 2019. According to reports, at least one person was killed and at least 18 people injured and transported to local hospitals. One suspect is in custody. EPA/IVAN PIERRE AGUIRRE IVAN PIERRE AGUIRRE EPA El Paso mass shooting: 20 killed at Walmart store Shoppers exit with their hands up. Reuters El Paso mass shooting: 20 killed at Walmart store Shopping carts sit next to a curb after the shooting. EPA El Paso mass shooting: 20 killed at Walmart store El Paso Fire Medical personnel arrive at the scene. AP El Paso mass shooting: 20 killed at Walmart store Walmart employees react after. AP El Paso mass shooting: 20 killed at Walmart store A woman runs to police near the scene. AP El Paso mass shooting: 20 killed at Walmart store Several law enforcement agencies respond. AP El Paso mass shooting: 20 killed at Walmart store People arrive at MacArthur Elementary looking for family and friends as the school is being used a re-unification centre. AP El Paso mass shooting: 20 killed at Walmart store Residents Erica Rios, 36, and Alma Rios, 61, cry outside a reunification centre. AFP/Getty El Paso mass shooting: 20 killed at Walmart store People gather in Juarez, Mexico, in a vigil for the Mexican nationals who were killed. AP El Paso mass shooting: 20 killed at Walmart store A child takes part in a vigil in Ciudad Juarez AFP/Getty El Paso mass shooting: 20 killed at Walmart store Francisco Castaneda joins mourners taking part in a vigil at El Paso High School. Reuters El Paso mass shooting: 20 killed at Walmart store Presidential candidate and former congressman Beto O'Rourke, right, meets with mass shooting survivor, Rosemary, at University Medical Centre Beto O'Rourke Facebook via AP El Paso mass shooting: 20 killed at Walmart store From left, Melody Stout, Hannah Payan, Aaliyah Alba, Sherie Gramlich and Laura Barrios comfort each other during a vigil for victims of the shooting. AP El Paso mass shooting: 20 killed at Walmart store A sign is posted near the scene Getty Images El Paso mass shooting: 20 killed at Walmart store Police cars parked below the Walmart sign block a road outside while investigating. EPA El Paso mass shooting: 20 killed at Walmart store Sherie Gramlich reacts during a vigil. AP El Paso mass shooting: 20 killed at Walmart store A man places flowers at the site Reuters El Paso mass shooting: 20 killed at Walmart store People take part in a rally against hate a day after a mass shooting at the Walmart store Reuters El Paso mass shooting: 20 killed at Walmart store Lupe Lopez holds a picture of a victim during a vigil for victims AP El Paso mass shooting: 20 killed at Walmart store People take part in a rally against hate a day after a mass shooting at a Walmart store, in El Paso, Texas, U.S. August 4, 2019. REUTERS/Jose Luis Gonzalez JOSE LUIS GONZALEZ REUTERS El Paso mass shooting: 20 killed at Walmart store Elsa Mendoza Marquez, a Mexican schoolteacher who was married and the mother of two adult children, was one of the victims Getty El Paso mass shooting: 20 killed at Walmart store People with the Mexican flag and the US flag take part in a rally against hate a day Reuters El Paso mass shooting: 20 killed at Walmart store People raise their arms in the air during a vigil for victims AP El Paso mass shooting: 20 killed at Walmart store People react and embrace each other Getty El Paso mass shooting: 20 killed at Walmart store Women light candles at a make shift memorial at the site of a mass shooting EPA El Paso mass shooting: 20 killed at Walmart store Adria Gonzalez (centre) who is being hailed as a hero for leading some Walmart customers to safety, speaks to the crowd AFP/Getty El Paso mass shooting: 20 killed at Walmart store People hold up their phones AFP/Getty Images El Paso mass shooting: 20 killed at Walmart store Beto O'Rourke speaks to the crowd AFP El Paso mass shooting: 20 killed at Walmart store People react during a prayer and candle vigil organized by the city, after a shooting left 20 people dead at the Cielo Vista Mall WalMart in El Paso, Texas, on August 4, 2019. - A shooting at a Walmart store in Texas left multiple people dead. At least one suspect was taken into custody after the shooting in the border city of El Paso, triggering fear and panic among weekend shoppers as well as widespread condemnation. It was the second fatal shooting in less than a week at a Walmart store in the US and comes after a mass shooting in California last weekend. (Photo by Mark RALSTON / AFP)MARK RALSTON/AFP/Getty Images MARK RALSTON AFP/Getty

The law requires background checks for almost all private gun sales excluding antiques and those to relatives. And it also allows federally licensed gun sellers, such as Walmart, to provide background checks.

Walmart stopped sales because it could not furnish such checks for private sales. A situation in which private individuals might come into a Walmart with their own guns and request a background check could create a confusing or dangerous situation.

Last year, Walmart said it would raise the minimum age to buy a firearm or ammunition from 18 to 21 and remove products resembling assault-style rifles, such as airsoft guns and toys, from its inventory. The company said in a statement that it made the decision “in light of recent events” – an inescapable reference to the recent mass shooting at a Parkland, Florida, high school that left 17 people dead.

It was an unusual acknowledgement from Walmart, which has often attributed its changing positions on gun sales to market factors, even when other issues are present.

Walmart was late to the game in 1993 when it decided to stop selling handguns. Other major retailers such as Sears and JC Penney had pulled firearms from their shelves years earlier.

That year, national rates of gun murders and violent gun crimes reached record highs, according to Pew Research Centre. Walmart’s representatives said the company was ending handgun sales at its 2,000 stores because marketing surveys showed people felt “uncomfortable” seeing pistols displayed alongside clothing and household items.

Although the stores continued to carry shotguns and rifles, some worried that the move would erode the legacy of Walton, who died the previous year. “It was something Sam liked, a reflection of him, and they will look at it as taking something away from the tradition of Walmart,” Walter Loeb, president of Loeb Associates Inc, a retail consulting firm, told The New York Times.

Another major move came in 2006 when Walmart announced it would stop selling firearms entirely at all but a third of its US stores, which then numbered around 3,000. Again, the company said the decision was market-driven, citing “diminished customer relevancy” in the suburban and urban areas where Walmart was expanding. And again, hunting and firearms enthusiasts voiced concerns the company was drifting away from its outdoorsy roots.

Just two years later, Walmart made it harder to buy firearms at the stores that were still selling them. The company signed on to a plan led by then-New York mayor Michael Bloomberg that created a computerised log of purchases, introduced stringent inventory controls and set up systems to film every firearm sale.

Bloomberg-backed news website The Trace, which covers guns in America, said the move made Walmart’s policies tougher than the federal government’s background checks.

But when the economic recession took hold in 2009, Walmart’s sales slumped. And after a five-year hiatus at most of its locations, the company started filling up shelves with shotguns, rifles and ammunition, as The Wall Street Journal reported in 2011.

It was part of a larger push to bring back “heritage categories” such as sewing and outdoors equipment after Walmart’s attempts to carry more “upscale” products backfired, according to The Journal. Gun sales were also on the rise at that time, driven in part by fears of regulation by a Democratic administration. Half of Walmart’s nearly 4,000 stores, including some in urban areas, started selling firearms again.

Military man hailed as a hero after carrying as many children as he could to protect them from El Paso shooter

In 2012, after the mass shooting in Newtown, Connecticut, Walmart resisted calls to stop selling assault-style rifles such as the Bushmaster AR-15, which a gunman used to massacre children and teachers at Sandy Hook Elementary School. But the company did remove a listing on its website for the weapon out of sensitivity for the victims, a spokesperson told CNN at the time.

Meanwhile, in the weeks after the attack, semiautomatic rifles sold out at Walmart locations around the country. The company even had to ration ammunition sales after Barack Obama’s re-election.

Three years and numerous mass shootings later, however, Walmart did stop selling the AR-15 and similar weapons. The announcement came on the same day a television journalist and her videographer were shot and killed during a live broadcast in Virginia. Walmart said its decision was not related to that incident nor any other high-profile shooting.

“This is done solely on what customer demand was,” company spokesperson Kory Lundberg said. “We are instead focusing on hunting and sportsman firearms.”

Some retail experts were sceptical, among them retail consultant Burt Flickinger, who said the decision to drop assault-style rifles reflected a leadership that was paying closer attention to social issues. “It shows that the Walmart of this decade is quite different from the prior four decades,” Mr Flickinger said at the time.

Walmart CEO Doug McMillon, who has headed the company since 2014, has stressed he wants to cater to hunting and sports shooting – the things Walton enjoyed.

“Our focus as it relates to firearms should be hunters and people who shoot sporting clays and things like that,” he told CNN in 2015. “We believe in serving those customers, we have for a long time, and we believe we should continue to.”

That message came up again last year. In February 2018, two weeks after the mass shooting in Parkland, Walmart said in a statement it had “taken an opportunity to review our policy on firearm sales”.

“Our heritage as a company has always been in serving sportsmen and hunters,” the statement read, “and we will continue to do so in a responsible way.”

It is unclear whether the Walmart in El Paso sold firearms at the time of the shooting, or where the suspect obtained his weapon.