Created
February 7, 2011 20:05
-
-
Save cranberyxl/815072 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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