2

Basically I am trying to add new custom drop-down option with values in Shipping Method option, in one page checkout. I am following this tutorial to create attributes and confused about some issues. To add static options to drop-down we can add below code.

        'option'     => array (
        'values' => array(
            0 => 'Small',
            1 => 'Medium',
            2 => 'Large',
        )

1) How can I add dynamic options to my select drop-down while creating an attribute ?

2) What is the difference between

'source'        => 'eav/entity_attribute_source_table'

'source'        => 'eav/entity_attribute_source_boolean'

'source'        => 'yourmodule/source_option'

3) How, where and when to use above source options ?

4) What is the difference between backend_model, backend_type and backend_table ?

Is there any tutorial that could guide me on complete parameters for attributes, its usages and sample code ?

Apart from the above technical concerns, I still do not know how to add a custom drop-down in shipping method.

Thanks in advance.

3

The source model is the model class that provides the options to your attribute. In order to have dynamic values, you need a source model yourmodule/source_options located in yourmodule/model/source/options.php, that must implement the getAllOptions() method and which has to return an array of values and labels:

class Namespace_Yourmodule_Model_Source_Options
{
  public function getAllOptions()
  {
    return array(
        array('value' => 0, 'label' => 'Small'),
        array('value' => 1, 'label' => 'Medium'),
  }
}

You can edit the class to load the values from the database, or any other source.

The source models you provided as example are predefined models to be used on attributes. For example 'eav/entity_attribute_source_table' is the default source model, and 'eav/entity_attribute_source_boolean' will return a yes/no values array, which you can use when you want to create a yes/no attribute (have a look in app/code/core/Mage/Eav/Model/Entity/Attribute/Source/Boolean.php to see how it works).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.