2

I am programmatically importing a list of products in Magento 1.8.1.0.

Although the products are enabled they are not showing in the frontend pages (searches, list, ...).

This are my product attributes: *Grouped Products:

  • Status: Enabled
  • Visibility: Catalog, Search
  • Manage Stock: NO
  • They are in the correct categories
  • They are in the Main Website

*Simple Products:

  • Status: Enabled
  • Visibility: Not visible individually
  • Manage Stock: NO
  • Minimum Qty Allowed in Shopping Cart: 1
  • Maximum Qty Allowed in Shopping Cart: 10000
  • The price is set
  • They are in the Main Website

By manually disabling and then reenabling a product in the backend, the toggled product shows up. I created a script to disable and reenable all products and it seems to work locally (OSX) but not on my server (openSuse 11.4).

Is there something I can check in my import script to make it work without toggling all the product status?

EDIT: In the import script I am setting the store id and website like this:

Mage::app()->setCurrentStore($storeId);
$product = Mage::getModel('catalog/product')->setStoreId($storeId);
$product->setWebsiteIds(array(Mage::app()->getStore(true)->getWebsite()->getId()));

EDIT 2: This is the script that seems to fix the problem (by setting the again the website Ids it work also on the server)

$products = Mage::getModel('catalog/product')->getCollection();

    foreach($products as $product){
        $product->load();
        echo "Disabling product: ".$product->getSku()."\n";
        $product->setStatus(2);

        $product->save();

        $product2 = Mage::getModel('catalog/product')->load($product->getId());
        echo "Enabling product: ".$product->getSku()."\n";
        $product2->setWebsiteIds(array(Mage::app()->getStore(true)->getWebsite()->getId()));
        $product2->setStatus(1);

        $product2->save();
    }
7
  • once do re-index and flush your cache
    – Keyul Shah
    Jun 19, 2014 at 16:01
  • does you have multi website or multi store?
    – Keyul Shah
    Jun 19, 2014 at 16:02
  • already done from the backend page and it is not working Jun 19, 2014 at 16:03
  • I have one Website and 2 stores (1 disabled), however products are Enabled in both of them. In my import script I am importing the information in the default store (id=0) and then again in the English store for localization purposes. Jun 19, 2014 at 16:06
  • got prb when you import product via code then have you set websiteid and store id?
    – Keyul Shah
    Jun 19, 2014 at 16:07

1 Answer 1

1

OP noted that setting the website IDs seems to resolve the issue:

$products = Mage::getModel('catalog/product')->getCollection();

foreach($products as $product){
    $product->load();
    echo "Disabling product: ".$product->getSku()."\n";
    $product->setStatus(2);

    $product->save();

    $product2 = Mage::getModel('catalog/product')->load($product->getId());
    echo "Enabling product: ".$product->getSku()."\n";
    $product2->setWebsiteIds(array(Mage::app()->getStore(true)->getWebsite()->getId()));
    $product2->setStatus(1);

    $product2->save();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.