Пример #1
0
 /**
  * Gets a list of all phone numbers available for the given Customer object
  *
  * @param Customer $object
  *
  * @return array of [phone number, phone owner]
  */
 public function getPhoneNumbers($object)
 {
     $contact = $object->getContact();
     if (!$contact) {
         return [];
     }
     return $this->rootProvider->getPhoneNumbers($contact);
 }
Пример #2
0
 /**
  * Update $entity with new contact data
  *
  * @param Customer $remoteData
  * @param Customer $localData
  * @param Contact  $contact
  */
 protected function updateContact(Customer $remoteData, Customer $localData, Contact $contact)
 {
     $helper = new ContactImportHelper($localData->getChannel(), $this->addressHelper);
     if ($localData->getContact() && $localData->getContact()->getId()) {
         $helper->merge($remoteData, $localData, $localData->getContact());
     } else {
         $addresses = $localData->getAddresses();
         // loop by imported addresses, add new only
         /** @var \OroCRM\Bundle\ContactBundle\Entity\ContactAddress $address */
         foreach ($contact->getAddresses() as $key => $address) {
             $helper->prepareAddress($address);
             if (!$address->getCountry()) {
                 $contact->removeAddress($address);
                 continue;
             }
             // @TODO find possible solution
             // guess parent address by key
             if ($entity = $addresses->get($key)) {
                 $entity->setContactAddress($address);
             }
         }
         // @TODO find possible solution
         // guess parent $phone by key
         foreach ($contact->getPhones() as $key => $phone) {
             $contactPhone = $this->getContactPhoneFromContact($contact, $phone);
             if ($entity = $addresses->get($key)) {
                 $entity->setContactPhone($contactPhone ? $contactPhone : $phone);
             }
         }
         // populate default owner only for new contacts
         $this->defaultOwnerHelper->populateChannelOwner($contact, $localData->getChannel());
         $localData->setContact($contact);
     }
 }
Пример #3
0
 protected function setAddresses(Customer $object, array $data, $format = null, array $context = array())
 {
     if (!empty($data['contact']['addresses'])) {
         $data['addresses'] = $data['contact']['addresses'];
         /** @var \Doctrine\Common\Collections\Collection $addresses */
         $addresses = $this->denormalizeObject($data, 'addresses', MagentoConnectorInterface::CUSTOMER_ADDRESSES_TYPE, $format, $context);
         // TODO Should be fixed during CRM-1185
         $originIds = array();
         foreach ($data['addresses'] as $key => $address) {
             if (!empty($address['customerAddressId'])) {
                 $originIds[$key] = $address['customerAddressId'];
             }
         }
         if (!empty($addresses)) {
             $contact = $object->getContact();
             /** @var Address $address */
             foreach ($addresses as $key => $address) {
                 if (!empty($originIds[$key])) {
                     $address->setOriginId($originIds[$key]);
                 }
                 if ($contactPhone = $address->getContactPhone()) {
                     $contactPhone->setOwner($contact);
                 }
             }
             $object->resetAddresses($addresses);
         }
     }
 }