PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.31
Booking for Appointments and Events Calendar – Amelia v1.2.31
2.4.5 2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / src / Application / Commands / User / Customer / AddCustomerCommandHandler.php
ameliabooking / src / Application / Commands / User / Customer Last commit date
AddCustomerCommand.php 1 year ago AddCustomerCommandHandler.php 1 year ago GetCustomerCommand.php 1 year ago GetCustomerCommandHandler.php 1 year ago GetCustomersCommand.php 1 year ago GetCustomersCommandHandler.php 1 year ago UpdateCustomerCommand.php 1 year ago UpdateCustomerCommandHandler.php 1 year ago UpdateCustomerStatusCommand.php 1 year ago UpdateCustomerStatusCommandHandler.php 1 year ago
AddCustomerCommandHandler.php
86 lines
1 <?php
2
3 namespace AmeliaBooking\Application\Commands\User\Customer;
4
5 use AmeliaBooking\Application\Common\Exceptions\AccessDeniedException;
6 use AmeliaBooking\Application\Services\User\CustomerApplicationService;
7 use AmeliaBooking\Application\Services\User\UserApplicationService;
8 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
9 use AmeliaBooking\Domain\Entity\Entities;
10 use AmeliaBooking\Application\Commands\CommandResult;
11 use AmeliaBooking\Application\Commands\CommandHandler;
12
13 /**
14 * Class AddCustomerCommandHandler
15 *
16 * @package AmeliaBooking\Application\Commands\User\Customer
17 */
18 class AddCustomerCommandHandler extends CommandHandler
19 {
20 public $mandatoryFields = [
21 'firstName',
22 'lastName',
23 'email'
24 ];
25
26 /**
27 * @param AddCustomerCommand $command
28 *
29 * @return CommandResult
30 * @throws \Slim\Exception\ContainerValueNotFoundException
31 * @throws AccessDeniedException
32 * @throws InvalidArgumentException
33 * @throws \AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException
34 * @throws \Interop\Container\Exception\ContainerException
35 */
36 public function handle(AddCustomerCommand $command)
37 {
38 /** @var CommandResult $result */
39 $result = new CommandResult();
40
41 /** @var UserApplicationService $userAS */
42 $userAS = $this->getContainer()->get('application.user.service');
43
44 if (!$command->getPermissionService()->currentUserCanWrite(Entities::CUSTOMERS)) {
45 if ($command->getToken()) {
46 if ($userAS->getAuthenticatedUser($command->getToken(), false, 'providerCabinet') === null) {
47 $result->setResult(CommandResult::RESULT_ERROR);
48 $result->setMessage('Could not retrieve user');
49 $result->setData(
50 [
51 'reauthorize' => true
52 ]
53 );
54
55 return $result;
56 }
57 } else {
58 throw new AccessDeniedException('You are not allowed to perform this action!');
59 }
60 }
61
62 /** @var CustomerApplicationService $customerAS */
63 $customerAS = $this->container->get('application.user.customer.service');
64
65 $this->checkMandatoryFields($command);
66
67 if ($command->getField('externalId') === -1) {
68 $command->setField('externalId', null);
69 }
70
71 $userData = $command->getFields();
72
73 $userData['type'] = 'customer';
74
75 $userData = apply_filters('amelia_before_customer_added_filter', $userData);
76
77 do_action('amelia_before_customer_added', $userData);
78
79 $response = $customerAS->createCustomer($userData);
80
81 do_action('amelia_after_customer_added', $response ? $response->getData() : null);
82
83 return $response;
84 }
85 }
86