public function testEmailDoesNotExist() { $email = new Email(); $email->setAlias('similar')->setEmail('*****@*****.**'); $entity = new Customer(); $this->assertFalse($entity->getEmailIndex($email)); }
public function testBuildingEntity() { $entity = new Email(); $this->assertInstanceOf('Expressly\\Entity\\Email', $entity->setEmail('*****@*****.**')); $this->assertInstanceOf('Expressly\\Entity\\Email', $entity->setAlias('default')); $this->assertEquals('*****@*****.**', $entity->getEmail()); $this->assertEquals('default', $entity->getAlias()); $this->assertJson(json_encode($entity->toArray())); $this->assertJsonStringEqualsJsonString(json_encode($entity->toArray()), json_encode(array('email' => '*****@*****.**', 'alias' => 'default'))); }
public function execute() { $emailAddress = $this->_request->getParam('email'); $result = $this->resultFactory->create(ResultFactory::TYPE_JSON); try { $magentoCustomer = $this->customerRegistry->retrieveByEmail($emailAddress); if (!$magentoCustomer->isEmpty()) { $customer = new Customer(); $customer->setFirstName($magentoCustomer->getFirstname())->setLastName($magentoCustomer->getLastname()); $email = new Email(); $email->setAlias('default')->setEmail($emailAddress); $customer->addEmail($email); $defaultBilling = $magentoCustomer->getDefaultBillingAddress(); $defaultShipping = $magentoCustomer->getDefaultShippingAddress(); foreach ($magentoCustomer->getAddresses() as $magentoAddress) { $address = new Address(); $address->setFirstName($magentoAddress->getFirstname())->setLastName($magentoAddress->getLastname())->setCompanyName($magentoAddress->getCompany())->setAddress1($magentoAddress->getStreetLine(1))->setAddress2($magentoAddress->getStreetLine(2))->setCity($magentoAddress->getCity())->setStateProvince($magentoAddress->getRegion())->setZip($magentoAddress->getPostcode())->setCountry($magentoAddress->getCountry()); $phone = new Phone(); $customer->addPhone($phone); $address->setPhonePosition($customer->getPhoneIndex($phone)); $primary = false; $type = null; if ($defaultBilling->getId() == $magentoAddress->getId()) { $primary = true; $type = Address::ADDRESS_BILLING; } if ($defaultShipping->getId() == $magentoAddress->getId()) { $primary = true; $type = $type == Address::ADDRESS_BILLING ? Address::ADDRESS_BOTH : Address::ADDRESS_SHIPPING; } $customer->addAddress($address, $primary, $type); } $presenter = new CustomerMigratePresenter($this->merchant, $customer, $emailAddress, 55); $result->setData($presenter->toArray()); } } catch (\Exception $e) { // log error $result->setData([]); } return $result; }
public function showAction() { $this->getResponse()->setHeader('Content-type', 'application/json'); $route = $this->resolver->process(preg_replace('/.*(expressly\\/.*)/i', '/${1}', $_SERVER['REQUEST_URI'])); if ($route instanceof Route) { $emailAddress = $this->getRequest()->getParam('email'); $merchant = $this->app['merchant.provider']->getMerchant(); try { $mageCustomer = \Mage::getModel('customer/customer'); $mageCustomer->setWebsiteId(\Mage::app()->getWebsite()->getId()); $mageCustomer->loadByEmail($emailAddress); $reference = $mageCustomer->getId(); if ($reference) { $customer = new Customer(); $customer->setFirstName($mageCustomer->getFirstname())->setLastName($mageCustomer->getLastname())->setDateUpdated(new DateTime($mageCustomer->getCreatedAt())); if ($mageCustomer->getDob()) { $customer->setBirthday(new DateTime($mageCustomer->getDob())); } if ($mageCustomer->getTaxvat()) { $customer->setTaxNumber($mageCustomer->getTaxvat()); } $gender = $mageCustomer->getGender(); if ($gender == 1 || $gender == 2) { $customer->setGender($mageCustomer->getGender() == 1 ? 'M' : 'F'); } $email = new Email(); $email->setAlias('default')->setEmail($emailAddress); $customer->addEmail($email); $defaultBilling = $mageCustomer->getDefaultBilling(); $defaultShipping = $mageCustomer->getDefaultShipping(); foreach ($mageCustomer->getAddresses() as $mageAddress) { $address = new Address(); $address->setFirstName($mageAddress->getFirstname())->setLastName($mageAddress->getLastname())->setCompanyName($mageAddress->getCompany())->setAddress1($mageAddress->getStreet1())->setAddress2($mageAddress->getStreet2())->setCity($mageAddress->getCity())->setStateProvince($mageAddress->getRegionCode())->setZip($mageAddress->getPostcode())->setCountry($mageAddress->getCountry()); $phone = new Phone(); $phone->setType(Phone::PHONE_TYPE_HOME)->setNumber($mageAddress->getTelephone()); $customer->addPhone($phone); $address->setPhonePosition($customer->getPhoneIndex($phone)); $primary = false; $type = null; if ($mageAddress->getId() == $defaultBilling) { $primary = true; $type = Address::ADDRESS_BILLING; } if ($mageAddress->getId() == $defaultShipping) { $primary = true; $type = $type == Address::ADDRESS_BILLING ? Address::ADDRESS_BOTH : Address::ADDRESS_SHIPPING; } $customer->addAddress($address, $primary, $type); } $presenter = new CustomerMigratePresenter($merchant, $customer, $emailAddress, $reference); $this->getResponse()->setBody(json_encode($presenter->toArray())); } else { $this->getResponse()->setHttpResponseCode(404); } } catch (\Exception $e) { $this->logger->error(ExceptionFormatter::format($e)); $this->getResponse()->setBody(json_encode(array())); } } else { $this->getResponse()->setHttpResponseCode(401); } }