requestService = $requestService; $this->helper = $helper; $this->customerRepository = $customerRepository; } /** * {@inheritdoc} */ public function postSetOffice($email, $secret, $id, $office) { return $this->requestService->post( $email, $secret, [$this, 'setOffice'], ['id' => $id, 'office' => $office] ); } /** * {@inheritdoc} */ public function setOffice($id, $office) { $result = []; try { $customer = $this->customerRepository->getById($id); if ($this->helper->hasOfficeName($office)) { $customer->setCustomAttribute('lts_office', $this->helper->getOfficeValueByShortName($office)); $this->customerRepository->save($customer); $result[] = array('account' => $customer->getEmail(), 'error' => NULL); } else { throw new LocalizedException(__("'$office' is an invalid office.")); } } catch (\Exception $e) { $result[] = array('account' => isset($customer) ? $customer->getEmail() : $id, 'error' => $e->getMessage()); } return $result; } }