PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.0.2
Booking for Appointments and Events Calendar – Amelia v2.0.2
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 6 months ago GetCustomerCommand.php 1 year ago GetCustomerCommandHandler.php 6 months ago GetCustomersCommand.php 1 year ago GetCustomersCommandHandler.php 6 months ago UpdateCustomerCommand.php 1 year ago UpdateCustomerCommandHandler.php 5 months ago UpdateCustomerStatusCommand.php 1 year ago UpdateCustomerStatusCommandHandler.php 6 months ago
AddCustomerCommandHandler.php
85 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 */
35 public function handle(AddCustomerCommand $command)
36 {
37 /** @var CommandResult $result */
38 $result = new CommandResult();
39
40 /** @var UserApplicationService $userAS */
41 $userAS = $this->getContainer()->get('application.user.service');
42
43 if (!$command->getPermissionService()->currentUserCanWrite(Entities::CUSTOMERS)) {
44 if ($command->getToken()) {
45 if ($userAS->getAuthenticatedUser($command->getToken(), false, 'providerCabinet') === null) {
46 $result->setResult(CommandResult::RESULT_ERROR);
47 $result->setMessage('Could not retrieve user');
48 $result->setData(
49 [
50 'reauthorize' => true
51 ]
52 );
53
54 return $result;
55 }
56 } else {
57 throw new AccessDeniedException('You are not allowed to perform this action!');
58 }
59 }
60
61 /** @var CustomerApplicationService $customerAS */
62 $customerAS = $this->container->get('application.user.customer.service');
63
64 $this->checkMandatoryFields($command);
65
66 if ($command->getField('externalId') === -1) {
67 $command->setField('externalId', null);
68 }
69
70 $userData = $command->getFields();
71
72 $userData['type'] = 'customer';
73
74 $userData = apply_filters('amelia_before_customer_added_filter', $userData);
75
76 do_action('amelia_before_customer_added', $userData);
77
78 $response = $customerAS->createCustomer($userData);
79
80 do_action('amelia_after_customer_added', $response ? $response->getData() : null);
81
82 return $response;
83 }
84 }
85