Last active
December 1, 2015 23:50
-
-
Save oreales/24fa667df77d86de4b86 to your computer and use it in GitHub Desktop.
Magento: poner todas las categorías a anchor script php
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 | |
/** | |
* todas las categorías de nivel 4 las ponemos a anchor | |
* por ejemplo para que tengan "filtros" (layered nav) | |
*/ | |
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('level', 4) | |
->setOrder('entity_id'); | |
// start emulation porque en frontend no se puede salvar categoria | |
$appEmulation = Mage::getSingleton('core/app_emulation'); | |
$initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation(0); | |
foreach($categories as $category) { | |
echo $category->getId() . "\t" . $category->getName() . "\n"; | |
$category->setIsAnchor(1); | |
$category->save(); | |
} | |
// stop, return to origional env. | |
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment