0

We need to be able to define an attribute for an internal use reference name but pass an alternative variable elsewhere.

For Example:

Item Condition (Displayed Internally when creating product):

  1. New
  2. Refurbished
  3. Used

Alternate Variable Passed

  1. 1000
  2. 2000
  3. 3000

The marketplace that we feed some of our inventory down requires this field but in the numeric format. Don't want to leave room for mistakes when selecting this.

We will create this attribute field separately and only for this inventory type in the attribute set.

Kudos for an extension that's available that makes this very easy rather than coding specifically each time we have the need.

Thanks in advance for time and responses. It's much appreciated!

** Using Magento 1.8.1

1 Answer 1

1

If I understood correctly you need a dropdown product attribute, but the actual values that are going to be stored in the db, need to be exactly 1000, 2000 and 3000.
if that is the case, then you need an attribute with a custom source model.
Here is an explanation on how you can do that.

The main idea in the article is that you need a custom module that will add a product attribute and specify a custom source model to it.
Something like this:

$this->addAttribute('catalog_product', 'provider', array(
    'group'                => 'General',
    'type'              => 'int',
    'backend'           => '',
    'frontend_input'    => '',
    'frontend'          => '',
    'label'             => 'Provider',
    'input'             => 'select',
    'class'             => '',
    'source'            => 'provider/attribute_source_provider',
    'global'             => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,//can be SCOPE_WEBSITE or SCOPE_STORE
    'visible'           => true,
    'used_in_product_listing' =>true,//can also be false
    'frontend_class'     => '',
    'required'          => false,//can be true
    'user_defined'      => true,
    'default'           => '',
    'searchable'        => false,//can be true
    'filterable'        => false,//can be true
    'comparable'        => false,//can be true
    'visible_on_front'  => false,//can be true
    'unique'            => false,
    'position'            => 60,//put any number here
));

Notice the source element in the config array. In this case is provider/attribute_source_provider. This means that the options you will see in the dropdown are generated by the call of

Mage::getModel('provider/attribute_source_provider')->getAllOptions();

You can implement that method in your custom model and set the values as you want.

For example

public function getAllOptions($withEmpty = false){
    if (is_null($this->_options)){
        $this->_options = array();
                   //$this->_options[] = array('label'=>'HERE GOES THE LABEL', 'value'=>'HERE GOES THE VALUE');
        //as example
        $this->_options[] = array('label'=> $this->__('New'), value=>1000);
        $this->_options[] = array('label'=> $this->__('Refurbished'), value=>2000);
        $this->_options[] = array('label'=> $this->__('Used'), value=>3000);
    }
    $options = $this->_options;
    if ($withEmpty) {
        array_unshift($options, array('value'=>'', 'label'=>''));
    }
    return $options;
}
3
  • Thanks for the quick answer and detailed information. I'm able to follow along with the concept but am struggling as I'm not a developer or pro at magento as my 9-5. However, I'm going to use the terminology you've used to search and see if there is an extension available that allows this to be done on the fly without coding. Will update thread when done.
    – harvmob
    Mar 17, 2014 at 14:54
  • At same time, I'm trying your solution. You have at the very end of your documentaion "If you choose to include the attribute in the product listing or if you made it filtrable" and had some code underneath....where do these 3 lines of code go?
    – harvmob
    Mar 17, 2014 at 15:12
  • Marius, after reviewing many of extension providers extensively, there doesn't seem to be anything alacart for product attributes , only for orders and other modules.I was able to follow your steps and setup the sample custom attribute. However I did have a question. Would this process need to be done, in full (website reference) for each attribute that I need to create?
    – harvmob
    Mar 28, 2014 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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