Beispiel #1
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());
 }
Beispiel #2
0
 /**
  * Create a Contact
  *
  * @param array $data
  * @param int $iteration
  * @return Contact
  */
 private function createContact(array $data, $iteration = 0)
 {
     $contact = new Contact();
     $contact->setFirstName($data['GivenName']);
     $lastName = $data['Surname'];
     if ($iteration) {
         $lastName .= '_' . $iteration;
     }
     $contact->setLastName($lastName);
     $contact->setNamePrefix($data['Title']);
     $phone = new ContactPhone($data['TelephoneNumber']);
     $phone->setPrimary(true);
     $contact->addPhone($phone);
     $email = new ContactEmail($data['EmailAddress']);
     $email->setPrimary(true);
     $contact->addEmail($email);
     $date = \DateTime::createFromFormat('m/d/Y', $data['Birthday']);
     $contact->setBirthday($date);
     /** @var ContactAddress $address */
     $address = new ContactAddress();
     $address->setCity($data['City']);
     $address->setStreet($data['StreetAddress']);
     $address->setPostalCode($data['ZipCode']);
     $address->setFirstName($data['GivenName']);
     $address->setLastName($data['Surname']);
     $address->setPrimary(true);
     $isoCode = $data['Country'];
     $country = array_filter($this->countries, function (Country $a) use($isoCode) {
         return $a->getIso2Code() == $isoCode;
     });
     $country = array_values($country);
     /** @var Country $country */
     $country = $country[0];
     $idRegion = $data['State'];
     /** @var Collection $regions */
     $regions = $country->getRegions();
     $region = $regions->filter(function (Region $a) use($idRegion) {
         return $a->getCode() == $idRegion;
     });
     $address->setCountry($country);
     if (!$region->isEmpty()) {
         $address->setRegion($region->first());
     }
     $contact->addAddress($address);
     return $contact;
 }
Beispiel #3
0
 public function testAddresses()
 {
     $addressOne = new ContactAddress();
     $addressOne->setCountry(new Country('US'));
     $addressTwo = new ContactAddress();
     $addressTwo->setCountry(new Country('UK'));
     $addressThree = new ContactAddress();
     $addressThree->setCountry(new Country('RU'));
     $addresses = array($addressOne, $addressTwo);
     $contact = new Contact();
     $this->assertSame($contact, $contact->resetAddresses($addresses));
     $actual = $contact->getAddresses();
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $actual);
     $this->assertEquals($addresses, $actual->toArray());
     $this->assertSame($contact, $contact->addAddress($addressTwo));
     $actual = $contact->getAddresses();
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $actual);
     $this->assertEquals($addresses, $actual->toArray());
     $this->assertSame($contact, $contact->addAddress($addressThree));
     $actual = $contact->getAddresses();
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $actual);
     $this->assertEquals(array($addressOne, $addressTwo, $addressThree), $actual->toArray());
     $this->assertSame($contact, $contact->removeAddress($addressOne));
     $actual = $contact->getAddresses();
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $actual);
     $this->assertEquals(array(1 => $addressTwo, 2 => $addressThree), $actual->toArray());
     $this->assertSame($contact, $contact->removeAddress($addressOne));
     $actual = $contact->getAddresses();
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $actual);
     $this->assertEquals(array(1 => $addressTwo, 2 => $addressThree), $actual->toArray());
 }
Beispiel #4
0
 public function testAddressCreateDefaultData()
 {
     $transportSetting = $this->getMock('Oro\\Bundle\\IntegrationBundle\\Entity\\Transport');
     $channel = new Channel();
     $channel->setTransport($transportSetting);
     $customer = new Customer();
     $customer->setOriginId(self::TEST_CUSTOMER_ID);
     $customer->setChannel($channel);
     $customer->setFirstName(self::TEST_CUSTOMER_FIRSTNAME);
     $customer->setLastName(self::TEST_CUSTOMER_LASTNAME);
     $address = new ContactAddress();
     $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);
     $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(3))->method('call')->with($this->equalTo(SoapTransport::ACTION_CUSTOMER_ADDRESS_CREATE), $this->equalTo(['customerId' => self::TEST_CUSTOMER_ID, 'addressData' => ['telephone' => 'no phone', 'prefix' => null, 'firstname' => self::TEST_FIRSTNAME, 'middlename' => null, 'lastname' => self::TEST_CUSTOMER_LASTNAME, '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]]))->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::NEW_ENTITY, 'magentoId' => self::TEST_CUSTOMER_ID]]]]);
     $this->writer->write($data);
 }