Skip to content

Commit f48b8ad

Browse files
committed
Check if email already in use on guest checkout page
1 parent 0b7fbe0 commit f48b8ad

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

app/controller/checkout/checkout.php

+23-15
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,15 @@ private function data(&$checkoutInfo) {
103103
function index() {
104104
$options = array_intersect_key($this->global['site'],
105105
array_flip(['weight_type_id', 'length_type_id', 'currency_id', 'country_id']));
106-
$cart = Cart :: getInstance($options);
106+
$cart = Cart :: getInstance($this->global + $options);
107107

108108
//buy now product
109-
if (isset($this->request->request['product_id'])) {
110-
$productId = $this->request->request['product_id'];
111-
$quantity = $this->request->post['quantity'] ?? 1;
112-
$cart->add($productId, $quantity);
109+
if (isset($this->request->get['product_id'])) {
110+
$productId = $this->request->get['product_id'];
111+
$quantity = $this->request->post['quantity'] ?? 1;
112+
$option = $this->request->post['option'] ?? [];
113+
$subscriptionPlanId = $this->request->post['subscription_plan_id'] ?? false;
114+
$cart->add($productId, $quantity, $option, $subscriptionPlanId);
113115
}
114116

115117
if (! $cart->hasProducts()) {
@@ -265,18 +267,24 @@ function index() {
265267
$userInfo['display_name'] = $userInfo['first_name'] . ' ' . $userInfo['last_name'];
266268
$userInfo['username'] = str_replace(' ', '', $userInfo['first_name'] . $userInfo['last_name']);
267269

268-
$error = __('Error creating account!');
269-
270-
if ($result = User::add($userInfo)) {
271-
$checkoutInfo['user_id'] = $result['user'] ?? NULL;
272-
$userInfo = User::get(['user_id' => $user_id]);
273-
//check if user was added before automatic login
274-
if ($userInfo) {
275-
\Vvveb\session(['user' => $userInfo]);
276-
$this->view->global['user_id'] = $userInfo['user_id'];
270+
$result = User::add($userInfo);
271+
272+
if ($result) {
273+
if (isset($result['user'])) {
274+
$checkoutInfo['user_id'] = $result['user'] ?? NULL;
275+
$userInfo = User::get(['user_id' => $checkoutInfo['user_id']]);
276+
//check if user was added before automatic login
277+
if ($userInfo) {
278+
\Vvveb\session(['user' => $userInfo]);
279+
$this->view->global['user_id'] = $userInfo['user_id'];
280+
}
281+
} else {
282+
$this->view->errors[] = __('This email is already in use. Please use another one or login.');
283+
284+
return;
277285
}
278286
} else {
279-
$this->view->errors[] = $error;
287+
$this->view->errors[] = __('Error creating account!');
280288

281289
return;
282290
}

0 commit comments

Comments
 (0)