Magento: Programmatically added products do not appear in store until you load and save them in admin.

Ok, so you have written an import script to add a whole load of products into a store but they just don’t show on the front end.  There they are in the admin but not on the front end.  Here is one possible cause.

Did you set the website ID when adding them to Magento?  If you didn’t, then the products will not show in the frontend of the store as they are not technically assigned to the the website. However, the website id will be added when you load and save the product in the admin.

If you can’t, or don’t want to, update your import script but want to fix the problem for all the products in one hit then you could try something like this:

$products = Mage::getModel(‘catalog/product’)->getCollection()
->addAttributeToSelect(‘id’);

foreach($products as $product){
$product->setWebsiteIds(array(1))->save();
}

You may want to switch indexing to manual mode before you do this, to save some time, especially if you have a lot of products.  Remember to re-run your indexed and switch it back onto “index on save” if that is what you usually have.

 

Facebook Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Apply your human brain cells and complete this highly complicated maths problem *