PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.5
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.5
1.6.5 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 All 48 releases
← All changes | api/Resource/FrontendResource/CustomerResource.php +11 -5 1.6.2 → 1.6.5 View file →
@@ -98,12 +98,18 @@
98 98 public static function create($data, $params = [])
99 99 {
100 100 $email = Arr::get($data, 'email');
101 101
102 - $customer = static::getQuery()->firstOrCreate(
103 - ['email' => $email],
104 - $data
105 - );
102 + $ownerId = (int) Arr::get($data, 'user_id');
103 + if (!$ownerId || $ownerId !== get_current_user_id()) {
104 + unset($data['user_id']);
105 + $ownerId = 0;
106 + }
107 + $customer = $ownerId ? static::getQuery()->where('user_id', $ownerId)->orderBy('id')->first() : null;
108 + if (!$customer) {
109 + // Matching an existing email never changes its owner or profile.
110 + $customer = static::getQuery()->firstOrCreate(['email' => $email], $data);
111 + }
106 112
107 113 if ($customer) {
108 114 return static::makeSuccessResponse(
109 115 $customer,
@@ -280,5 +286,5 @@
280 286 return static::makeErrorResponse([
281 287 ['code' => 400, 'message' => __('Selected action is invalid', 'fluent-cart')]
282 288 ]);
283 289 }
284 -}
290 +}