You can implement merge baskets using existing Script API. A recommended approach is to append to existing SFRA/SG controllers where a shopper can log in and implement functionality to then merge baskets as shown in the scripts below.
In a custom SFRA/SG cartridge, extend the Login functionality using server.extend() and server.append() functions like so:
*/cartridges/controllers/Account.js