Today we are glad to introduce to our community a new free module: «Belvg_AutoLogin». In future this module will help us demonstrate how our modules work. The idea of this module is that it allows users to test modules, which are installed on our demo-shops, without creating accounts. Using the form, shown below, users can log into the demo-shop under a profile of some other user, who have already been registered in the system.
To make the user appear in the form, he should be recorded in the table belvg_autologin
and should also exist in the standard table ps_customer
. The user can be added to the belvg_autologin
table both manually and automatically. The automatic mode is controlled by the property belvg_autologin::$default_customers:
1 2 3 |
It contains an array of users’ IDs, whose profiles we want to use to allow free logging into the system.
Ecommerce Development
Take your online store to the next level with BelVG ecommerce development
Visit the pageThe authorization is controlled by the controller Belvg_AutoLoginDefaultModuleFrontController and its method prосessLоgin( ):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
protected function processLogin() { $autologin_id = (int)Tools::getValue('autologin_id'); //getting the id of the record in the table belvg_autologin $autologinObj = new Autologin($autologin_id); //creating an object $customer = new Customer($autologinObj->id_customer); if (!$autologinObj->id) { die(Tools::displayError('This cuistomer is not exists')); } //verifying if the user is related to this ID if (!$customer->id) { die(Tools::displayError('Authentication failed.')); } Hook::exec('actionBeforeAuthentication'); //implementing the standard hook to enable the logic of the modules, that are using this hook // setting up data for the session $this->context->cookie->id_compare = isset($this->context->cookie->id_compare) ? $this->context->cookie->id_compare: CompareProduct::getIdCompareByIdCustomer($customer->id); $this->context->cookie->id_customer = (int)($customer->id); $this->context->cookie->customer_lastname = $customer->lastname; $this->context->cookie->customer_firstname = $customer->firstname; $this->context->cookie->logged = 1; $customer->logged = 1; $this->context->cookie->is_guest = $customer->isGuest(); $this->context->cookie->passwd = $customer->passwd; $this->context->cookie->email = $customer->email; // Add customer to the context $this->context->customer = $customer; // Cart if (Configuration::get('PS_CART_FOLLOWING') && (empty($this->context->cookie->id_cart) || Cart::getNbProducts($this->context->cookie->id_cart) == 0) && $id_cart = (int)Cart::lastNoneOrderedCart($this->context->customer->id)) { $this->context->cart = new Cart($id_cart); } else { $id_carrier = (int)$this->context->cart->id_carrier; $this->context->cart->id_carrier = 0; $this->context->cart->setDeliveryOption(null); $this->context->cart->id_address_delivery = (int)Address::getFirstCustomerAddressId((int)($customer->id)); $this->context->cart->id_address_invoice = (int)Address::getFirstCustomerAddressId((int)($customer->id)); } $this->context->cart->id_customer = (int)$customer->id; $this->context->cart->secure_key = $customer->secure_key; if ($this->ajax && isset($id_carrier) && $id_carrier && Configuration::get('PS_ORDER_PROCESS_TYPE')) { $delivery_option = array($this->context->cart->id_address_delivery => $id_carrier.','); $this->context->cart->setDeliveryOption($delivery_option); } $this->context->cart->save(); $this->context->cookie->id_cart = (int)$this->context->cart->id; $this->context->cookie->write(); $this->context->cart->autosetProductAddress(); Hook::exec('actionAuthentication'); //invoke the standard hook again, for the same purpose as the previous one Tools::redirect($this->context->link->getPageLink('order-opc')); //in our case we want to redirect visitors to the checkout page, but you can use any other pages, see examples below //Tools::redirect('index.php?controller=my-account'); //Tools::redirect($_SERVER['HTTP_REFERER']); } |
Looking for a reliable PrestaShop development partner? Turn to BelVG!
Hi, Silvio
Our blog post is about the way to login customer at the frontend, not the Webservice (API)
If you are looking to create a new webservice method for working with customer data, you should provide a way to pass the customer_id or other customer params to determine/create a customer.
please how can i use it?
i,ve code a webservice with all code with cart and everymore… bute i have to make a login before it… how your code can help-me???
Hi, Renato!
Yes, we made this changes especially for demo to make customer’s live easier.
To implement the same feature on your end we should know what exactly product should be added. It takes about 1 hour of support. Please contact us for further details https://belvg.com/contact
Kindly,
Alex
Hello,
I am trying to setup an auto-login in my prestashop.
Your module seems to be very interesting and could feet my needs with minor changes.
But, the module I installed from the ZIP file have a different behavior from the one we can test online.
In the example you provide (http://belvg.info/demo/prestashop16/deliveryandpayments/), as soon as I add a product to the cart, I am logged-in. But with the ZIP file I have to click on the “Log In” at the bottom of the page.
Is there a difference between the example and the zip file or do you believe it is due to a configuration on my side ?
I would help me to search in the right direction.
Thanks,
Renato
Marco, thank you for the feedback. We’re happy to be useful :)
thank you for this great free Modul. It works perfect in 1.6.1.15
I use it for one custumer who will show his wishlist to other without giving to much information.
I unhookt the login from the footer and gave just the link to the login.
With the different options at the end of the php it was easy to redirect the visitor to the wishlist.
Hi Alex.
i fortunatly found your module. It is really great, and nearly exactly what I am looking for. Maybe with some small changes it can fit my needs.
My target is to have a link that directs the customers automaticly logged in, to the product page.
As far as I see, I only need to
1. delete the module from the footer hook
2. change the URL target, which actually always routes to the basket
3. Having the autologin_ID to be something more cryptic
What I would like to use is is to have the customers directed to the products he bought, to leave a comment.
Do you think this could be made with some easy modifications?
thx a lot for your answer
regards