The story
From the three principal parts of a flintlock. The explanation that it refers to all of a shopkeeper’s possessions—the lock to the door, the stock in trade and the items stored in barrels—is fanciful. First attested in an 1817 letter by the Scottish novelist Walter Scott (see quotation).
Etymology from Wiktionary, CC BY-SA 4.0.