context->customer->isLogged()) { $back = $this->context->link->getModuleLink('jxheaderaccount', 'vklink', array(), true, $this->context->language->id); Tools::redirect('index.php?controller=authentication&back='.urlencode($back)); } $user_id = Tools::getValue('user_id'); $user_name = Tools::getValue('user_name'); $profile_image_url = Tools::getValue('profile_image_url'); $headeraccount = new HeaderAccount(); $customer_id = $headeraccount->getCustomerId($user_id, 'vk', $this->context->getContext()->shop->id); if ($customer_id > 0 && $customer_id != $this->context->customer->id) { $this->context->smarty->assign(array( 'vk_status' => 'error', 'vk_massage' => 'The VK account is already linked to another account.', 'vk_picture' => $profile_image_url, 'vk_name' => $user_name )); } elseif ($customer_id == $this->context->customer->id) { $headeraccount = new HeaderAccount(); $avatar = $headeraccount->getImageUrl('vk', $this->context->customer->id); if ($avatar != $profile_image_url) { $headeraccount = new HeaderAccount(); $headeraccount->updateAvatar($profile_image_url, $this->context->customer->id); } $this->context->smarty->assign(array( 'vk_status' => 'linked', 'vk_massage' => 'The VK account is already linked to your account.', 'vk_picture' => $profile_image_url, 'vk_name' => $user_name )); } else { $headeraccount = new HeaderAccount(); $vk_id = $headeraccount->getSocialIdByRest('vk', $this->context->customer->id); if (!$vk_id) { $new_customer = new HeaderAccount(); $new_customer->id_customer = (int)$this->context->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; $new_customer->add(); $this->context->smarty->assign(array( 'vk_status' => 'confirm', 'vk_massage' => 'Your VK account has been linked to account.', 'vk_picture' => $profile_image_url, 'vk_name' => $user_name )); } else { $this->context->smarty->assign(array( 'vk_status' => 'error', 'vk_massage' => 'Sorry, unknown error.', )); } } $this->setTemplate('vklink.tpl'); } }