Jump to content

Login As Customer


Recommended Posts

Hi I started to make a module that will login as a customer.

 

I have a button on the adminCustomer page, this url

 

admin7318/index.php?controller=AdminCustomers&id_customer=17800&viewcustomer&token=2dbd917dda79537006dbbc925d5ffc12

 

 

 

When i click the button, it runs the following code:

Context::getContext()->cookie->id_compare = isset(Context::getContext()->cookie->id_compare) ? Context::getContext()->cookie->id_compare: CompareProduct::getIdCompareByIdCustomer($customer->id);
        Context::getContext()->cookie->id_customer = (int)($customer->id);
        Context::getContext()->cookie->customer_lastname = $customer->lastname;
        Context::getContext()->cookie->customer_firstname = $customer->firstname;
        Context::getContext()->cookie->logged = 1;
        Context::getContext()->logged = 1;
        Context::getContext()->cookie->is_guest = $customer->isGuest();
        Context::getContext()->cookie->passwd = $customer->passwd;
        Context::getContext()->cookie->email = $customer->email;

        // Add customer to the context
        Context::getContext()->customer = $customer;

        if (Configuration::get('PS_CART_FOLLOWING') && (empty(Context::getContext()->cookie->id_cart) || Cart::getNbProducts(Context::getContext()->cookie->id_cart) == 0) && $id_cart = (int)Cart::lastNoneOrderedCart(Context::getContext()->customer->id))
            Context::getContext()->cart = new Cart($id_cart);
        else
        {
            Context::getContext()->cart->id_carrier = 0;
            Context::getContext()->cart->setDeliveryOption(null);
            Context::getContext()->cart->id_address_delivery = Address::getFirstCustomerAddressId((int)($customer->id));
            Context::getContext()->cart->id_address_invoice = Address::getFirstCustomerAddressId((int)($customer->id));
        }
        Context::getContext()->cart->id_customer = (int)$customer->id;
        Context::getContext()->cart->secure_key = $customer->secure_key;
        Context::getContext()->cart->save();
        Context::getContext()->cookie->id_cart = (int)Context::getContext()->cart->id;

        //d(Context::getContext()->cookie);
        //Context::getContext()->cookie->__unset('employee');
        //Context::getContext()->cookie->__unset('controller');

        Context::getContext()->cookie->write();
        Context::getContext()->cart->autosetProductAddress();
        header('Location: http://mywebsite.com');

When ever i redirect to my front end i.e. http://mywebsite.com

 

I'm not logged in as the customer but I have been logged out as the employee

 

What am doing wrong?

 

thanks.

Link to comment
Share on other sites

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...