Codeschnipsel: Liste aller Produkt-Attribute und deren Optionen
Archiv-Beitrag aus 2010 – Magento mache ich heute nur noch selten. Aktuell: com:werft (Shopware 6, Laravel & PHP) · siepker.com · kontor:worx · campr
Mit diesem Code erhält man in Magento eine Liste aller Attribute und deren Optionen, falls diese einem Attribut zugeordnet wurden.
require_once $_SERVER['DOCUMENT_ROOT'] . '/app/Mage.php';
umask(0);
Mage::app();
$product = Mage::getModel('catalog/product');
$collection = Mage::getResourceModel('eav/entity_attribute_collection')
->setEntityTypeFilter($product->getResource()->getTypeId())
->addVisibleFilter();
echo "<pre>\n";
foreach ($collection as $attribute) {
echo $attribute['attribute_code'] . "\n";
$collection = Mage::getResourceModel('eav/entity_attribute_collection')
->setEntityTypeFilter($product->getResource()->getTypeId())
->addFieldToFilter('attribute_code', $attribute['attribute_code']);
$_attribute = $collection->getFirstItem()->setEntity($product->getResource());
$attribute_options = $_attribute->getSource()->getAllOptions(false);
if ($attribute_options) {
foreach ($attribute_options as $option) {
if ($option['label']) {
echo "\t" . $option['label'] . "\n";
}
}
}
}
echo "</pre>\n";