I am using the following code to get and process the custom options
$orderIncrementId = $order->getIncrementId();
$orderReal = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
$orderItems = $orderReal->getAllItems();
$sk = "";
foreach ($orderItems as $item)
{
$options = $item->getProductOptions();
foreach ($options as $option) {
if (is_array($option)) {
$firstElement = array_shift($option);
foreach ($option as $firstElement){
if (isset($firstElement['label']) && isset($firstElement['option_value'])){
if ($firstElement['label'] == 'Delivery Date') {
$deliveryDate = $firstElement['option_value'];
}
}
}
}
}
}
and my usage is to write it to CSV like this
if (isset($deliveryDate)) {
$outputString.= '"'.$deliveryDate.'",';
} else {
$outputString.= '"deliverydate error",';
}
now, I have made sure that
- Label Delivery Date is available in data base “Catalog Product Option Title Table”
- custom option Delivery Date has values in “Catalog Product Option
Table”
it looks like Delivery date is not being accessed via the script so my custom message ‘deliverydate error’ saves in CSV
in fact I am trying to debug mag extension that is not working properly…
to me, code is okay, but not sure why its not working….
can anybody guide me?
While it’s not the perfect solution, this will return your custom option value for the ordered item, assuming that your product custom option is a type “field”.