Skip to content

Instantly share code, notes, and snippets.

@kkrieger85
Last active August 29, 2015 14:20
Show Gist options
  • Save kkrieger85/1cce57e860bae20894e9 to your computer and use it in GitHub Desktop.
Save kkrieger85/1cce57e860bae20894e9 to your computer and use it in GitHub Desktop.
Get Attributes and Attributsets from Magento (Formatted for Redmine -Wiki)
<?php
/**
* Created by PhpStorm.
* User: kkrieger
* Date: 04.05.15
* Time: 14:03
*/
ini_set('display_errors', 1);
error_reporting(E_ALL | E_STRICT);
umask(0);
require(__DIR__ . '/app/Mage.php');
Mage::setIsDeveloperMode(true);
Mage::app();
//Get Entity Type ID
$entityTypeId = Mage::getModel('eav/entity')
->setType('catalog_product')
->getTypeId();
//Default-Attribute-Set
$defaultAttributeSetId = Mage::getModel('eav/entity_attribute_set')
->getCollection()
->setEntityTypeFilter($entityTypeId)
->addFieldToFilter('attribute_set_name', 'Default')
->getFirstItem()
->getAttributeSetId();
//Get Default AttributsetId
$defaultAttributeCodes = array();
$defaultAttributes = Mage::getModel('catalog/product')
->getResource()
->loadAllAttributes()
->getSortedAttributes($defaultAttributeSetId);
foreach ($defaultAttributes as $attribute) {
$defaultAttributeCodes[] = $attribute->getName();
}
//Default
//echo count($defaultAttributeCodes).PHP_EOL;
//echo implode(', ', $defaultAttributeCodes) . PHP_EOL;
//Get all AttributeSets
$attributeSets = Mage::getModel('eav/entity_attribute_set')
->getCollection()
->setEntityTypeFilter($entityTypeId)
->load();
foreach ($attributeSets as $set) {
//Attributsetname
echo "* *".$set->getAttributeSetName()."*" . PHP_EOL;
$attributes = Mage::getModel('catalog/product')
->getResource()
->loadAllAttributes()
->getSortedAttributes($set->getAttributeSetId());
$attributeCodes = array();
foreach ($attributes as $attribute) {
$attributeCodes[] = $attribute->getName();
}
//echo count($attributeCodes).PHP_EOL;
$currentAttributes = array_diff($attributeCodes, $defaultAttributeCodes);
echo '> * '.join(PHP_EOL.'> * ', $currentAttributes).PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment