Adelino Vascncelos Posted February 12, 2020 Share Posted February 12, 2020 Boas Não estou a conseguir fazer Force ao ID na criação de Categorias e possivelmente nos Produtos O meu código é o seguinte $xmlResponse1 = $webService->get(['url' => _URL_ . '/api/categories?schema=blank']); $resources1 = $xmlResponse1->category[0]; unset($resources1->id); unset($resources1->position); unset($resources1->date_add); unset($resources1->date_upd); unset($resources1->level_depth); unset($resources1->nb_products_recursive); $f = $force ? 'true' : 'false'; $resources1->id = trim($params['Id Categoria']); $resources1->force_id = $f; $resources1->is_root_category = false; $resources1->active = 1; $resources1->name->language[0] = trim($params['Nombre']); $resources1->name->language[1] = trim($params['Nombre']); $resources1->link_rewrite->language[0] = Tools::link_rewrite(trim($params['Nombre'])); $resources1->link_rewrite->language[1] = Tools::link_rewrite(trim($params['Nombre'])); $resources1->id_parent = trim($params['Id Padre']); try{ $addedResources1 = $webService->add(['resource' => 'categories', 'postXml' => $xmlResponse1->asXML()]); }catch(PrestaShopWebserviceException $e){ $trace = $e->getTrace(); $resources2 = $addedResources1->errors->error; error_log_txt("Code: ".$resources2->code."\nMensagem: ".$resources2->message, 'error'); if ($trace[0]['args'][0] == 404) error_log_txt('Bad ID', 'error'); else if ($trace[0]['args'][0] == 401) error_log_txt('Bad auth key', 'error'); else error_log_txt("Other error\n".$e->getMessage(), 'error'); return false; } O erro que retoma é o seguinte RETURN HTTP BODY <?xml version="1.0" encoding="UTF-8"?> <prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> <errors> <error> <code><![CDATA[91]]></code> <message><![CDATA[id is forbidden when adding a new resource]]></message> </error> </errors> </prestashop> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now