4 New version to process only 10 at a time
source | link

EDIT (browser version to process 10 products at a time)

Run this script in the browser as shell/makechildrennotvisible.php?page=1 and increment the page value each time until all products have been procesed. E.g.

www.example.com/shell/makechildrennotvisible.php?page=1
www.example.com/shell/makechildrennotvisible.php?page=2
www.example.com/shell/makechildrennotvisible.php?page=3

<?php
include_once '../app/Mage.php';
Mage::app()->setCurrentStore( Mage_Core_Model_App::ADMIN_STORE_ID );

// Get the current page from $_GET
$curPage = intval(Mage::app()->getRequest()->getParam('page'));
$curPage = $curPage < 1 ? 1 : $curPage;

// Get all configurable and grouped products
$products = Mage::getModel('catalog/product')
    ->getCollection()
    ->addAttributeToSelect('name')
    ->addAttributeToFilter('type_id', array('in' => array('configurable', 'grouped')))
    ->setPageSize(10);

$curPage = $curPage > $products->getLastPageNumber() ? $products->getLastPageNumber() : $curPage;
$products->setCurPage($curPage);

printf("Processing page %s of %s<br/>", $curPage, $products->getLastPageNumber());

// Loop each configurable product
foreach ($products as $_product) {
    // Get the child products for this product
    if ($_product->getTypeId() == 'configurable') {
        $simpleProducts = $_product->getTypeInstance(true)->getUsedProductIds($_product);
    } elseif ($_product->getTypeId() == 'grouped') {
        $simpleProducts = $_product->getTypeInstance(true)->getAssociatedProductIds($_product);
    }
    printf("Setting children of Product ID %s<br/>", $_product->getId());
    // Loop each child product
    foreach($simpleProducts as $_simpleID) {
        try {
            // Set associated product as not visible
            $_simple = Mage::getModel('catalog/product')->load($_simpleID);
            $_simple->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE);
            $_simple->save();
            printf("Product ID %s saved as 'Not Visible Individually'<br/>", $_simple->getId());
        } catch ( Exception $e ) {
            print_r($e);
        }
    }
}

EDIT (browser version to process 10 products at a time)

Run this script in the browser as shell/makechildrennotvisible.php?page=1 and increment the page value each time until all products have been procesed. E.g.

www.example.com/shell/makechildrennotvisible.php?page=1
www.example.com/shell/makechildrennotvisible.php?page=2
www.example.com/shell/makechildrennotvisible.php?page=3

<?php
include_once '../app/Mage.php';
Mage::app()->setCurrentStore( Mage_Core_Model_App::ADMIN_STORE_ID );

// Get the current page from $_GET
$curPage = intval(Mage::app()->getRequest()->getParam('page'));
$curPage = $curPage < 1 ? 1 : $curPage;

// Get all configurable and grouped products
$products = Mage::getModel('catalog/product')
    ->getCollection()
    ->addAttributeToSelect('name')
    ->addAttributeToFilter('type_id', array('in' => array('configurable', 'grouped')))
    ->setPageSize(10);

$curPage = $curPage > $products->getLastPageNumber() ? $products->getLastPageNumber() : $curPage;
$products->setCurPage($curPage);

printf("Processing page %s of %s<br/>", $curPage, $products->getLastPageNumber());

// Loop each configurable product
foreach ($products as $_product) {
    // Get the child products for this product
    if ($_product->getTypeId() == 'configurable') {
        $simpleProducts = $_product->getTypeInstance(true)->getUsedProductIds($_product);
    } elseif ($_product->getTypeId() == 'grouped') {
        $simpleProducts = $_product->getTypeInstance(true)->getAssociatedProductIds($_product);
    }
    printf("Setting children of Product ID %s<br/>", $_product->getId());
    // Loop each child product
    foreach($simpleProducts as $_simpleID) {
        try {
            // Set associated product as not visible
            $_simple = Mage::getModel('catalog/product')->load($_simpleID);
            $_simple->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE);
            $_simple->save();
            printf("Product ID %s saved as 'Not Visible Individually'<br/>", $_simple->getId());
        } catch ( Exception $e ) {
            print_r($e);
        }
    }
}
3 Fixed to work with both configurable and grouped
source | link

Here is an example script, now tested. Just change that sets the product collection filter tochildren of both grouped orand configurable as requiredproducts to Not Visible Individually.

Save this in ./shell/makechildrennotvisible.php and run from shell.

<?php
include_once 'app'../app/Mage.php';
Mage::app()->setCurrentStore( Mage_Core_Model_App::ADMIN_STORE_ID );

// Get all grouped/configurable and grouped products
$products = Mage::getModel('catalog/product')
    ->getCollection()
    ->addAttributeToSelect('name')
    ->addAttributeToFilter('type_id', array('eq''in' => array('configurable', 'grouped'))); // set this to grouped or configurable

// Loop each configurable product
foreach ($products as $_product) {
    // Get the associatedchild products for this product
    if ($_product->getTypeId() == 'configurable') {
        $simpleProducts = $_product->getTypeInstance(true)->getAssociatedProducts>getUsedProductIds($_product);
    } elseif ($_product->getTypeId() == 'grouped') {
        $simpleProducts = $_product->getTypeInstance(true)->getAssociatedProductIds($_product);
    }
    printf("Setting children of Product ID %s\r\n", $_product->getId());
    // Loop each associatedchild product
    foreach($simpleProducts as $_simple$_simpleID) {
        try {
            // Set associated product as not visible
            $_simple = Mage::getModel('catalog/product')->load($_simpleID);
            $_simple->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE);
            $_simple->save();
            printf("Product ID %s saved as 'Not Visible Individually'\r\n", $_simple->getId());
        } catch ( Exception $e ) {
            print_r($e);
        }
    }
 
}

Here is an example script, now tested. Just change the product collection filter to grouped or configurable as required.

<?php
include_once 'app/Mage.php';
Mage::app();

// Get all grouped/configurable products
$products = Mage::getModel('catalog/product')
    ->getCollection()
    ->addAttributeToSelect('name')
    ->addAttributeToFilter('type_id', array('eq' => 'grouped')); // set this to grouped or configurable

// Loop each product
foreach ($products as $_product) {
    // Get the associated products for this product
    $simpleProducts = $_product->getTypeInstance(true)->getAssociatedProducts($_product);
    // Loop each associated product
    foreach($simpleProducts as $_simple) {
        try {
            // Set associated product as not visible
            $_simple->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE);
            $_simple->save();
            printf("Product ID %s saved as 'Not Visible Individually'\r\n", $_simple->getId());
        } catch ( Exception $e ) {
            print_r($e);
        }
    }
 
}

Here is an example script that sets the children of both grouped and configurable products to Not Visible Individually.

Save this in ./shell/makechildrennotvisible.php and run from shell.

<?php
include_once '../app/Mage.php';
Mage::app()->setCurrentStore( Mage_Core_Model_App::ADMIN_STORE_ID );

// Get all configurable and grouped products
$products = Mage::getModel('catalog/product')
    ->getCollection()
    ->addAttributeToSelect('name')
    ->addAttributeToFilter('type_id', array('in' => array('configurable', 'grouped')));

// Loop each configurable product
foreach ($products as $_product) {
    // Get the child products for this product
    if ($_product->getTypeId() == 'configurable') {
        $simpleProducts = $_product->getTypeInstance(true)->getUsedProductIds($_product);
    } elseif ($_product->getTypeId() == 'grouped') {
        $simpleProducts = $_product->getTypeInstance(true)->getAssociatedProductIds($_product);
    }
    printf("Setting children of Product ID %s\r\n", $_product->getId());
    // Loop each child product
    foreach($simpleProducts as $_simpleID) {
        try {
            // Set associated product as not visible
            $_simple = Mage::getModel('catalog/product')->load($_simpleID);
            $_simple->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE);
            $_simple->save();
            printf("Product ID %s saved as 'Not Visible Individually'\r\n", $_simple->getId());
        } catch ( Exception $e ) {
            print_r($e);
        }
    }
}
2 Tested script
source | link

Here is an example script, untested but it should be rightnow tested. Just change the product collection filter to grouped or configurable as required.

<?php
include_once 'app/Mage.php';
Mage::app();

// Get all grouped/configurable products
$products = Mage::getModel('catalog/product')
    ->getCollection()
    ->addAttributeToSelect('name')
    ->addAttributeToFilter('type_id', array('eq' => 'grouped')); // useset this to grouped or configurable

// Loop each product
foreach ($products as $_product) {
    // Get the associated products for this product
    $simpleProducts = $_product->getTypeInstance(true)->getAssociatedProducts($_product);
    // Loop each associated product
    foreach($simpleProducts as $_simple) {
        try {
            // Set associated product as not visible
            $_simple->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE);
            $_simple->save();
            printf("Product ID %s saved as 'Not Visible Individually'\r\n", $_simple->getId());
        } catch ( Exception $e ) {
            print_r($e);
        }
    }

}

Here is an example script, untested but it should be right.

<?php
include_once 'app/Mage.php';
Mage::app();

// Get all grouped/configurable products
$products = Mage::getModel('catalog/product')
    ->getCollection()
    ->addAttributeToSelect('name')
    ->addAttributeToFilter('type_id', array('eq' => 'grouped')); // use grouped or configurable

// Loop each product
foreach ($products as $_product) {
    // Get the associated products for this product
    $simpleProducts = $_product->getTypeInstance(true)->getAssociatedProducts($_product);
    // Loop each associated product
    foreach($simpleProducts as $_simple) {
        try {
            // Set associated product as not visible
            $_simple->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE);
            $_simple->save();
        } catch ( Exception $e ) {
            print_r($e);
        }
    }

}

Here is an example script, now tested. Just change the product collection filter to grouped or configurable as required.

<?php
include_once 'app/Mage.php';
Mage::app();

// Get all grouped/configurable products
$products = Mage::getModel('catalog/product')
    ->getCollection()
    ->addAttributeToSelect('name')
    ->addAttributeToFilter('type_id', array('eq' => 'grouped')); // set this to grouped or configurable

// Loop each product
foreach ($products as $_product) {
    // Get the associated products for this product
    $simpleProducts = $_product->getTypeInstance(true)->getAssociatedProducts($_product);
    // Loop each associated product
    foreach($simpleProducts as $_simple) {
        try {
            // Set associated product as not visible
            $_simple->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE);
            $_simple->save();
            printf("Product ID %s saved as 'Not Visible Individually'\r\n", $_simple->getId());
        } catch ( Exception $e ) {
            print_r($e);
        }
    }

}
1
source | link