예제 #1
0
 /**
  * {@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);
 }
예제 #2
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);
 }