Created
November 23, 2016 20:03
-
-
Save jameshiggins/a83097e81644d86a4aefcd43b630d810 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(100); | |
$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_IN_SEARCH); | |
$_simple->save(); | |
printf("Product ID %s saved as 'Not Visible Individually'<br/>", $_simple->getId()); | |
} catch ( Exception $e ) { | |
print_r($e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment