src/Checkout/Component/Address.php
public function setData(Order $order, array $data)
    {
        $address = $this->getAddress($order);
        //if the value matches the current address then unset
        //this is to fix issues with blank fields & the readonly Country field
        $addressFields = DataObject::getSchema()->databaseFields(\SilverShop\Model\Address::class);
        foreach ($data as $key => $value) {
            if (!isset($addressFields[$key]) || (!$value && !$address->{$key})) {
                unset($data[$key]);
            }
        }
        $address->update($data);
        //if only one country is available, then set it
        if ($country = SiteConfig::current_site_config()->getSingleCountry()) {
            $address->Country = $country;
        }
        //write new address, or duplicate if changed
        if (!$address->isInDB()) {
            $address->write();
        } elseif ($address->isChanged()) {
            $address = $address->duplicate();
        }
        //set billing address, if not already set
        $order->{$this->addresstype . 'AddressID'} = $address->ID;
        if (!$order->BillingAddressID) {
            $order->BillingAddressID = $address->ID;
        }
        $order->write();

        if ($this->addresstype === 'Shipping') {
            ShopUserInfo::singleton()->setAddress($address);

            $order->extend('onSetShippingAddress', $address);
        }

        //associate member to address
        if ($member = Security::getCurrentUser()) {
            $default = $member->{'Default' . $this->addresstype . 'Address'}();
            //set default address
            if (!$default->exists()) {
                $member->{'Default' . $this->addresstype . 'AddressID'} = $address->ID;
                $member->write();
            }
            if ($this->addtoaddressbook) {
                $member->AddressBook()->add($address);
            }
        }
        //extension hooks
        $order->extend('onSet' . $this->addresstype . 'Address', $address);
    }
public function setData(Order $order, array $data)
    {
        $address = $this->getAddress($order);
        //if the value matches the current address then unset
        //this is to fix issues with blank fields & the readonly Country field
        $addressFields = DataObject::getSchema()->databaseFields(\SilverShop\Model\Address::class);
        foreach ($data as $key => $value) {
            if (!isset($addressFields[$key]) || (!$value && !$address->{$key})) {
                unset($data[$key]);
            }
        }
        $address->update($data);
        //if only one country is available, then set it
        if ($country = SiteConfig::current_site_config()->getSingleCountry()) {
            $address->Country = $country;
        }
        //write new address, or duplicate if changed
        if (!$address->isInDB()) {
            $address->write();
        } elseif ($address->isChanged()) {
            $address = $address->duplicate();
        }
        //set billing address, if not already set
        $order->{$this->addresstype . 'AddressID'} = $address->ID;
        if (!$order->BillingAddressID) {
            $order->BillingAddressID = $address->ID;
        }
        $order->write();

        if ($this->addresstype === 'Shipping') {
            ShopUserInfo::singleton()->setAddress($address);

            $order->extend('onSetShippingAddress', $address);
        }

        //associate member to address
        if ($member = Security::getCurrentUser()) {
            $default = $member->{'Default' . $this->addresstype . 'Address'}();
            //set default address
            if (!$default->exists()) {
                $member->{'Default' . $this->addresstype . 'AddressID'} = $address->ID;
                $member->write();
            }
            if ($this->addtoaddressbook) {
                $member->AddressBook()->add($address);
            }
        }
        //extension hooks
        $order->extend('onSet' . $this->addresstype . 'Address', $address);
    }
Create a new address if the existing address has changed, or is not yet
created.

@param  Order $order order to get addresses from
@param  array $data  data to set
@throws \SilverStripe\ORM\ValidationException