Today we will learn about how can a guest user do the checkout process in the Opencart. A guest user can view the Opencart front end and can add products to the cart. Guest users can view the cart and go to the checkout.
On the checkout options page user can register himself or do the checkout process as a guest user.
If the user chooses the guest checkout then he needs to fill some information like delivery and billing address.
If the guest does not select that the billing and delivery address is the same then the guest has to enter the delivery address.
After entering the address the guest has to select the delivery method.
After selecting the delivery method, the guest has to select the available payment method
After clicking on the continue button order details are saved in the database.
Open-cart calls the “save” function of the “checkout/shipping_method” controller to save the shipping details.
Opencart saves all the details of the guest in the session.
Click the “Continue” button of the payment method after selecting a payment option.
When clicked, Opencart calls two Ajax, first is (“checkout/payment_method/save”) to save the payment method on the session and the other is (“checkout/confirm”) to save the whole session details to the “order” table in the database.
If we print the session then we can see the full details of the checkout process.
Opencart checks if the customer is logged in, then gets the details from the database; otherwise, it checks the “guest” index in the session, Since a user doesn’t register as a customer, Opencart sets the customer ID for that user to zero in the database.
<!-- /** * Webkul Software. * * @category Webkul * @author Webkul * @copyright Copyright (c) Webkul Software Private Limited (https://webkul.com) * @license https://store.webkul.com/license.html */ if ($this->customer->isLogged()) { $customer_info = $this->model_account_customer->getCustomer($this->customer->getId()); $order_data['customer_id'] = $this->customer->getId(); $order_data['customer_group_id'] = $customer_info['customer_group_id']; $order_data['firstname'] = $customer_info['firstname']; $order_data['lastname'] = $customer_info['lastname']; $order_data['email'] = $customer_info['email']; $order_data['telephone'] = $customer_info['telephone']; $order_data['custom_field'] = json_decode($customer_info['custom_field'], true); } elseif (isset($this->session->data['guest'])) { $order_data['customer_id'] = 0; $order_data['customer_group_id'] = $this->session->data['guest']['customer_group_id']; $order_data['firstname'] = $this->session->data['guest']['firstname']; $order_data['lastname'] = $this->session->data['guest']['lastname']; $order_data['email'] = $this->session->data['guest']['email']; $order_data['telephone'] = $this->session->data['guest']['telephone']; $order_data['custom_field'] = $this->session->data['guest']['custom_field']; }
after that guests can view the order product list and can confirm the order.
Be the first to comment.