For the sake of: If everyone every tries to google 'How to assign products to website or storeview programatically' Magento 1.9
Here's how, source from
app/code/core/Mage/Adminhtml/controllers/Catalog/Product/Action/AttributeController.php
Use
//...
$actionModel = Mage::getSingleton('catalog/product_action');
$productIds = $this->_getHelper()->getProductIds();
if ($websiteRemoveData) {
$actionModel->updateWebsites($productIds, $websiteRemoveData, 'remove');
}
if ($websiteAddData) {
$actionModel->updateWebsites($productIds, $websiteAddData, 'add');
}
Mage::dispatchEvent('catalog_product_to_website_change', array(
'products' => $productIds
));
//...
Where the $websiteAddData
and $websiteRemoveData
is defined as followed
$websiteRemoveData = $this->getRequest()->getParam('remove_website_ids', array());
$websiteAddData = $this->getRequest()->getParam('add_website_ids', array());
Meaning, you will need to specify an array of website ids.