public function testBuildingEntity() { $entity = new Address(); $this->assertInstanceOf('Expressly\\Entity\\Address', $entity->setFirstName('Sam')); $this->assertInstanceOf('Expressly\\Entity\\Address', $entity->setLastName('Pratt')); $this->assertInstanceOf('Expressly\\Entity\\Address', $entity->setAddress1('Address1')); $this->assertInstanceOf('Expressly\\Entity\\Address', $entity->setAddress2('Address2')); $this->assertInstanceOf('Expressly\\Entity\\Address', $entity->setCity('London')); $this->assertInstanceOf('Expressly\\Entity\\Address', $entity->setCompanyName('Expressly')); $this->assertInstanceOf('Expressly\\Entity\\Address', $entity->setZip('W2 6LG')); $this->assertInstanceOf('Expressly\\Entity\\Address', $entity->setPhonePosition(0)); $this->assertInstanceOf('Expressly\\Entity\\Address', $entity->setAlias('shipping')); $this->assertInstanceOf('Expressly\\Entity\\Address', $entity->setStateProvince('England')); $this->assertInstanceOf('Expressly\\Entity\\Address', $entity->setCountry('GBR')); $this->assertEquals('Sam', $entity->getFirstName()); $this->assertEquals('Pratt', $entity->getLastName()); $this->assertEquals('Address1', $entity->getAddress1()); $this->assertEquals('Address2', $entity->getAddress2()); $this->assertEquals('London', $entity->getCity()); $this->assertEquals('Expressly', $entity->getCompanyName()); $this->assertEquals('W2 6LG', $entity->getZip()); $this->assertEquals(0, $entity->getPhonePosition()); $this->assertEquals('shipping', $entity->getAlias()); $this->assertEquals('England', $entity->getStateProvince()); $this->assertEquals('GBR', $entity->getCountry()); $this->assertJson(json_encode($entity->toArray())); $this->assertJsonStringEqualsJsonString(json_encode($entity->toArray()), json_encode(array('firstName' => 'Sam', 'lastName' => 'Pratt', 'address1' => 'Address1', 'address2' => 'Address2', 'city' => 'London', 'companyName' => 'Expressly', 'zip' => 'W2 6LG', 'phone' => 0, 'alias' => 'shipping', 'stateProvince' => 'England', 'country' => 'GBR'))); }
private function retrieveUserByEmail($emailAddr) { try { $user = get_user_by('email', $emailAddr); if ($user) { $customer = new Customer(); $customer->setFirstName($user->first_name)->setLastName($user->last_name); $email = new Email(); $email->setEmail($emailAddr)->setAlias('primary'); $customer->addEmail($email); $user_id =& $user->ID; $countryCodeProvider = $this->app['country_code.provider']; $createAddress = function ($prefix) use($user_id, $countryCodeProvider, $customer) { $address = new Address(); $address->setFirstName(get_user_meta($user_id, $prefix . '_first_name', true))->setLastName(get_user_meta($user_id, $prefix . '_last_name', true))->setAddress1(get_user_meta($user_id, $prefix . '_address_1', true))->setAddress2(get_user_meta($user_id, $prefix . '_address_2', true))->setCity(get_user_meta($user_id, $prefix . '_city', true))->setZip(get_user_meta($user_id, $prefix . '_postcode', true)); $iso3 = $countryCodeProvider->getIso3(get_user_meta($user_id, $prefix . '_country', true)); $address->setCountry($iso3); $address->setStateProvince(get_user_meta($user_id, $prefix . '_state', true)); $phoneNumber = get_user_meta($user_id, $prefix . '_phone', true); if (!empty($phoneNumber)) { $phone = new Phone(); $phone->setType(Phone::PHONE_TYPE_HOME)->setNumber((string) $phoneNumber); $customer->addPhone($phone); $address->setPhonePosition((int) $customer->getPhoneIndex($phone)); } return $address; }; $billingAddress = $createAddress('billing'); $shippingAddress = $createAddress('shipping'); if (Address::compare($billingAddress, $shippingAddress)) { $customer->addAddress($billingAddress, true, Address::ADDRESS_BOTH); } else { $customer->addAddress($billingAddress, true, Address::ADDRESS_BILLING); $customer->addAddress($shippingAddress, true, Address::ADDRESS_SHIPPING); } $merchant = $this->app['merchant.provider']->getMerchant(); $response = new CustomerMigratePresenter($merchant, $customer, $emailAddr, $user->ID); wp_send_json($response->toArray()); } } catch (\Exception $e) { $this->app['logger']->error(ExceptionFormatter::format($e)); wp_send_json(array()); } }