Can somebody explain why setCategoryIds($ids)
changes the product's visibility to Catalog,Search
from whatever else it was (in my encounter, I was working with Search
-view products)?
Here's the code that makes all of the products in $categoryId
to have visibility Catalog,Search
after the save()
when they originally had Search
. I restored all of my products and tested it to verify as well.
$productCollection = Mage::getModel('catalog/category')->load($categoryId)
->getProductCollection()
->addAttributeToSelect(array('name','price','special_price','sku','small_image'));
foreach($productCollection as $product) {
$catIds = $product->getCategoryIds();
$product->setCategoryIds($catIds);
$product->save();
}