Recently, I needed to associate a large number of products with a specific “store” in Magento. Rather than go through each product individually, I thought it might be quicker to update them programmatically via a script.

To simplify the script for an example, I’m going to grab all of the products, and here, I’m going to set them to simply the default website we’ve got set up.

The setWebsiteIds() function takes an array of integers for its input, so you can associate a product with multiple websites at once if needs-be.

If you need to retreive a list of your website ids or store ids from the database via script, Mage::App has the function you’re looking for:

Image Credit: Jims_photos