2017-01-03 2 views
1

Я пытаюсь обновить клиента в prestashop с помощью webservice. Вебсервис написан на PHP. Теперь проблема заключается в том, что я не могу обновить клиент, используя примеры кода, потому что он продолжает давать мне ту же ошибкуОбновление клиента prestashop не работает

This call to PrestaShop Web Services failed and returned an HTTP status of 404. That means: Not Found. 

Но я могу получить данные с веб-сайта, но когда я хочу, чтобы изменить это дает ошибка.

Странно, что, когда я использую код для локального обновления пользователя, он действительно работает.

код ниже:

define('DEBUG', false); 
define('PS_SHOP_PATH', 'www.Myshop.com'); 
define('PS_WS_AUTH_KEY', 'HERE IS NORMALLY THE CORRECT AUTH_KEY '); 
require_once('PSWebServiceLibrary.php'); 

// Here we use the WebService to get the schema of "customers" resource 

// First : We always get the customer's list or a specific one 
try 
{ 
    $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG); 
    $opt = array('resource' => 'customers'); 
    if (isset($_GET['id'])) 
     $opt['id'] = $_GET['id']; 
    $xml = $webService->get($opt); 
    // Here we get the elements from children of customer markup which is children of prestashop root markup 
    $resources = $xml->children()->children(); 
} 
catch (PrestaShopWebserviceException $e) 
{ 
    // Here we are dealing with errors 
    $trace = $e->getTrace(); 
    if ($trace[0]['args'][0] == 404) echo 'Bad ID'; 
    else if ($trace[0]['args'][0] == 401) echo 'Bad auth key'; 
    else echo 'Other error<br />'.$e->getMessage(); 
} 
// Second : We update the data and send it to the web service 
if (isset($_GET['id']) && isset($_POST['id'])) // Here we check id cause in every resource there's an id 
{ 
    // Here we have XML before update, lets update XML with new values 
    foreach ($resources as $nodeKey => $node) 
    { 

     $resources->$nodeKey = $_POST[$nodeKey]; 


    } 
    // And call the web service 
    try 
    { 
     $opt = array('resource' => 'customers'); 
     $opt['id'] = $_GET[ 'id' ]; 
     $opt['putXml'] = $xml->children()->asXML(); 
     $xml =$webService->edit($opt) ; 

     // if WebService don't throw an exception the action worked well and we don't show the following message 
     echo "Successfully updated."; 
    } 
    catch (PrestaShopWebserviceException $ex) 
    { 
     // Here we are dealing with errors 
     echo "testy"; 
     $trace = $ex->getTrace(); 
     if ($trace[1]['args'][0] == 404) echo 'Bad ID'; 
     else if ($trace[0]['args'][0] == 401) echo 'Bad auth key'; 
     else echo 'Other error<br />'.$ex->getMessage(); 
    } 
} 
// UI 
// We set the Title 
echo '<h1>Customer\'s '; 
if (isset($_GET['id'])) echo 'Update'; 
else echo 'List'; 
echo '</h1>'; 
// We set a link to go back to list if we are in customer's details 
if (isset($_GET['id'])) 
    echo '<a href="?">Return to the list</a>'; 
if (isset($_GET['id'])) 
    echo '<form method="POST" action="?id='.$_GET['id'].'">'; 
echo '<table border="5">'; 
if (isset($resources)) 
{ 
echo '<tr>'; 
if (!isset($_GET['id'])) 
{ 
    //Show list of customers 
    echo '<th>Id</th><th>More</th></tr>'; 
    foreach ($resources as $resource) 
    { 
     echo '<td>'.$resource->attributes().'</td><td>'. 
     '<a href="?id='.$resource->attributes().'">Update</a>&nbsp;'. 
     '</td></tr>'; 
    } 
} 
else 
{ 
    //Show customer form 
    echo '</tr>'; 
    foreach ($resources as $key => $resource) 
    { 
     echo '<tr><th>'.$key.'</th><td>'; 
     echo '<input type="text" name="'.$key.'" value="'.$resource.'"/>'; 
     echo '</td></tr>'; 
    } 
} 
} 
echo '</table><br/>'; 
if (isset($_GET['id'])) 
    echo '<input type="submit" value="Update"></form>'; 
?> 
</body></html> 

Надеется, что кто-то может мне помочь.

+0

Здравствуйте. Попробуйте активировать DEBUG MODE в вашем магазине webservices, чтобы получить больше сведений об ошибке. Проверьте разрешение POST на своем хостинге. Удачи. – PrestaAlba

+0

Прежде всего спасибо за то, что посмотрели мою проблему. Когда я активировал свой режим отладки, я не видел ничего странного, но когда я проверял свои права на хостинг, я мог видеть проблему. Спасибо за поддержку –

ответ

1

Проблема не в моем коде, а в моем файле .htaccess.

когда я добавил этот код ниже у меня не было ошибок и может обновить данные

<Limit GET POST PUT DELETE HEAD OPTIONS> 
    Order allow,deny 
    Allow from all 
</Limit> 
<LimitExcept GET POST PUT DELETE HEAD OPTIONS> 
    Order deny,allow 
    Deny from all 
</LimitExcept> 

Спасибо всем за поддержку

Смежные вопросы