Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Hide Magento 1 products with configurable parents
<?php
require_once 'abstract.php';
class Hide_Children_Products extends Mage_Shell_Abstract {
/**
* Hide products having at least one configurable parent
*/
public function run()
{
$products = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('type_id', array('eq' => 'configurable'));
foreach ($products as $product) {
$product = Mage::getModel('catalog/product')->load($product->getId());
$children = $product->getTypeInstance()->getUsedProducts($product);
foreach ($children as $child) {
if ($product->getStatus() &&
$product->getVisiblity() != Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE &&
$child->getVisibility() != Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE
) {
$child = Mage::getModel('catalog/product')->load($child->getId());
$this->output($child->getName());
$child->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE);
$child->save();
}
}
}
}
}
$shell = new Hide_Children_Products();
$shell->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.