/** * Update an existing birth date * @param CustomerEvent $event * @throws \Exception * @throws \Propel\Runtime\Exception\PropelException */ public function updateBirthDate(CustomerEvent $event) { if ($this->request->fromApi() === false) { // Get date from input depending on request origin (front or back) if ($this->request->fromFront() === true) { $birthDate = $this->request->get('thelia_customer_profile_update')['birth_date']; } elseif ($this->request->fromAdmin() === true) { $birthDate = $this->request->get('thelia_customer_update')['birth_date']; } else { throw new Exception('No form found'); } // Format birth date $birthDate = new \DateTime($birthDate['year'] . '-' . $birthDate['month'] . '-' . $birthDate['day']); // Check if the customer already have a birth date if (null === ($customerBirthDate = CustomerBirthDateQuery::create()->findOneById($event->getCustomer()->getId()))) { // Create a new birth date $this->doCreateBirthDate($event, $birthDate); } else { // Save it $customerBirthDate->setBirthDate($birthDate)->save(); } } }
public function delete(CustomerEvent $event) { if (null !== ($customer = $event->getCustomer())) { if (true === $customer->hasOrder()) { throw new CustomerException(Translator::getInstance()->trans("Impossible to delete a customer who already have orders")); } $customer->delete(); } }
/** * @param CustomerEvent $event */ public function afterCreateCustomer(CustomerEvent $event) { $form = $this->request->request->get(self::THELIA_CUSTOMER_CREATE_FORM_NAME); if (is_null($form) or !array_key_exists(CustomerFamilyFormListener::CUSTOMER_FAMILY_CODE_FIELD_NAME, $form)) { // Nothing to create the new CustomerCustomerFamily => stop here ! return; } $customerFamily = CustomerFamilyQuery::create()->findOneByCode($form[CustomerFamilyFormListener::CUSTOMER_FAMILY_CODE_FIELD_NAME]); if (is_null($customerFamily)) { // No family => no CustomerCustomerFamily to update. return; } $customerFamilyId = $customerFamily->getId(); // Ignore SIRET and VAT if the customer is not professional $siret = $customerFamily->getCode() == CustomerFamily::CUSTOMER_FAMILY_PROFESSIONAL ? $form[CustomerFamilyFormListener::CUSTOMER_FAMILY_SIRET_FIELD_NAME] : ''; $vat = $customerFamily->getCode() == CustomerFamily::CUSTOMER_FAMILY_PROFESSIONAL ? $form[CustomerFamilyFormListener::CUSTOMER_FAMILY_VAT_FIELD_NAME] : ''; $updateEvent = new CustomerCustomerFamilyEvent($event->getCustomer()->getId()); $updateEvent->setCustomerFamilyId($customerFamilyId)->setSiret($siret)->setVat($vat); $event->getDispatcher()->dispatch(CustomerFamilyEvents::CUSTOMER_CUSTOMER_FAMILY_UPDATE, $updateEvent); }