/** * @param \Symfony\Component\HttpFoundation\Request $request * * @return \Symfony\Component\HttpFoundation\JsonResponse */ public function editAction(Request $request) { $form = $this->getFactory()->createCustomerForm($request); if ($form->isValid() === true) { $customerTransfer = new CustomerTransfer(); $customerTransfer->fromArray($form->getRequestData()); $this->getFacade()->updateCustomer($customerTransfer); } return $this->jsonResponse($form->renderData()); }
/** * @param \Symfony\Component\HttpFoundation\Request $request * * @return array|\Symfony\Component\HttpFoundation\RedirectResponse */ public function indexAction(Request $request) { $dataProvider = $this->getFactory()->createCustomerFormDataProvider(); $form = $this->getFactory()->createCustomerForm($dataProvider->getData(), $dataProvider->getOptions())->handleRequest($request); if ($form->isValid()) { $customerTransfer = new CustomerTransfer(); $customerTransfer->fromArray($form->getData(), true); $this->getFacade()->registerCustomer($customerTransfer); return $this->redirectResponse('/customer'); } return $this->viewResponse(['form' => $form->createView()]); }
/** * @param \Symfony\Component\HttpFoundation\Request $request * * @return array|\Symfony\Component\HttpFoundation\RedirectResponse */ public function indexAction(Request $request) { $idCustomer = $this->castId($request->query->get(CustomerConstants::PARAM_ID_CUSTOMER)); $dataProvider = $this->getFactory()->createCustomerUpdateFormDataProvider(); $form = $this->getFactory()->createCustomerUpdateForm($dataProvider->getData($idCustomer), $dataProvider->getOptions($idCustomer))->handleRequest($request); if ($form->isValid()) { $customerTransfer = new CustomerTransfer(); $customerTransfer->fromArray($form->getData(), true); $this->getFacade()->updateCustomer($customerTransfer); $defaultBilling = $customerTransfer->getBillingAddress() ?: null; if (!$defaultBilling) { $this->updateBillingAddress($idCustomer, $defaultBilling); } $defaultShipping = $customerTransfer->getShippingAddress() ?: null; if (!$defaultShipping) { $this->updateShippingAddress($idCustomer, $defaultShipping); } return $this->redirectResponse(sprintf('/customer/view/?%s=%d', CustomerConstants::PARAM_ID_CUSTOMER, $idCustomer)); } return $this->viewResponse(['form' => $form->createView(), 'idCustomer' => $idCustomer]); }
/** * @param \Generated\Shared\Transfer\CustomerTransfer $customerTransfer * * @throws \Spryker\Zed\Customer\Business\Exception\CustomerNotFoundException * * @return \Generated\Shared\Transfer\CustomerTransfer */ public function confirmRegistration(CustomerTransfer $customerTransfer) { $customerEntity = $this->queryContainer->queryCustomerByRegistrationKey($customerTransfer->getRegistrationKey())->findOne(); if ($customerEntity === null) { throw new CustomerNotFoundException(sprintf('Customer for registration key `%s` not found', $customerTransfer->getRegistrationKey())); } $customerEntity->setRegistered(new \DateTime()); $customerEntity->setRegistrationKey(null); $customerEntity->save(); $customerTransfer->fromArray($customerEntity->toArray(), true); return $customerTransfer; }
/** * @param \Orm\Zed\Customer\Persistence\SpyCustomer $entity * * @return \Generated\Shared\Transfer\CustomerTransfer */ protected function entityToCustomerTransfer(SpyCustomer $entity) { $addressTransfer = new CustomerTransfer(); return $addressTransfer->fromArray($entity->toArray(), true); }