How to get custom order fields in scFinishOrder postHook

Hi,

I need to get custom order fields

in this way I take the fields
// get order passed by the hook
$order =& $hook->getValue(‘order’);

but for custom fields I had to do
$orderPhs = $order->toArray();
$mycustomfield = $orderPhs[‘customFiledName’];

is there a better way?

I have a problem with a custom field that begins with the 00 ( eg . 002345 original value , return value 2345) as if toArray would remove zeros :confused:

Still I don’t know if there’s a better way to get custom order fields.

I realized that. My custom value that started with zero 000123, becomes 123
because getFields() function on simpleCartOrder class converts it to integer
if(is_numeric($value)) { $value = (integer) $value; }
I do not understand why it is done

That looks like the best way to do it to me! Casting it to an integer is probably done to make sure the fields get the right type. If you need the zeros before, you could try prefixing your values with another character, and filter that out in your hook.

This came just in time. I have been dealing with an issue but had yet to look under the hood. I have alot of custom fields many of which hold pricing values that are outside of the cart itself as well as item numbers with prefixed 0. I was loosing the prefixed zero as well as all $00.00 were coming up $00.

This is how I ended up solving it for myself. I needed support for both float and numeric strings that had a leading zero

//if(is_numeric($value)) { $value = (integer) $value;  } // original code
                if(is_numeric($value)) {  // adjusted by adam smith (enminc)
                    if(substr_count($value,'.') > 0){
                        $value = (float) $value;
                    }
                    else {

                        if($value[0] == '0'){ // treat as string
                            $value = (string)$value;
                        }
                        else {
                            $value = (integer)$value;
                        }
                    }
                }

NOTE: I did attempt to use use a postHook as PMedusa described but the scrub happens after postHook apparently (though I cant see where) because I still had the same float and zero prefix issue. Hacking the code was the only solution I could find. Look forward to a solution that doesn’t involve the need for my hack