Skip to content

Instantly share code, notes, and snippets.

@Tomasz-Silpion
Created February 15, 2018 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tomasz-Silpion/039a022f2c7867a630360bb2a7d8e747 to your computer and use it in GitHub Desktop.
Save Tomasz-Silpion/039a022f2c7867a630360bb2a7d8e747 to your computer and use it in GitHub Desktop.
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