Jump to content

is it possible, no any guest and visitor but only Logged in User can able to add product in cart .


deepankar

Recommended Posts

Hello there,

I want to change some functionality of cart as following:

 

(1) user need to be logged in for adding product in cart .

 

(2)If user who is not logged in whether they are guest or visitor , if they click add to cart button they will first have to login/register themselves then product will be added in their cart .

 

I need help in this topic. How can I do this ?? :( :(

 

though I am also aware of this topic:

 

[ https://www.prestashop.com/forums/topic/81810-disable-add-to-cart-button-for-unregistered-visitors/ ]

 

but I don't want to achieve this thing . I want to make condition here so that if guest or visitor click add to cart button firstly they will redirect to login page and then they will be able to add product in cart .

 

Link to comment
Share on other sites

thanks for your reply...yeah exactly I want to do same thing.

 

I found the solution for it . Just use following code in override/controllers/front directory in your prestashop dir.

<?php

/*
  Copyright (C) 2015 by Iriemo

  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  THE SOFTWARE.
 */

class CartController extends CartControllerCore
{

    public function init()
    {
        parent::init();
        if (!self::$cookie->isLogged(false))
        {
        // not logged in
            if (Tools::getValue('ajax') === 'true' && Tools::getValue('add') === '1')
                // ajax cart
                die('{"hasError" : true, "errors" : ["' . Tools::displayError('Please login first.', false) . '"]}');
            else
                $this->errors[] = Tools::displayError('Please login first.');
        }
    }

}

?>

But I want More functionality like if user is not logged in and he/she is clicking ADD TO CART button, they need to be redirected in login page like following snapshot :

For New Account :

 

sPnEugw.png?1

 

For Login :

 

fSX3cdT.png?1

 

 

it should be directly prompted login or sign up (toggle tab) hover page .

 

How can I create a module for this kind of functionality?

Link to comment
Share on other sites

  • 1 month later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...