Created
February 15, 2018 13:16
-
-
Save Tomasz-Silpion/039a022f2c7867a630360bb2a7d8e747 to your computer and use it in GitHub Desktop.
Hide Magento 1 products with configurable parents
This file contains hidden or 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 | |
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