/**
  * {@inheritdoc}
  */
 protected function getSerializationConfig()
 {
     $config = ['excluded_fields' => ['email'], 'fields' => ['source' => ['fields' => 'name'], 'method' => ['fields' => 'name'], 'assignedTo' => ['fields' => 'id'], 'owner' => ['fields' => 'id'], 'reportsTo' => ['fields' => 'id'], 'createdBy' => ['fields' => 'id'], 'updatedBy' => ['fields' => 'id'], 'organization' => ['fields' => 'name'], 'emails' => ['exclusion_policy' => 'all', 'fields' => ['email' => null, 'primary' => null], 'orderBy' => ['primary' => 'DESC']], 'phones' => ['exclusion_policy' => 'all', 'fields' => ['phone' => null, 'primary' => null], 'orderBy' => ['primary' => 'DESC']], 'addresses' => AddressApiUtils::getAddressConfig(true), 'groups' => ['fields' => ['organization' => ['fields' => 'name'], 'owner' => ['fields' => 'username']]], 'accounts' => ['fields' => 'id'], 'picture' => ['fields' => 'id']], 'post_serialize' => function (array &$result) {
         $this->postSerializeContact($result);
     }];
     return $config;
 }
 /**
  * {@inheritdoc}
  */
 protected function fixRequestAttributes($entity)
 {
     $formAlias = 'b2bcustomer';
     $customerData = $this->getRequest()->request->get($formAlias);
     // @todo: just a temporary workaround until new API is implemented
     // - convert country name to country code (as result we accept both the code and the name)
     //   also it will be good to accept ISO3 code in future, need to be discussed with product owners
     // - convert region name to region code (as result we accept the combined code, code and name)
     // - move region name to region_text field for unknown region
     if (array_key_exists('shippingAddress', $customerData)) {
         AddressApiUtils::fixAddress($customerData['shippingAddress'], $this->get('doctrine.orm.entity_manager'));
         $this->getRequest()->request->set($formAlias, $customerData);
     }
     if (array_key_exists('billingAddress', $customerData)) {
         AddressApiUtils::fixAddress($customerData['billingAddress'], $this->get('doctrine.orm.entity_manager'));
         $this->getRequest()->request->set($formAlias, $customerData);
     }
     parent::fixRequestAttributes($entity);
 }
 /**
  * {@inheritdoc}
  */
 protected function getSerializationConfig()
 {
     $config = ['fields' => ['shippingAddress' => AddressApiUtils::getAddressConfig(), 'billingAddress' => AddressApiUtils::getAddressConfig(), 'account' => ['fields' => 'id'], 'contact' => ['fields' => 'id'], 'leads' => ['fields' => 'id'], 'opportunities' => ['fields' => 'id'], 'owner' => ['fields' => 'id'], 'organization' => ['fields' => 'name'], 'createdBy' => ['fields' => 'id'], 'updatedBy' => ['fields' => 'id']]];
     return $config;
 }
Exemple #4
0
 /**
  * @param Contact $entity
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function fixRequestAttributes($entity)
 {
     $formAlias = $this->getFormAlias();
     $contactData = $this->getRequest()->request->get($formAlias);
     if (array_key_exists('accounts', $contactData)) {
         $accounts = $contactData['accounts'];
         $appendAccounts = array_key_exists('appendAccounts', $contactData) ? $contactData['appendAccounts'] : array();
         $removeAccounts = array_key_exists('removeAccounts', $contactData) ? $contactData['removeAccounts'] : array();
         if ($entity->getId()) {
             foreach ($entity->getAccounts() as $account) {
                 if (!in_array($account->getId(), $accounts)) {
                     $removeAccounts[] = $account->getId();
                 }
             }
         }
         $contactData['appendAccounts'] = array_merge($appendAccounts, $accounts);
         $contactData['removeAccounts'] = $removeAccounts;
         unset($contactData['accounts']);
         $this->getRequest()->request->set($formAlias, $contactData);
     }
     // @todo: just a temporary workaround until new API is implemented
     // - convert country name to country code (as result we accept both the code and the name)
     //   also it will be good to accept ISO3 code in future, need to be discussed with product owners
     // - convert region name to region code (as result we accept the combined code, code and name)
     // - move region name to region_text field for unknown region
     if (array_key_exists('addresses', $contactData)) {
         foreach ($contactData['addresses'] as &$address) {
             AddressApiUtils::fixAddress($address, $this->get('doctrine.orm.entity_manager'));
         }
         $this->getRequest()->request->set($formAlias, $contactData);
     }
     parent::fixRequestAttributes($entity);
 }