Kamil Borkowski
Kamil Borkowski

Reputation: 96

Magento - import attribute with custom source model

I'm running into a problem with importing product attribute values that has custom source model (so no visible options in attribute edit page). Simply it's not working with option ID value or option label neither.

When I was trying to export product with this attribute, there has been an error

Invalid option ID specified for ceneo_category_id (2278), skipping the record. (Line 1, SKU: ...)

Can someone help me with this?

Upvotes: 1

Views: 1214

Answers (1)

Jamie
Jamie

Reputation: 11

I think I've just experienced the same problem:

  1. created a custom multiselect attribute with a custom source model for a product.
  2. the label was 'human readable' and the value was an alphanumeric code.
  3. used the alphanumeric code in a csv product import file.
  4. tried to use the Magento import to load a product with this attribute.
  5. Got the error: Invalid value for 'test_attr' in rows: 1

After some debugging this seems to be because: - Mage_ImportExport_Model_Import_Entity_Abstract#isAttributeValid(..) reports the attribute value is invalid (the case 'multiselect' line). - this is because it is checking the value from the csv file (alphanumeric code) and finding it wasn't in the list of valid options for this attribute. This is because its list of valid options contained the label. - The reason the list of options contains the label and not the value/code is because in Mage_ImportExport_Model_Import_Entity_Abstract#getAttributeOptions(..) it decides to use the label because the attribute isn't in an array of attributes that values should be used for. This array is declared in Mage_ImportExport_Model_Import_Entity_Abstract:

protected $_indexValueAttributes = array(
    'status',
    'tax_class_id',
    'visibility',
    'enable_googlecheckout',
    'gift_message_available',
    'custom_design'
);

So, the answer is to use in the csv file the label for the attribute. Or to overwrite Mage_ImportExport_Model_Import_Entity_Abstract to get your attribute into the array of attributes for which the value and not the label is expected during product imports.

Upvotes: 1

Related Questions