Ошибка Unexpected token < in JSON at position 0. Как решить?

149
21 декабря 2019, 22:20

Выдает ошибку при оформлении заказа без регистрации.

Notice: Undefined index: firstname in /home/buffalob/public_html/system/storage/modification/catalog/controller/checkout/guest.php on line 244Notice: Undefined index: lastname in /home/buffalob/public_html/system/storage/modification/catalog/controller/checkout/guest.php on line 248Notice: Undefined index: email in /home/buffalob/public_html/system/storage/modification/catalog/controller/checkout/guest.php on line 252Notice: Undefined index: email in /home/buffalob/public_html/system/storage/modification/catalog/controller/checkout/guest.php on line 252Notice: Undefined index: telephone in /home/buffalob/public_html/system/storage/modification/catalog/controller/checkout/guest.php on line 256Notice: Undefined index: address_1 in /home/buffalob/public_html/system/storage/modification/catalog/controller/checkout/guest.php on line 260Notice: Undefined index: city in /home/buffalob/public_html/system/storage/modification/catalog/controller/checkout/guest.php on line 264Notice: Undefined index: country_id in /home/buffalob/public_html/system/storage/modification/catalog/controller/checkout/guest.php on line 270Notice: Undefined index: country_id in /home/buffalob/public_html/system/storage/modification/catalog/controller/checkout/guest.php on line 276{"error":{"firstname":"\u0418\u043c\u044f \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043e\u0442 1 \u0434\u043e 32 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432!","lastname":"\u0424\u0430\u043c\u0438\u043b\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043e\u0442 1 \u0434\u043e 32 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432!"}}

<?php 
class ControllerCheckoutGuest extends Controller { 
	public function index() { 
		$this->load->language('checkout/checkout'); 
 
		$data['text_select'] = $this->language->get('text_select'); 
		$data['text_none'] = $this->language->get('text_none'); 
		$data['text_your_details'] = $this->language->get('text_your_details'); 
		$data['text_your_account'] = $this->language->get('text_your_account'); 
		$data['text_your_address'] = $this->language->get('text_your_address'); 
		$data['text_loading'] = $this->language->get('text_loading'); 
 
		$data['entry_firstname'] = $this->language->get('entry_firstname'); 
		$data['entry_lastname'] = $this->language->get('entry_lastname'); 
		$data['entry_email'] = $this->language->get('entry_email'); 
		$data['entry_telephone'] = $this->language->get('entry_telephone'); 
		$data['entry_fax'] = $this->language->get('entry_fax'); 
		$data['entry_company'] = $this->language->get('entry_company'); 
		$data['entry_customer_group'] = $this->language->get('entry_customer_group'); 
		$data['entry_address_1'] = $this->language->get('entry_address_1'); 
		$data['entry_address_2'] = $this->language->get('entry_address_2'); 
		$data['entry_postcode'] = $this->language->get('entry_postcode'); 
		$data['entry_city'] = $this->language->get('entry_city'); 
		$data['entry_country'] = $this->language->get('entry_country'); 
		$data['entry_zone'] = $this->language->get('entry_zone'); 
		$data['entry_shipping'] = $this->language->get('entry_shipping'); 
 
		$data['button_continue'] = $this->language->get('button_continue'); 
		$data['button_upload'] = $this->language->get('button_upload'); 
 
		$data['customer_groups'] = array(); 
 
		if (is_array($this->config->get('config_customer_group_display'))) { 
			$this->load->model('account/customer_group'); 
 
			$customer_groups = $this->model_account_customer_group->getCustomerGroups(); 
 
			foreach ($customer_groups as $customer_group) { 
				if (in_array($customer_group['customer_group_id'], $this->config->get('config_customer_group_display'))) { 
					$data['customer_groups'][] = $customer_group; 
				} 
			} 
		} 
 
		 
		if (isset($this->request->post['customer_group_id'])) { 
			$data['customer_group_id'] = $this->request->post['customer_group_id']; 
		} elseif(isset($this->session->data['guest']['customer_group_id'])) { 
 
             
			$data['customer_group_id'] = $this->session->data['guest']['customer_group_id']; 
		} else { 
			$data['customer_group_id'] = $this->config->get('config_customer_group_id'); 
		} 
 
 
//lightshop start 
		$data['button_back'] = $this->language->get('button_back'); 
		$data['entry_telephone'] = $this->language->get('entry_telephone'); 
		$data['entry_email'] = $this->language->get('entry_email'); 
		$data['checkout_st3_sa'] = $this->config->get('theme_lightshop_checkout_st3_sa'); 
		 
		$this->load->model('catalog/lightshop'); 
		$activeFields = $this->model_catalog_lightshop->getFields($data['customer_group_id']); 
		$allFields = $this->model_catalog_lightshop->getAllFields(); 
 
		$data['allCustomFields'] = $allFields; 
		foreach($allFields as $field){ 
			$data['entry_'.$field.'_required'] = 0; 
			$data['entry_'.$field.'_show'] = 0; 
		 
			if (isset($this->request->post[$field])) { 
				$data[$field] = $this->request->post[$field]; 
			} elseif (!empty($customer_info)) { 
				$data[$field] = $customer_info[$field]; 
			} else { 
				$data[$field] = ''; 
			} 
 
			if (isset($this->error[$field])) { 
				$data['error_'.$field] = $this->error[$field]; 
			} else { 
				$data['error_'.$field] = ''; 
			} 
 
		} 
 
		foreach($activeFields as $field){ 
			if($field['description']){ 
				$data['entry_'.$field['name']] = $field['description']; 
			} 
			$data['entry_'.$field['name'].'_required'] = $field['required']; 
			$data['entry_'.$field['name'].'_show'] = $field['is_show']; 
		} 
 
 
//lightshop end		 
 
             
		if (isset($this->session->data['guest']['firstname'])) { 
			$data['firstname'] = $this->session->data['guest']['firstname']; 
		} else { 
			$data['firstname'] = ''; 
		} 
 
		if (isset($this->session->data['guest']['lastname'])) { 
			$data['lastname'] = $this->session->data['guest']['lastname']; 
		} else { 
			$data['lastname'] = ''; 
		} 
 
		if (isset($this->session->data['guest']['email'])) { 
			$data['email'] = $this->session->data['guest']['email']; 
		} else { 
			$data['email'] = ''; 
		} 
 
		if (isset($this->session->data['guest']['telephone'])) { 
			$data['telephone'] = $this->session->data['guest']['telephone']; 
		} else { 
			$data['telephone'] = ''; 
		} 
 
		if (isset($this->session->data['guest']['fax'])) { 
			$data['fax'] = $this->session->data['guest']['fax']; 
		} else { 
			$data['fax'] = ''; 
		} 
 
		if (isset($this->session->data['payment_address']['company'])) { 
			$data['company'] = $this->session->data['payment_address']['company']; 
		} else { 
			$data['company'] = ''; 
		} 
 
		if (isset($this->session->data['payment_address']['address_1'])) { 
			$data['address_1'] = $this->session->data['payment_address']['address_1']; 
		} else { 
			$data['address_1'] = ''; 
		} 
 
		if (isset($this->session->data['payment_address']['address_2'])) { 
			$data['address_2'] = $this->session->data['payment_address']['address_2']; 
		} else { 
			$data['address_2'] = ''; 
		} 
 
		if (isset($this->session->data['payment_address']['postcode'])) { 
			$data['postcode'] = $this->session->data['payment_address']['postcode']; 
		} elseif (isset($this->session->data['shipping_address']['postcode'])) { 
			$data['postcode'] = $this->session->data['shipping_address']['postcode']; 
		} else { 
			$data['postcode'] = ''; 
		} 
 
		if (isset($this->session->data['payment_address']['city'])) { 
			$data['city'] = $this->session->data['payment_address']['city']; 
		} else { 
			$data['city'] = ''; 
		} 
 
		if (isset($this->session->data['payment_address']['country_id'])) { 
			$data['country_id'] = $this->session->data['payment_address']['country_id']; 
		} elseif (isset($this->session->data['shipping_address']['country_id'])) { 
			$data['country_id'] = $this->session->data['shipping_address']['country_id']; 
		} else { 
			$data['country_id'] = $this->config->get('config_country_id'); 
		} 
 
		if (isset($this->session->data['payment_address']['zone_id'])) { 
			$data['zone_id'] = $this->session->data['payment_address']['zone_id']; 
		} elseif (isset($this->session->data['shipping_address']['zone_id'])) { 
			$data['zone_id'] = $this->session->data['shipping_address']['zone_id']; 
		} else { 
			$data['zone_id'] = ''; 
		} 
 
		$this->load->model('localisation/country'); 
 
		$data['countries'] = $this->model_localisation_country->getCountries(); 
 
		// Custom Fields 
		$this->load->model('account/custom_field'); 
 
		$data['custom_fields'] = $this->model_account_custom_field->getCustomFields(); 
 
		if (isset($this->session->data['guest']['custom_field'])) { 
			if (isset($this->session->data['guest']['custom_field'])) { 
				$guest_custom_field = $this->session->data['guest']['custom_field']; 
			} else { 
				$guest_custom_field = array(); 
			} 
 
			if (isset($this->session->data['payment_address']['custom_field'])) { 
				$address_custom_field = $this->session->data['payment_address']['custom_field']; 
			} else { 
				$address_custom_field = array(); 
			} 
 
			$data['guest_custom_field'] = $guest_custom_field + $address_custom_field; 
		} else { 
			$data['guest_custom_field'] = array(); 
		} 
 
		$data['shipping_required'] = $this->cart->hasShipping(); 
 
		if (isset($this->session->data['guest']['shipping_address'])) { 
			$data['shipping_address'] = $this->session->data['guest']['shipping_address']; 
		} else { 
			$data['shipping_address'] = true; 
		} 
 
		// Captcha 
		if ($this->config->get($this->config->get('config_captcha') . '_status') && in_array('guest', (array)$this->config->get('config_captcha_page'))) { 
			$data['captcha'] = $this->load->controller('extension/captcha/' . $this->config->get('config_captcha')); 
		} else { 
			$data['captcha'] = ''; 
		} 
 
		$this->response->setOutput($this->load->view('checkout/guest', $data)); 
	} 
 
	public function save() { 
		$this->load->language('checkout/checkout'); 
 
		$json = array(); 
 
		// Validate if customer is logged in. 
		if ($this->customer->isLogged()) { 
			$json['redirect'] = $this->url->link('checkout/checkout', '', true); 
		} 
 
		// Validate cart has products and has stock. 
		if ((!$this->cart->hasProducts() && empty($this->session->data['vouchers'])) || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) { 
			$json['redirect'] = $this->url->link('checkout/cart'); 
		} 
 
		// Check if guest checkout is available. 
		if (!$this->config->get('config_checkout_guest') || $this->config->get('config_customer_price') || $this->cart->hasDownload()) { 
			$json['redirect'] = $this->url->link('checkout/checkout', '', true); 
		} 
 
		if (!$json) { 
	244 строка----------------		if ((utf8_strlen(trim($this->request->post['firstname'])) < 1) || (utf8_strlen(trim($this->request->post['firstname'])) > 32)) { 
				$json['error']['firstname'] = $this->language->get('error_firstname'); 
			}

Answer 1

Ошибка Undefined index: .... in ... в opencart говорит о том, что во время сабмита данных значения этих полей (firstname etc) не передались в контроллер. Либо передались не так, как он их ожидает.

Почему - тайна, покрытая полумраком. Обычно появляется после вмешательства в контроллер/шаблон. Сказать конкретнее не возможно, мало вводных.

Дебажте/приньте/эхайте/вардампье/дайте, и будет вах счастье.

READ ALSO
Регулярное выражение с заменой

Регулярное выражение с заменой

Нужно заменить все встречающиеся точки кроме таких случаев:

145
Доставка php-кода на бэкэнды

Доставка php-кода на бэкэнды

Категорически приветствую! Допустим, у меня есть локальный gitlab и веб схема, где в роли фронта nginx который просто проксирует все запросы на apache...

158