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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | <?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