Recently I upgraded magento on test server from 1.4.1.1 to 1.7.0.2
Previously all products are Virtual Products, no real shipping.
I upgraded magento through shell and it went smooth except this problem:
Old products are no way visible (either in frontend or backend) but they are visible in crosssells/related products when adding a new products (All products are visible only here)
I can edit any product by accessing url index.php/admin/catalog_product/edit/id/[id]
Even after saving/editing product, it is not visible on admin/frontend.
Category count is working fine.
When I added a new product, it is working fine. (With continuing id)
Tried full clearing of var folder and it's contents, reset file permissions, emptied database log tables and did everything that I know, but nothing is useful.
There are about 4500 products which I can't afford loosing. Please help me to show the correctly.
Some improvement:
After comparing this database with a newly created database, I found that, in the table catalog_product_entity_int
there is no entry related to attribute visibility
. Manually adding them to table with store id set to admin fixed the problem. But trying to do it through php code for all products. Tried the following code but is not working:
<?php
require_once("app/Mage.php");
$store_id = '0';
Mage::app()->setCurrentStore($store_id);
$productModel = Mage::getModel('catalog/product');
$products = $productModel->getCollection()->getAllIds();
foreach($products as $productId)
{
$product = $productModel->load($productId);
$product->setVisibility(4);
$product->save();
echo $productId.' Finished<br>';
}
?>
But the above code is not working. Any help????
For some reason, above code didn't worked. So I used custom code to insert values directly into databse.
<?php
$con = mysql_connect($host, $user, $pass);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($db, $con);
$sql=mysql_query("SELECT DISTINCT(entity_id) AS pid FROM magentocatalog_product_entity_int ORDER BY entity_id DESC;");
while($row = mysql_fetch_array($sql)) {
if ($row['pid']<4152) { //Condition for Mangento 1.7.0.2 version products, below this pid, all are Magento 1.4.1.1. version products.
$insquery=mysql_query("INSERT INTO `magentocatalog_product_entity_int` (`value_id`, `entity_type_id`, `attribute_id`, `store_id`, `entity_id`, `value`) VALUES ('', 4, 89, 0, ".$row['pid'].", 0);");//89 is attribute id and 4 is default value for showing in admin. Tested against newly created product which has these values.
echo $row['pid']." Finished<br />";
}
}
mysql_close($con);
?>
And products are now showing in admin but not in stores. So modified the above code to add values for each store. Problem is fixed. But still want to make sure is it was the right approach??
Note: In my Magento 1.4.1.1, the above two attributes can be removed from Attibute set, but not in Magento 1.7.0.2.