getByEmail($email); $header_account = new HeaderAccount(); $vk_id = $header_account->getSocialId('vk', $customer->id); if ($vk_id) { if ($vk_id == $user_id) { Tools::redirect($this->context->link->getModuleLink('jxheaderaccount', 'vklogin', array(), false, $this->context->language->id)); } else { $this->errors[] = Tools::displayError('An error occurred while linking your VK account.'); } } else { $new_customer = new HeaderAccount(); $new_customer->id_customer = (int)$customer->id; $new_customer->social_id = $user_id; $new_customer->avatar_url = $profile_image_url; $new_customer->social_type = 'vk'; $new_customer->id_shop = (int)$this->context->getContext()->shop->id; if ($new_customer->add()) { // $this->errors[] = Tools::displayError('an error occurred while linking your VK account.'); } else { $customer->active = 1; $customer->deleted = 0; $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; $this->context->cookie->passwd = $customer->passwd; $this->context->cookie->email = $customer->email; if (Configuration::get('PS_CART_FOLLOWING') && (empty($this->context->cookie->id_cart) || Cart::getNbProducts($this->context->cookie->id_cart) == 0)) { $this->context->cookie->id_cart = (int)Cart::lastNoneOrderedCart((int)$customer->id); } Hook::exec('actionAuthentication'); if (($back = Tools::getValue('back')) && $back == Tools::secureReferrer($back)) { Tools::redirect(html_entity_decode($back)); } // redirection: if cart is not empty : redirection to the cart if (count($this->context->cart->getProducts(true)) > 0) { Tools::redirect('index.php?controller=order&multi-shipping='.(int)Tools::getValue('multi-shipping')); // else : redirection to the account } else { Tools::redirect('index.php?controller='.(($this->authRedirection !== false) ? urlencode($this->authRedirection) : 'my-account')); } } } } if (Tools::getValue('done')) { $customer = new Customer(); if (Tools::getValue('gender') == 1) { $post['id_gender'] = 2; } elseif (Tools::getValue('gender') == 2) { $post['id_gender'] = 1; } else { $post['id_gender'] = 0; } $customer->lastname = $post['lastname'] = Tools::getValue('family_name'); $customer->firstname = $post['firstname'] = Tools::getValue('given_name'); $customer->passwd = $post['passwd'] = Tools::passwdGen(); $customer->email = $post['email'] = Tools::getValue('email'); $this->errors = $customer->validateController(); if (!sizeof($this->errors)) { $customer->active = 1; if (!$customer->add()) { $this->errors[] = Tools::displayError('an error occurred while creating your account'); } else { $new_customer = new HeaderAccount(); $new_customer->id_customer = (int)$customer->id; $new_customer->social_id = $user_id; $new_customer->avatar_url = $profile_image_url; $new_customer->social_type = 'vk'; $new_customer->id_shop = (int)$this->context->getContext()->shop->id; if ($new_customer->add()) { $this->errors[] = Tools::displayError('an error occurred while linking your VK account.'); } $this->context->smarty->assign('confirmation', 1); $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->passwd = $customer->passwd; $this->context->cookie->logged = 1; $this->context->cookie->email = $customer->email; Hook::exec('actionCustomerAccountAdd', array( '_POST' => $post, 'newCustomer' => $customer )); if (($back = Tools::getValue('back')) && $back == Tools::secureReferrer($back)) { Tools::redirect(html_entity_decode($back)); } // redirection: if cart is not empty : redirection to the cart if (count($this->context->cart->getProducts(true)) > 0) { Tools::redirect('index.php?controller=order&multi-shipping='.(int)Tools::getValue('multi-shipping')); // else : redirection to the account } else { Tools::redirect('index.php?controller='.(($this->authRedirection !== false) ? urlencode($this->authRedirection) : 'my-account')); } } } } $this->context->smarty->assign(array( 'user_id' => $user_id, 'user_name' => $user_name, 'email' => $email, 'given_name' => $given_name, 'back' => Tools::getValue('back'), 'family_name' => $family_name, 'gender' => $gender, 'profile_url' => $profile_url, 'profile_image_url' => $profile_image_url, 'error' => $this->errors, 'id_module' => $this->module->id )); $this->setTemplate('module:jxheaderaccount/views/templates/front/vkregistration.tpl'); } }