I'm extending the catalog_product_option_type_value database. I created my own table, my_catalog_product_option_type_value and it has a reference to the option_type_id. I have that working, and my class working but I added a table column to the custom options grid and I can't figure out how to get my custom field value.
enter image description here
When I click the 'Save and Continue Button', I want to be able to get the ID of the newly created or existing option_type_id and then use that id and 'My Value' to insert or update a record into my my_catalog_product_option_type_value table. I created an observer that picks up the catalog_product_prepare_save event. That is working but it only returns a product and it's options. I can't get my value. I found this code in the ProductController class:
if (isset($productData['options']) && !$product->getOptionsReadonly()) {
 $product->setProductOptions($productData['options']);
 }
So, I though i'd be able to do something like
$productData['options']['my_value']
but that doesn't work because the post data is [options][id][values][id][my_value]. I don't know how i'd get the id of these options. So, I'm a little stuck and hoping someone can point me in the right direction
2 Answers 2
Looks like you will have to do some array itterations and key checking to pull your values.
Try this in your observer.
$options = $observer->getEvent()->getProduct()->getOptions();
if (is_array($options)) {
 foreach ($options as $key => $option) {
 if (is_array($option) && array_key_exists('values',$option)) { 
 foreach ($option['values'] as $value) {
 if (is_array($value) && array_key_exists('YOUR FIELD NAME',$value)) {
 $result = $value['YOUR FIELD NAME'];
 // do something with the $result
 } 
 }
 }
 } 
}
Hope that helps.
In the catalog_product_prepare_save observer, you should use the code
$options = $observer->getEvent()->getProduct()->getProductOptions();
instead of
$options = $observer->getEvent()->getProduct()->getOptions();
& refer the remaining part in ProxiBlue's answer!
I tested it work with magento 1.8.1.0 version.
Explore related questions
See similar questions with these tags.