Powerful and easy to use cms to build websites, blogs or ecommerce stores.
HTML backendblogblog-engineblog-platformbloggingcmscontent-managementcontent-management-systemecommerceecommerce-platformno-codepage-builderphpphp-cmsphp7php8self-hostedshopping-cartweb-applicationwebsite-builder
On new order add new address to user account, add phone number if user profile phone number is empty
givanzcdf1e413fc14
diff --git a/app/controller/checkout/checkout.php b/app/controller/checkout/checkout.phpindex 6f3a8d9..5389d51 100755--- a/app/controller/checkout/checkout.php+++ b/app/controller/checkout/checkout.php@@ -215,7 +215,7 @@ class Checkout extends Base {$checkoutInfo += $this->global;//create user account if password is provided- if (isset($checkoutInfo['password'])) {+ if (isset($checkoutInfo['password']) && ! $this->global['user_id']) {$userInfo = [];foreach (['first_name', 'last_name', 'email', 'phone_number', 'password'] as $field) {@@ -233,6 +233,20 @@ class Checkout extends Base {}}+ $user_id = $checkoutInfo['user_id'] ?? $this->global['user_id'];++ //if new address add to user account+ if (empty($this->request->post['billing_address_id']) && $user_id) {+ $addressSql = new User_AddressSQL();+ $address = $addressSql->add(['user_address' => $this->request->post['billing_address'] + ['user_id' => $user_id]]);+ }++ //if account does not have a phone number set add phone number to user profile for next order+ if ($this->global['user_id'] && ! $this->global['user']['phone_number']) {+ User::update(['phone_number' => $checkoutInfo['phone_number']], ['user_id' => $this->global['user_id']]);+ User::session(['phone_number' => $checkoutInfo['phone_number']]);+ }+if (! $checkoutInfo['user_id']) {unset($checkoutInfo['user_id']); //if anonymous then unset user_id}@@ -260,6 +274,7 @@ class Checkout extends Base {if ($checkoutInfo && $checkoutInfo['order_id']) {$order_id = $checkoutInfo['order_id'];+ $customer_order_id = $checkoutInfo['customer_order_id'];$this->request->request['order_id'] = $order_id;$checkoutInfo['order_id'] = $order_id;@@ -273,7 +288,7 @@ class Checkout extends Base {try {$error = __('Error sending order confirmation mail!');- if (! email([$checkoutInfo['email'], $site['admin-email']], sprintf(__('Order confirmation #%s'), $order_id), 'order/new', $checkoutInfo)) {+ if (! email([$checkoutInfo['email'], $site['admin-email']], sprintf(__('Order confirmation #%s'), $customer_order_id), 'order/new', $checkoutInfo)) {$this->session->set('errors', $error);$this->view->errors[] = $error;}diff --git a/app/template/checkout/checkout.tpl b/app/template/checkout/checkout.tplindex 44ee7f3..42c60ca 100755--- a/app/template/checkout/checkout.tpl+++ b/app/template/checkout/checkout.tpl@@ -40,6 +40,20 @@ textarea =else echo $value;?>++input[name="register"]|addNewAttribute = <?php+ if (isset($_POST['register']) && ($_POST['register'] == '@@__value__@@')) echo ' checked';+?>++input[name="terms"]|addNewAttribute = <?php+ if (isset($_POST['terms']) && ($_POST['terms'] == '@@__value__@@')) echo ' checked';+?>++input[name="newsletter"]|addNewAttribute = <?php+ if (isset($_POST['newsletter']) && ($_POST['newsletter'] == '@@__value__@@')) echo ' checked';+?>++input[name="different_shipping_address"]|addNewAttribute =<?php/* if no shipping is unchecked or user didn't submit the form then set no shipping to checked */