Page 1 of 1

Checkout Login SyntaxError: Unexpected token < in JSON at position 0 OK <b>Notice</b>:

Posted: Wed Jul 08, 2020 5:45 pm
by Alaque123
SyntaxError: Unexpected token < in JSON at position 0 OK <b>Notice</b>: Undefined index: approved in <b>C: \wampp\htdocs\default2\catalog\controller\extension\quickcheckout\login.php</b> on line <b>35</b>{"error":("warning:"error_approved"}}



I get the following error when logging in during payment. I can't publish my site because of this error






this is my login controller file

Code: Select all


<?php  
class ControllerExtensionQuickCheckoutLogin extends Controller { 
	public function index() {
		$data = $this->load->language('checkout/checkout');
		$data = array_merge($data, $this->load->language('extension/quickcheckout/checkout'));
		
		$data['forgotten'] = $this->url->link('account/forgotten', '', true);
		
		return $this->load->view('extension/quickcheckout/login', $data);
	}
	
	public function validate() {
		$this->load->language('checkout/checkout');
		$this->load->language('extension/quickcheckout/checkout');
		
		$json = array();
		
		if ($this->customer->isLogged()) {
			$json['redirect'] = $this->url->link('extension/quickcheckout/checkout', '', true);			
		}
		
		if (!$json) {
			$this->load->model('account/customer');
			
			// Check how many login attempts have been made.
			$login_info = $this->model_account_customer->getLoginAttempts($this->request->post['email']);
					
			if ($login_info && ($login_info['total'] > $this->config->get('config_login_attempts')) && strtotime('-1 hour') < strtotime($login_info['date_modified'])) {
				$json['error']['warning'] = $this->language->get('error_attempts');
			}
			
			// Check if customer has been approved.
			$customer_info = $this->model_account_customer->getCustomerByEmail($this->request->post['email']);

			if ($customer_info && !$customer_info['approved']) {
				$json['error']['warning'] = $this->language->get('error_approved');
			}
			
			if (!$json) {
				if (!$this->customer->login($this->request->post['email'], $this->request->post['password'])) {
					$json['error']['warning'] = $this->language->get('error_login');
					
					$this->model_account_customer->addLoginAttempt($this->request->post['email']);
				} else {
					$this->model_account_customer->deleteLoginAttempts($this->request->post['email']);
					
					// Add to activity log
					if ($this->config->get('config_customer_activity')) {
						$this->load->model('account/activity');

						$activity_data = array(
							'customer_id' => $this->customer->getId(),
							'name'        => $this->customer->getFirstName() . ' ' . $this->customer->getLastName()
						);

						$this->model_account_activity->addActivity('login', $activity_data);
					}
				}
			}
		}
		
		if (!$json) {
			$json['redirect'] = $this->url->link('extension/quickcheckout/checkout', '', true);
		}
		
		$this->response->addHeader('Content-Type: application/json');
		$this->response->setOutput(json_encode($json));		
	}
}

Re: Checkout Login SyntaxError: Unexpected token < in JSON at position 0 OK <b>Notice</b>:

Posted: Wed Jul 08, 2020 6:08 pm
by letxobnav
start by stop displaying notices and rely on your error logs for that.
That is an error message complaining about the format (not json) of a php notice which states that the field $customer_info['approved'] is not defined.

Because you display notices, php will produce those and since those are not json encoded, the javascript will produce an alert stating that fact.

Re: Checkout Login SyntaxError: Unexpected token < in JSON at position 0 OK <b>Notice</b>:

Posted: Thu Jul 09, 2020 5:45 pm
by paulfeakins
letxobnav wrote:
Wed Jul 08, 2020 6:08 pm
start by stop
Indeed.

But as letxobnav says, turn off Notices and Warnings in PHP. There's plenty on Google about how to do that.