The following code does not adhere to Magento’s developer recommendations. Using object manager in such a way externally is a TERRIBLE idea.
Comment out line number 2 and then run the script. Edit line 11 and put the attribute code you want to dump
<?php
header("Location: /");exit;
use \Magento\Framework\App\Bootstrap;
error_reporting(E_ALL);
ini_set("display_errors", 1);
include('./app/bootstrap.php');
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$eavConfig = $objectManager->get('\Magento\Eav\Model\Config');
$attribute = $eavConfig->getAttribute('catalog_product', 'manufacturer');
$options = $attribute->getSource()->getAllOptions();
$options = array_slice($options, 1);
usort($options, function($a, $b)
{
return strcasecmp($a['label'], $b['label']);
});
if (count($options))
$v = "<table>";
foreach ($options as $option) {
$v .= "<tr><td>" . $option['value'] . '</td><td>' . $option['label'] . '</td></tr>';
}
if (count($options))
$v .= "</table>";
echo $v;
?>
<style>
table tr:nth-child(odd){background:#444;color:#fff}
</style>
Leave a Reply