If you’ve already picked up your copy of Pokemon Sun or Pokemon Moon then you’ll need to mark you calendar for December 5th. You’ll be able to get Magearna if you finish the story mode in Alola.
The mythical Pokemon Magearna is available “in-game,” when the main story for the game is completed. Once you finish the game head to Pokemon.com, then unlock the QR code using the QR scanning feature. And whala you’ll be rewarded with Magearna. The promotion is running December 5th-March 5th.