问题
In OpenCart v. 2.0.0 in /admin when I receive an order I should be able to change status of the order to let the customer know what is going on with her purchase. This functionality is in 'History' tab. Unfortunately I can't change or modify any orders. When I change the status and try to save it Openart gives me an error:
SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data OK
It happens even on clean install. Everything is set up correctly - the domain name is OK, the shop is not in maintenance mode, there is no password in .htaccess file (BTW even removing it doesn't help).
It looks like in the screenshot attached.
The one solution is to install the newest version of OpenCart which is in the moment I'm writing this post 2.0.1.1. It's probably the best idea.
My problem is that I have made quite a lot of modifications and that would be very difficult for me. Making my changes I didn't use vqmod which probably I should use (but nobody is perfect - isn't she?). Or maybe you don't want to go into upgrade for a different reason?
Now, how to resolve this problem without actually changing the software itself?
回答1:
I got the same error and I fixed it:
- Go to Admin -> System -> Users -> API
- Add a new API generate password, and enable it
- Then go to Admin -> System -> Settings -> Edit -> Option(tab)
- Select API user under Checkout section as your API user
- Then save the changes
- Then go to Sales -> Orders -> Edit
回答2:
I guess that the error comes when a cURL method in your OC tries to get data from the OC API and gets blocked.
-- Quick Testing
Goto function info() in /admin/controller/sale/order.php
find the curl initialization inside info() and aim on $json = curl_exec($curl);
add after that:
if($json === false){
var_dump(curl_error($curl));
exit;
}
if there is an error, you should see it when you go to an order info from your admin panel. You may have a refused connection msg on 80 or 443 port.
If yes, possible errors and solutions may be:
You are working in a protected directory. This is a website message (like js alert with fields) that asks for user/pass. You may turn it off and try again to add a history record. In Plesk you can find it as "Password Protected Directory" in domain options.
If you recently modify your .htaccess, you should check it for auth statements causing the above symptoms.
PHP; Check if you have added any $_SERVER['REMOTE_ADDR'] into an if block to reject ips on purpose.
When using Plesk, have root access (ssh), and you have the same website domain as the Plesk admin panel hostname, (assume that your domain is www.yourdomain.com) you can check from your ssh, executing
curl -vv "http://www.yourdomain.com"
(or https) inside of your own server (localhost) which your domain is hosted. If you get a refused connection on port 80, or 443 for https and have a success return msg oncurl -vv "http://www.yourdomain.com:7080"
ORcurl -vv "http://www.yourdomain.com:7081"
(virtualhost ports) then you can fix it as below. It is also strange to get a successfull connection msg on 80 & 443 when try it from other server! So, you have to modify your server hosts (/etc/hosts) and add right to your public ip your full website domain (last line usually). So, add to the public-ip linexxx.xxx.xxx.xxx www.yourdomain.com
. You may have other hosts defined right on your public ip. Please, do not remove any. Add www.yourdomain.com in the last of the piblic-ip line. You can check again with curl, or adding an order history.
I may help,
giannisepp
回答3:
After some hard time I managed to solve this problem and I want to share this solution with you:
In the admin panel of your shop go to:
Admin > Settings > Users > API
There should be one user with name like
XrpeYEWrFHOcqB1phjBXdUCRO1A3sCvDpgmTGBcJ7G6WuYIMKXCrIJUpzvFPfimWT6LHQLisTYz0nuOy7ZK
if there is not create one and give her reasonably complicated name like in the example.
Then you have to check out your database (using phpMyAdmin helps a lot) where keeps your store data.
- find the api table which contains the API user and check the api_id of this user.
- find table setting (by default OpenCart instalation it's named oc_setting) and find key config_api_id.
- Set the value field to the same number as the api_id you had found in the api table.
- Problem should be solved.
In my OpenCart 2.0.0 installation the value was set to 0 while the api_id was 2.
回答4:
I had the same issue and tried all workarounds possible and imaginable.
In the end gave up and called my hosting provider. They found that OpenCart wont run properly on any php version above 5.4.33. Ergo: use php 5.4.33
This might not solve all issues, or might work only in conjunction with other fixes bove, but itÄs worth a try to check which php version your hosting is running by default.
回答5:
If your server does not support HTTPS
, please modify the https to http.
Open the admin/config.php
file, modify the https to http.
define('HTTPS_SERVER', 'http://'.$_SERVER['HTTP_HOST'].'/admin/');
define('HTTPS_CATALOG', 'http://'.$_SERVER['HTTP_HOST'].'/');
回答6:
Disabling maintenance mode did it for me.
回答7:
In admin/controller/sale/order.php file line below 2438 you should see like this:
if ($store_info) {
$url = $store_info['ssl'];
} else {
$url = HTTPS_CATALOG;
}
As you can see CURL is allways use HTTPS_CATALOG defined constant which contain your shop SSL URL. Why? I don't now. The solution: edit your config.php on shop root folder and change HTTPS_CATALOG defined constant value to non-ssl URL, simply delete "s" after end of https.
来源:https://stackoverflow.com/questions/27732677/opencart-2-0-0-syntaxerror-json-parse-unexpected-end-of-data-at-line-1-colu