Skip to content

Instantly share code, notes, and snippets.

@cranberyxl
Created February 7, 2011 20:05
Show Gist options
  • Save cranberyxl/815072 to your computer and use it in GitHub Desktop.
Save cranberyxl/815072 to your computer and use it in GitHub Desktop.
<?php
public function testFoo()
{
$order = new Order();
$order->setBillingAddress($this->createAddress('billing'));
$order->setBillingAddress($this->createAddress('shipping'));
}
private function createAddress($type)
{
$address = new CustomerAddress();
$address->setFirstName("{$type} First");
$address->setLastName("{$type} Last");
$address->setAddress1("{$type} 123 Main Street");
$address->setAddress2("{$type} Apt 123");
$address->setCity("{$type} New York");
$address->setState("{$type} NY");
$address->setPostalCode("{$type} 10011");
return $address;
}
//Order.php
public function setAddress(CustomerAddress $address, $type = self::SHIPPING)
{
$this->shippingAddress1 = $address->getAddress1();
$addressClass = new \ReflectionClass('OpenSky\Bundle\MainBundle\Document\Address\CustomerAddress');
$orderClass = new \ReflectionClass($this);
$firstName= "";
$lastName = "";
foreach($addressClass->getProperties() as $prop) {;
//TODO do addresses need two fields. Should be one. Let's refactor that?
if($prop->getName() == "firstName") {
$firstName = $address->getFirstName();
continue;
}
if($prop->getName() == "lastName"){
$lastName = $address->getLastName();
continue;
}
//TODO orders are using zip, some addresses use postal code some zip. Standardize
if($prop->getName() == "postalCode"){
$field = $type."Zip";
} else {
$field = $type.ucfirst($prop->getName());
}
if($orderClass->hasProperty($field)) {
$this->$field = $address->{"get".$prop->getName()}();
}
}
$this->{$type."Name"} = $firstName." ".$lastName;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment