Last active
February 22, 2017 10:09
-
-
Save americkson/7032454 to your computer and use it in GitHub Desktop.
Magento - Set all categories to be an anchor
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
IMPORTANT NOTE: To have this work you cannot have Flat Catalog enabled | |
// ORIGINAL ----------------------- | |
<?php | |
error_reporting(E_ALL); | |
ini_set('display_errors', '1'); | |
// Load Up Magento Core | |
define('MAGENTO', realpath('')); | |
require_once(MAGENTO . '/app/Mage.php'); | |
$app = Mage::app(); | |
$categories = Mage::getModel('catalog/category') | |
->getCollection() | |
->addAttributeToSelect('*') | |
->addAttributeToFilter('is_anchor', 0) | |
->addAttributeToFilter('entity_id', array("gt" => 1)) | |
->setOrder('entity_id') | |
; | |
foreach($categories as $category) { | |
echo $category->getId() . "\t" . $category->getName() . "\n"; | |
$category->setIsAnchor(1); | |
$category->save(); | |
} | |
?> | |
// END ORIGINAL ------------------------------------ | |
// MODIFIED ----------------------------------- | |
<?php | |
error_reporting(E_ALL); | |
ini_set('display_errors', '1'); | |
// Load Up Magento Core | |
define('MAGENTO', realpath('')); | |
require_once(MAGENTO . '/app/Mage.php'); | |
$app = Mage::app(); | |
$categories = Mage::getModel('catalog/category') | |
->getCollection() | |
->addAttributeToSelect('*') | |
// ->addAttributeToFilter('is_anchor', '0') | |
->addAttributeToFilter('entity_id', array("gt" => 1)) | |
->setOrder('entity_id') | |
; | |
foreach($categories as $category) { | |
echo $category->getId() . "\t" . $category->getName() . "\t" . $category->getIsAnchor() . "\n"; | |
$category->setIsAnchor(1); | |
echo $category->getId() . "\t" . $category->getName() . "\t" . $category->getIsAnchor() . "\n"; | |
$category->save(); | |
// echo $category->getId() . "\t" . $category->getName() . "\t" . $category->getIsAnchor() . "\n"; | |
} | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
THIS IS MAGENTO 1