Blog » Quickly Map Manufacturers to Store in ASPDNSF Multi-Store solution

Quickly Map Manufacturers to Store in ASPDNSF Multi-Store solution

image I’m sure you’ve been there before. You (or your customer) have gone in and added all your products and defined which products go with which stores but then decided after the fact that you want to have a manufacturer’s page (or menu) that shows all the manufacturers of products that  exist in a give store on your Multi-Store solution.

What’s the solution? Enable all the Manufacturer’s for a given store? No, then you’ll end up with empty Manufacturers on the manufacturers listing page.

Do you slog through each store’s list of products to find the manufacturers and map them one by one as you encounter a new one? No, as not only is that too time consuming, this human process is far to ripe for chance of error.

The solution?

You can run a SQL command that will generate a series of insert commands that you can then paste back into SQL Mangler (I mean Microsoft SQL Server Management Studio) or Visual Studio in order to quickly add the mappings you need. Here is some sample code and it’s output:

Select DISTINCT  'Insert INTO EntityStore (StoreID, EntityID, EntityType) Values (4, ' + RTrim(Cast(ManufacturerId as char)) + ', ''manufacturer'')' as InsertCommand from ProductManufacturer WHERE ProductID IN (
    Select ProductID from ProductStore where StoreID=4
)
Note that in the example above, the number 4 is used in two places and this represents the StoreID that I want to affect these changes for.
The output from the above command will give you the following (note that the results below are for example only. Do not run THESE on your site)
Insert INTO EntityStore (StoreID, EntityID, EntityType) Values (4, 10, 'manufacturer')
Insert INTO EntityStore (StoreID, EntityID, EntityType) Values (4, 36, 'manufacturer')
Insert INTO EntityStore (StoreID, EntityID, EntityType) Values (4, 39, 'manufacturer')
Insert INTO EntityStore (StoreID, EntityID, EntityType) Values (4, 40, 'manufacturer')
Insert INTO EntityStore (StoreID, EntityID, EntityType) Values (4, 59, 'manufacturer')
Insert INTO EntityStore (StoreID, EntityID, EntityType) Values (4, 6, 'manufacturer')
Insert INTO EntityStore (StoreID, EntityID, EntityType) Values (4, 7, 'manufacturer')
Insert INTO EntityStore (StoreID, EntityID, EntityType) Values (4, 8, 'manufacturer')
Insert INTO EntityStore (StoreID, EntityID, EntityType) Values (4, 9, 'manufacturer')

As always, usual caveat’s apply:

  • Always back up your database first
  • Always test in a non-live environment before running batch commands like this
  • I cannot be held responsible for the failure of this code in your environment!

Any questions? Have tried something similar? If so, tell us about it in the comments below!

Michael Gibbs
Stalk Me...
Latest posts by Michael Gibbs (see all)