PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.4
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.4
1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk 1.2.0 All 47 releases
fluent-cart / app / Services / ShortCodeParser / Parsers / UserParser.php

UserParser.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.4, at app/Services/ShortCodeParser/Parsers/UserParser.php

83 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Services\ShortCodeParser\Parsers;
4
5 use FluentCart\Framework\Support\Arr;
6
7 class UserParser extends BaseParser
8 {
9 private $user;
10 private $userId;
11
12 public function __construct($data)
13 {
14 if (Arr::has($data, 'user_id')) {
15 $uId = Arr::get($data, 'user_id', null);
16 } else {
17 $uId = Arr::get($data, 'customer.user_id', null);
18 }
19
20 $this->userId = $uId;
21 $this->setUser();
22 parent::__construct($data);
23 }
24
25 protected array $methodMap = [
26 'admin_email' => 'getAdminEmail',
27 'site_url' => 'getSiteUrl',
28 'site_name' => 'getSiteName',
29 ];
30
31 protected function setUser()
32 {
33 $this->user = get_user_by('ID', $this->userId) ?: null;
34 }
35
36 public function parse($accessor = null, $code = null): ?string
37 {
38 return $this->get($accessor,$code);
39 }
40
41 public function getID()
42 {
43 return $this->userId;
44 }
45
46 public function getFirstName()
47 {
48 return $this->getDataFromUser('first_name');
49 }
50
51 public function getLastName()
52 {
53 return $this->getDataFromUser('last_name');
54 }
55
56 public function getDisplayName()
57 {
58 return $this->getDataFromUser('display_name');
59 }
60 public function getEmail()
61 {
62 return $this->getDataFromUser('user_email');
63 }
64
65 public function getUserEmail()
66 {
67 return $this->getDataFromUser('user_email');
68 }
69
70 private function getDataFromUser(string $key)
71 {
72 if (empty($key) || empty($this->user)) {
73 return '';
74 }
75
76 if ($key === 'first_name' || $key === 'last_name') {
77 return get_user_meta($this->userId, $key, true) ?: '';
78 }
79
80 return $this->user->{$key} ?? '';
81 }
82 }
83