PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.20
Booking for Appointments and Events Calendar – Amelia v1.2.20
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 7 years ago AddCustomerCommandHandler.php 1 year ago GetCustomerCommand.php 7 years ago GetCustomerCommandHandler.php 1 year ago GetCustomersCommand.php 7 years ago GetCustomersCommandHandler.php 1 year ago UpdateCustomerCommand.php 7 years ago UpdateCustomerCommandHandler.php 1 year ago UpdateCustomerStatusCommand.php 1 year ago UpdateCustomerStatusCommandHandler.php 1 year ago
AddCustomerCommandHandler.php
87 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
21 public $mandatoryFields = [
22 'firstName',
23 'lastName',
24 'email'
25 ];
26
27 /**
28 * @param AddCustomerCommand $command
29 *
30 * @return CommandResult
31 * @throws \Slim\Exception\ContainerValueNotFoundException
32 * @throws AccessDeniedException
33 * @throws InvalidArgumentException
34 * @throws \AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException
35 * @throws \Interop\Container\Exception\ContainerException
36 */
37 public function handle(AddCustomerCommand $command)
38 {
39 /** @var CommandResult $result */
40 $result = new CommandResult();
41
42 /** @var UserApplicationService $userAS */
43 $userAS = $this->getContainer()->get('application.user.service');
44
45 if (!$command->getPermissionService()->currentUserCanWrite(Entities::CUSTOMERS)) {
46 if ($command->getToken()) {
47 if ($userAS->getAuthenticatedUser($command->getToken(), false, 'providerCabinet') === null) {
48 $result->setResult(CommandResult::RESULT_ERROR);
49 $result->setMessage('Could not retrieve user');
50 $result->setData(
51 [
52 'reauthorize' => true
53 ]
54 );
55
56 return $result;
57 }
58 } else {
59 throw new AccessDeniedException('You are not allowed to perform this action!');
60 }
61 }
62
63 /** @var CustomerApplicationService $customerAS */
64 $customerAS = $this->container->get('application.user.customer.service');
65
66 $this->checkMandatoryFields($command);
67
68 if ($command->getField('externalId') === -1) {
69 $command->setField('externalId', null);
70 }
71
72 $userData = $command->getFields();
73
74 $userData['type'] = 'customer';
75
76 $userData = apply_filters('amelia_before_customer_added_filter', $userData);
77
78 do_action('amelia_before_customer_added', $userData);
79
80 $response = $customerAS->createCustomer($userData);
81
82 do_action('amelia_after_customer_added', $response? $response->getData() : null);
83
84 return $response;
85 }
86 }
87