/** * @param Organization $organization * @param array $data * @param Channel $channel * * @return B2bCustomer */ protected function createCustomer(Organization $organization, $data, Channel $channel = null) { $address = new Address(); $customer = new B2bCustomer(); $customer->setName($data['Company']); $customer->setOwner($this->getRandomUserReference()); $customer->setAccount($this->getAccount()); $customer->setOrganization($organization); $address->setCity($data['City']); $address->setStreet($data['StreetAddress']); $address->setPostalCode($data['ZipCode']); $address->setFirstName($data['GivenName']); $address->setLastName($data['Surname']); $address->setCountry($this->getCountryReference($data['Country'])); $address->setRegion($this->getRegionReference($data['Country'], $data['State'])); $customer->setShippingAddress($address); $customer->setBillingAddress(clone $address); if ($channel) { $customer->setDataChannel($channel); } return $customer; }
/** * @param $region * @param $country * * @return Address */ protected function createAddress($region, $country) { $address = new Address(); $address->setRegion($region); $address->setCountry($country); $address->setCity('City'); $address->setStreet('street'); $address->setPostalCode(123456); $address->setFirstName('John'); $address->setLastName('Doe'); $address->setOrganization($this->organization); $this->em->persist($address); return $address; }
/** * @param array $data * @param User $user * * @return Lead */ protected function createLead(array $data, $user) { $lead = new Lead(); /** @var LeadStatus $defaultStatus */ $defaultStatus = $this->em->find('OroCRMSalesBundle:LeadStatus', 'new'); $lead->setStatus($defaultStatus); $lead->setName($data['Company']); $lead->setFirstName($data['GivenName']); $lead->setLastName($data['Surname']); $lead->setEmail($data['EmailAddress']); $lead->setPhoneNumber($data['TelephoneNumber']); $lead->setCompanyName($data['Company']); $lead->setOwner($user); $lead->setDataChannel($this->channel); /** @var Address $address */ $address = new Address(); $address->setLabel('Primary Address'); $address->setCity($data['City']); $address->setStreet($data['StreetAddress']); $address->setPostalCode($data['ZipCode']); $address->setFirstName($data['GivenName']); $address->setLastName($data['Surname']); $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()); } $lead->setAddress($address); $countSources = count($this->sources) - 1; $source = $this->sources[mt_rand(0, $countSources)]; $lead->setSource($source); return $lead; }