Magento attribute distribution with first blank value

I want to show one drop-down menu with the values ​​from the product attribute. But it always shows that the first position is empty. I have 2 values, but I don't know why the array has 3 positions

<?php
    $options  = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'tipo_paquete')->getSource()->getAllOptions();
    var_dump($options);
?>
<select id="tipo_paquete" class="required select" name="tipo_paquete">
   <option value=""><?php echo $helper->__('--Please Select--')?></option>
   <?php
        foreach ($options as $option)
        {
           echo "<option value='".$option['value']."'>". $option['label'] ."</option>";
        }
   ?>
</select>

This code shows the selection as follows:

Look at the white row

And var_dump shows this:

array(3) { [0]=> array(2) { ["label"]=> string(0) "" ["value"]=> string(0) "" } [1]=> array(2) { ["value"]=> string(1) "8" ["label"]=> string(15) "Caja de cartón" } [2]=> array(2) { ["value"]=> string(1) "7" ["label"]=> string(14) "Caja de madera" } } 

I don’t know why I have 3 positions, I saved only 2 options. I tested with other attributes with the same problem.

0
source share
1 answer

I found a solution here . getAllOptionscan get two parameters:

array getAllOptions ([bool $withEmpty = true], [bool $defaultValues = false])

$withEmpty adds an empty option to the array

Just go falseto getAllOptions().

$options  = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'tipo_paquete')->getSource()->getAllOptions(false);
+1
source

All Articles