0

I have a basic product in Magento Enterprise (v1.11.2.0). I need to add 0 to many instruction sheets to this product. I know I could just hard code the links within a textbox and have them show on the page, but at some point, I'm going to need to access the value(s) for these attributes through the Magento API, so I need to break them out.

I know I could add multiple attributes to the set (ex. instruction-1, instruction-2, etc.), but that's not very clean or scalable.

I also know that I could add multiple "Custom Options", but something about that just doesn't seem right. If I come across a product that needs these custom options, that is really going to muddy up the user-facing view logic distinguishing between the two (actual custom options and faux custom options).

Ideas?

Brit Mansell
  • 786
  • 7
  • 7

2 Answers2

1

Create one attribute called instructions as varchar in eav_attribute. Save all the data of instruction-1, instruction-2, etc.. in instructions attribute in serialized form. So, next time when you show the instructions, just unserialize them and you will be good to go.

Or are you looking something different?

Kalpesh
  • 5,635
  • 2
  • 23
  • 39
  • Is there a way for that serialized data to be inserted via the Magento admin panel? – Brit Mansell Aug 01 '12 at 21:19
  • Yes there is a way. You need to give your custom `backend_model` for your new attribute `instructions`. `backend_model` allows you to edit the provided data before inserting it to the database, and also allows to prepare data before loading it. Confused? I will show you how to implement in the next answer. – Kalpesh Aug 01 '12 at 21:51
0

It's possible depending on how much work you're willing to do. I recently built a module with a many-to-one relationship and based it off of how tier pricing works. I basically used a custom renderer looping through all the current values and inserting them into a table. Then I used javascript to insert and delete rows. If you copy the classes magento used for tier pricing, you shouldn't have too much of a problem.

Nate
  • 578
  • 2
  • 8
  • Thanks, Nate, but I'm trying to stay within the bounds of the Magento framework, rather than building custom code. We may not have a choice with Magento, though. – Brit Mansell Aug 01 '12 at 21:18
  • Right. I think if it was possible within the framework, the Magento team would have done it that way instead of the way described above. I pretty much mimicked tier pricing when I did it. – Nate Aug 01 '12 at 21:32