I have 2 custom option text fields associated with a product called Location To and Location From,
I have set up a Module that has an Observer for checkout_cart_add_product_complete
with a method called getLocationCoords, how would I get access to these two fields from the event object that passed to my method.
I need these 2 fields so I can reverse geocode them which I think I will be able to do myself.
Once I get the 2 sets of coordinates how would I go about storing them with the product so I would be able to see them associated with the product when an order is paced?
======================= edit addded ============================
What i have tried so far
public function getLocationCoords(Varien_Event_Observer $observer)
{
// Retrieve the product being updated from the event observer
$product = $observer->getEvent()->getProduct();
// Write a new line to var/log/product-updates.log
$name = $product->getName();
$sku = $product->getSku();
Mage::log(
"{$name} ({$sku}) updated",
null,
'product-updates.log'
);
foreach ($product->getOptions() as $o) {
$type = "Custom Option TYPE: " . $o->getType();
$title = "Custom Option TITLE: " . $o->getTitle();
Mage::log(
"{$type} ({$title}) custom option {$o}",
null,
'product-updates.log'
);
}
}
It all works except getting the values of the custom options, i will try the answer below and see where i get
when i print out the var dump of the option object this is what i get
2012-12-11T15:19:45+00:00 DEBUG (7): array (
'option_id' => '1',
'product_id' => '1',
'type' => 'field',
'is_require' => '1',
'max_characters' => '0',
'sort_order' => '0',
'default_title' => 'Location To',
'title' => 'Location To',
'default_price' => '0.0000',
'default_price_type' => 'fixed',
'price' => '0.0000',
'price_type' => 'fixed',
)
there is no value to the object