public function setData(Order $order, array $data)
{
if (!isset($data[$this->addresstype . 'ToSameAddress'])) {
parent::setData($order, $data);
} else {
$order->{$this->addresstype . "AddressID"} = $order->{$this->useAddressType . "AddressID"};
if (!$order->BillingAddressID) {
$order->BillingAddressID = $order->{$this->useAddressType . "AddressID"};
}
}
// FIX for missing name fields
$fields = array_intersect_key($data, array_flip(['FirstName', 'Surname', 'Name', 'Email']));
$changed = false;
foreach ($fields as $field => $value) {
if (!$order->{$this->addresstype . "Address"}->{$field}) {
$order->{$this->addresstype . "Address"}->{$field} = $value;
$changed = true;
}
}
if ($changed) {
$order->{$this->addresstype . "Address"}->write();
}
}