Attribute Source Model

Updated . Posted . Visible to the public.

Used when you want to use a multiselect or select dropdown box on an EAV entity, such as products or categories.

class Namespace_Module_Model_Select extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
{
    /**
     * Retrieve Full Option values array
     *
     * @param bool $withEmpty     Add empty option to array
     * @param bool $defaultValues
     *
     * @return array
     */
    public function getAllOptions($withEmpty = true)
    {
        if (!$this->_options) {
            $options = array();
            $options[] = array(
                'value' => '0',
                'label' => 'Option 1',
            );
            $options[] = array(
                'value' => '1',
                'label' => 'Option 2',
            );
            $this->_options = $options;
        }
        $options = $this->_options;
        if ($withEmpty) {
            array_unshift($options, array(
                'value' => '',
                'label' => '-- Please Select --',
            ));
        }
        return $options;
    }
}

Mike Whitby
Last edit
Posted by Mike Whitby to Magento (2012-06-29 14:59)