Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Names on shipping and billing address will now default to the main order names #435

Merged
merged 1 commit into from Feb 26, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 24 additions & 11 deletions code/model/Order.php
Expand Up @@ -456,12 +456,7 @@ public function getTitle()
*/
public function getShippingAddress()
{
if ($address = $this->ShippingAddress()) {
return $address;
} elseif ($this->Member() && $address = $this->Member()->DefaultShippingAddress()) {
return $address;
}
return null;
return $this->getAddress('Shipping');
}

/**
Expand All @@ -472,12 +467,30 @@ public function getBillingAddress()
{
if (!$this->SeparateBillingAddress && $this->ShippingAddressID === $this->BillingAddressID) {
return $this->getShippingAddress();
} elseif ($address = $this->BillingAddress()) {
return $address;
} elseif ($this->Member() && $address = $this->Member()->DefaultBillingAddress()) {
return $address;
} else {
return $this->getAddress('Billing');
}
return null;
}

/**
* @param string $type - Billing or Shipping
* @return Address
* @throws Exception
*/
protected function getAddress($type)
{
$address = $this->getComponent($type . 'Address');

if (!$address || !$address->exists() && $this->Member()) {
$address = $this->Member()->{"Default${type}Address"}();
}

if (empty($address->Surname) && empty($address->FirstName)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this check/assign each field separately?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. If, for example they the shipping address had only the last name (which I've seen happen), we wouldn't want it to then inject the first name from the order because the customer probably did that for a reason. I think we only want it to inject if both fields are empty.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, fair enough.

$address->FirstName = $this->FirstName;
$address->Surname = $this->Surname;
}

return $address;
}

/**
Expand Down