예제 #1
0
 /**
  * "Success" form handler
  *
  * @param Address $entity
  */
 protected function onSuccess(Address $entity)
 {
     if (null === $entity->getOrganization()) {
         $entity->setOrganization($this->organization);
     }
     $this->manager->persist($entity);
     $this->manager->flush();
 }
예제 #2
0
 /**
  * @return array
  */
 public function sourceDataProvider()
 {
     $address1 = new Address();
     $address2 = new Address();
     $badSource = null;
     $region1 = new BAPRegion(self::TEST_REGION_COMBINED_CODE);
     $region1->setName(self::TEST_REGION_NAME);
     $address1->setRegion($region1);
     $address2->setRegionText(self::TEST_REGION_NAME);
     return ['take region from address, found in magento DB, use region ID' => [$address1, true, ['region' => null, 'region_id' => self::TEST_MAGENTO_REGION_ID]], 'take region from address, not found in magento DB, use region name' => [$address1, false, ['region' => self::TEST_REGION_NAME, 'region_id' => null]], 'region not set, use region text' => [$address2, null, ['region' => self::TEST_REGION_NAME, 'region_id' => null]], 'bad type given' => [$badSource, null, null, '\\InvalidArgumentException']];
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $addressTypeRepo = $manager->getRepository('OroAddressBundle:AddressType');
     foreach (self::$data as $item) {
         $customer = new Customer();
         $customer->setEmail($item['email']);
         $customer->setFirstName($item['firstName']);
         $customer->setLastName($item['lastName']);
         foreach ($item['addresses'] as $addressData) {
             $address = new Address();
             $address->setPostalCode($addressData['postalCode']);
             $address->addType($addressTypeRepo->findOneBy(['name' => $addressData['type']]));
             $customer->addAddress($address);
             $manager->persist($address);
         }
         $manager->persist($customer);
         $manager->flush();
         $this->setReference($item['reference'], $customer);
     }
 }
예제 #4
0
 /**
  * @dataProvider addressTypesUpdateDataProvider
  *
  * @param string          $priority
  * @param ArrayCollection $remoteTypes
  * @param ArrayCollection $localTypes
  * @param ArrayCollection $contactTypes
  * @param array           $expectedTypeNames
  */
 public function testAddressTypesUpdate($priority, ArrayCollection $remoteTypes, ArrayCollection $localTypes, ArrayCollection $contactTypes, array $expectedTypeNames)
 {
     $channel = new Channel();
     $channel->getSynchronizationSettingsReference()->offsetSet('syncPriority', $priority);
     $testCountry = new Country('US');
     $contact = new Contact();
     $contactAddress = new ContactAddress();
     $contactAddress->setId(self::TEST_CONTACT_ADDRESS_ID);
     $contactAddress->setTypes($contactTypes);
     $contactAddress->setCountry($testCountry);
     $contact->addAddress($contactAddress);
     $phone = new ContactPhone();
     $phone->setPhone('123-123-123');
     $phone->setOwner($contact);
     $contact->addPhone($phone);
     $localCustomer = new Customer();
     $localAddress = new Address();
     $localAddress->setContactAddress($contactAddress);
     $localAddress->setTypes($localTypes);
     $localAddress->setCountry($testCountry);
     $localAddress->setPhone('123-123-123');
     $localAddress->setContactPhone($phone);
     $localCustomer->addAddress($localAddress);
     $remoteCustomer = new Customer();
     $remoteAddress = new Address();
     $remoteAddress->setContactAddress($contactAddress);
     $remoteAddress->setTypes($remoteTypes);
     $remoteAddress->setCountry($testCountry);
     $remoteAddress->setContactPhone($phone);
     $remoteCustomer->addAddress($remoteAddress);
     $helper = $this->getHelper($channel);
     $helper->merge($remoteCustomer, $localCustomer, $contact);
     $this->assertCount(1, $contact->getAddresses());
     $this->assertEquals($expectedTypeNames, $contactAddress->getTypeNames());
 }
예제 #5
0
 /**
  * Gets a list of all phone numbers available for the given Address object
  *
  * @param Address $object
  *
  * @return array of [phone number, phone owner]
  */
 public function getPhoneNumbers($object)
 {
     $result = [];
     $phone = $object->getPhone();
     if (!empty($phone)) {
         $result[] = [$phone, $object];
     }
     if ($object->getContactPhone() && $object->getContactPhone()->getPhone() !== $phone) {
         $result[] = [$object->getContactPhone()->getPhone(), $object->getContactPhone()->getOwner()];
     }
     return $result;
 }
예제 #6
0
 /**
  * @param $region
  * @param $country
  *
  * @return MagentoAddress
  */
 protected function createMagentoAddress($region, $country)
 {
     $address = new MagentoAddress();
     $address->setRegion($region);
     $address->setCountry($country);
     $address->setCity('City');
     $address->setStreet('street');
     $address->setPostalCode(123456);
     $address->setFirstName('John');
     $address->setLastName('Doe');
     $address->setLabel('label');
     $address->setPrimary(true);
     $address->setOrganization('oro');
     $address->setOriginId(1);
     $address->setOrganization($this->organization);
     $this->em->persist($address);
     return $address;
 }
예제 #7
0
 /**
  * Find correspondent to local address by remote one
  *
  * @param Customer $customer
  * @param Address  $remoteAddress
  *
  * @return Address|false
  */
 protected function getCorrespondentLocalAddress(Customer $customer, Address $remoteAddress)
 {
     $filtered = $customer->getAddresses()->filter(function (Address $address) use($remoteAddress) {
         return $remoteAddress->getOriginId() === $address->getOriginId();
     });
     return $filtered->first();
 }
예제 #8
0
 /**
  * @param Address $address
  */
 public function markAddressRemoved(Address $address)
 {
     $address->setSyncState(Address::MAGENTO_REMOVED);
 }
예제 #9
0
 /**
  * @SuppressWarnings(PHPMD)
  *
  * @dataProvider  getDataProvider
  *
  * @param array     $fields
  * @param \stdClass $checkingObject
  */
 public function testProcess(array $fields, $checkingObject)
 {
     $customerReverseProcessor = new CustomerReverseProcessor();
     $checkingObject->entity = $this->customer;
     $this->customer->expects($this->any())->method('getOriginId')->will($this->returnValue(true));
     $this->customer->expects($this->any())->method('getEmail')->will($this->returnValue($fields['email']));
     $this->contact->expects($this->any())->method('getPrimaryEmail')->will($this->returnValue($fields['emailContact']));
     $this->customer->expects($this->any())->method('getFirstName')->will($this->returnValue($fields['firstName']));
     $this->contact->expects($this->any())->method('getFirstName')->will($this->returnValue($fields['firstNameContact']));
     $this->customer->expects($this->any())->method('getLastName')->will($this->returnValue($fields['lastName']));
     $this->contact->expects($this->any())->method('getLastName')->will($this->returnValue($fields['lastNameContact']));
     $this->customer->expects($this->any())->method('getNamePrefix')->will($this->returnValue($fields['prefix']));
     $this->contact->expects($this->any())->method('getNamePrefix')->will($this->returnValue($fields['prefixContact']));
     $this->customer->expects($this->any())->method('getNameSuffix')->will($this->returnValue($fields['suffix']));
     $this->contact->expects($this->any())->method('getNameSuffix')->will($this->returnValue($fields['suffixContact']));
     $this->customer->expects($this->any())->method('getBirthday')->will($this->returnValue($fields['dob']));
     $this->contact->expects($this->any())->method('getBirthday')->will($this->returnValue($fields['dobContact']));
     $this->customer->expects($this->any())->method('getGender')->will($this->returnValue($fields['gender']));
     $this->contact->expects($this->any())->method('getGender')->will($this->returnValue($fields['genderContact']));
     $this->customer->expects($this->any())->method('getMiddleName')->will($this->returnValue($fields['middleName']));
     $this->contact->expects($this->any())->method('getMiddleName')->will($this->returnValue($fields['middleNameContact']));
     $this->address->expects($this->any())->method('getCity')->will($this->returnValue($fields['cityAddress']));
     $this->contactAddress->expects($this->any())->method('getCity')->will($this->returnValue($fields['cityContactAddress']));
     $this->address->expects($this->any())->method('getOrganization')->will($this->returnValue($fields['organizationAddress']));
     $this->contactAddress->expects($this->any())->method('getOrganization')->will($this->returnValue($fields['organizationContactAddress']));
     $this->address->expects($this->any())->method('getCountry')->will($this->returnValue($fields['countryAddress']));
     $this->contactAddress->expects($this->any())->method('getCountry')->will($this->returnValue($fields['countryContactAddress']));
     $this->address->expects($this->any())->method('getFirstName')->will($this->returnValue($fields['firstNameAddress']));
     $this->contactAddress->expects($this->any())->method('getFirstName')->will($this->returnValue($fields['firstNameContactAddress']));
     $this->address->expects($this->any())->method('getLastName')->will($this->returnValue($fields['lastNameAddress']));
     $this->contactAddress->expects($this->any())->method('getLastName')->will($this->returnValue($fields['lastNameContactAddress']));
     $this->address->expects($this->any())->method('getMiddleName')->will($this->returnValue($fields['middleNameAddress']));
     $this->contactAddress->expects($this->any())->method('getMiddleName')->will($this->returnValue($fields['middleNameContactAddress']));
     $this->address->expects($this->any())->method('getPostalCode')->will($this->returnValue($fields['postalCodeAddress']));
     $this->contactAddress->expects($this->any())->method('getPostalCode')->will($this->returnValue($fields['postalCodeContactAddress']));
     $this->address->expects($this->any())->method('getNamePrefix')->will($this->returnValue($fields['prefixAddress']));
     $this->contactAddress->expects($this->any())->method('getNamePrefix')->will($this->returnValue($fields['prefixContactAddress']));
     $this->address->expects($this->any())->method('getRegion')->will($this->returnValue($fields['regionAddress']));
     $this->contactAddress->expects($this->any())->method('getRegion')->will($this->returnValue($fields['regionContactAddress']));
     $this->address->expects($this->any())->method('getRegionText')->will($this->returnValue($fields['regionTextAddress']));
     $this->contactAddress->expects($this->any())->method('getRegionText')->will($this->returnValue($fields['regionTextContactAddress']));
     $this->address->expects($this->any())->method('getStreet')->will($this->returnValue($fields['streetAddress']));
     $this->contactAddress->expects($this->any())->method('getStreet')->will($this->returnValue($fields['streetContactAddress']));
     $this->address->expects($this->any())->method('getNameSuffix')->will($this->returnValue($fields['nameSuffixAddress']));
     $this->contactAddress->expects($this->any())->method('getNameSuffix')->will($this->returnValue($fields['nameSuffixContactAddress']));
     $this->address->expects($this->any())->method('getPhone')->will($this->returnValue($fields['phone']));
     $this->contactPhone->expects($this->any())->method('getPhone')->will($this->returnValue($fields['phone']));
     $this->contact->expects($this->any())->method('getAddresses')->will($this->returnValue([$this->contactAddress]));
     if (!empty($checkingObject->object['addresses'])) {
         foreach ($checkingObject->object['addresses'] as &$address) {
             $address['entity'] = $this->address;
             if (!empty($address['status'])) {
                 if ('update' === $address['status']) {
                     $address['object']['country'] = $this->country;
                     $address['object']['region'] = $this->region;
                 }
             }
         }
         unset($address);
     }
     $result = $customerReverseProcessor->process($this->customer);
     $this->assertEquals($checkingObject, $result);
 }
예제 #10
0
 public function testUpdateAddress()
 {
     $transportSetting = $this->getMock('Oro\\Bundle\\IntegrationBundle\\Entity\\Transport');
     $channel = new Channel();
     $channel->setTransport($transportSetting);
     $channel->getSynchronizationSettingsReference()->offsetSet('syncPriority', TwoWaySyncConnectorInterface::LOCAL_WINS);
     $customer = new Customer();
     $customer->setOriginId(self::TEST_CUSTOMER_ID);
     $customer->setChannel($channel);
     $customer->setFirstName(self::TEST_CUSTOMER_FIRSTNAME);
     $customer->setLastName(self::TEST_CUSTOMER_LASTNAME);
     $contactAddress = new ContactAddress();
     $address = new Address();
     $address->setFirstName(self::TEST_FIRSTNAME);
     $address->setCountry(new Country(self::TEST_ADDRESS_COUNTRY));
     $address->setRegionText(self::TEST_ADDRESS_REGION);
     $address->setStreet(self::TEST_ADDRESS_STREET);
     $address->setContactAddress($contactAddress);
     $address->setOriginId(1);
     $this->transport->expects($this->once())->method('init');
     $this->regionConverter->expects($this->once())->method('toMagentoData')->with($this->identicalTo($address))->will($this->returnValue(['region' => self::TEST_ADDRESS_REGION_RESOLVED, 'region_id' => null]));
     $this->transport->expects($this->at(2))->method('getCustomerAddresses')->with($this->identicalTo($customer))->will($this->returnValue([(object) ['customer_address_id' => 1, 'telephone' => '911', 'middlename' => 'testMiddleName', 'suffix' => 'testSuffix', 'company' => 'testCompany', 'city' => 'testCity', 'is_default_shipping' => false, 'is_default_billing' => false]]));
     $this->transport->expects($this->at(3))->method('call')->with($this->equalTo(SoapTransport::ACTION_CUSTOMER_ADDRESS_UPDATE), $this->equalTo(['addressId' => 1, 'addressData' => ['prefix' => null, 'firstname' => 'newName', 'middlename' => null, 'lastname' => 'newLastName', 'suffix' => null, 'company' => null, 'street' => [0 => self::TEST_ADDRESS_STREET, 1 => null], 'city' => null, 'postcode' => null, 'country_id' => self::TEST_ADDRESS_COUNTRY, 'region' => self::TEST_ADDRESS_REGION_RESOLVED, 'region_id' => null, 'created_at' => null, 'updated_at' => null, 'is_default_billing' => false, 'is_default_shipping' => false, 'telephone' => 'no phone']]))->will($this->returnValue(true));
     $this->em->expects($this->atLeastOnce())->method('persist');
     $this->em->expects($this->once())->method('flush');
     $data = [];
     array_push($data, (object) ['entity' => $customer, 'object' => ['addresses' => [['entity' => $address, 'status' => AbstractReverseProcessor::UPDATE_ENTITY, 'object' => ['firstname' => 'newName', 'lastname' => 'newLastName']]]]]);
     $this->writer->write($data);
 }