I'd suggest you to use a PHP-based approach. In the .htaccess:
RewriteRule (.*) switchboard.php?orig_uri=$1
This captures the entire requested uri, and kind of forwards it to a central switchboard. Then in the switchboard.php you have access to the requested uri, which you can explode() along '/' signs, then look up the id-s associated with the names in you database.
$components = explode('/', $_GET['orig_uri']);
list( $merchant_name, $product_name ) = $components;
// get merchant id and product id from your database
// and serve suitable content by include-ing:
include 'merchant.php';
This is a simple method, and rather easy to scale. It also has the added advantage that no mod-rewrite magic is required.
Don't forget to add proper error-handling.
$1 = merchant-store-nameand$2 = product-name?$1,$2? What do they map to?