Another way to do this task, you should track product category and set additional options for its category while adding to cart, using event/observers. See my solution:
1. Every "add to cart form" or "add to cart button" you should add category param to url:
/app/design/frontend/base/default/template/catalog/product/view.phtml:
<form action="<?php echo $this->getSubmitUrl($_product,array('category'=>$_product->getCategory()->getId())) ?>"
method="post" id="product_addtocart_form"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
/app/design/frontend/base/default/template/catalog/product/list.phtml:
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart"
onclick="setLocation('<?php echo $this->getAddToCartUrl($_product,array('category'=>$_product->getCategory()->getId())) ?>')">
<span><span><?php echo $this->__('Add to Cart') ?></span></span>
</button>
2.Add these observers to your config.xml:
<frontend>
<events>
<sales_quote_add_item>
<observers>
<your_module>
<method>salesQuoteAddItem</method>
<class>Your_Module_Model_Observer</class>
</your_module>
</observers>
</sales_quote_add_item>
<sales_convert_quote_item_to_order_item>
<observers>
<your_module>
<method>salesConvertQuoteItemToOrderItem</method>
<class>Your_Module_Model_Observer</class>
</your_module>
</observers>
</sales_convert_quote_item_to_order_item>
<events>
<!-- other nodes -->
<frontend>
3.And your Observer.php:
class Your_Module_Model_Observer
{
public function salesQuoteAddItem($observer)
{
/**
* here we save category id and name to quote item option as 'additional_options'
* @var $item Mage_Sales_Model_Quote_Item
*/
$item = $observer->getEvent()->getQuoteItem();
if ($categoryId = Mage::app()->getRequest()->getParam('category')) {
$name = Mage::getModel('catalog/category')->load($categoryId)->getName();
$option = $item->getOptionByCode('additional_options');
$categoryOption = array(
'label' => 'Category',
'option_value' => $categoryId,
'value' => $name,
'print_value' => $name,
);
if ($option == null) {
$value = array('category'=> $categoryOption);
$value = serialize($value);
$item->addOption(array('code'=> 'additional_options', 'product_id'=> $item->getProductId(), 'value'=> $value));
} else {
$additional = unserialize($option->getValue());
$additional['category'] = $categoryOption;
$option->setValue(serialize($additional));
}
}
}
public function salesConvertQuoteItemToOrderItem($observer)
{
/**
* here we convert previous saved category option to order item option
* @var $quoteItem Mage_Sales_Model_Quote_Item
*/
$orderItem = $observer->getEvent()->getOrderItem();
$quoteItem = $observer->getEvent()->getItem();
$orderOptions = $orderItem->getProductOptions();
if ($additional = $quoteItem->getOptionByCode('additional_options')) {
$additional = unserialize($additional->getValue());
if (isset($orderOptions['attributes_info'])) {
$orderOptions['attributes_info'][] = $additional['category'];
} else {
$orderOptions['attributes_info'] = array($additional['category']);
}
$orderItem->setProductOptions($orderOptions);
}
}
}
Here is my final result: