public function saveProdutoFornecedores($arr, $id_item_referencia) { $r = httpRequest::get(array('url' => $this->ps_shop_path . 'api/produto_fornecedores/' . $id_item_referencia, 'CURLOPT_USERPWD' => $this->ps_shop_path)); if ($r->info['http_code'] != 200) { return false; } $suppliers = $r->response; foreach ($arr as $value) { $find = findINObj('id_supplier', $value, $suppliers); if ($find == false) { $xml = $this->webService->get(array('url' => $this->ps_shop_path . '/api/product_suppliers?schema=blank')); $resources = $xml->children()->children(); $resources->id_product = $id_item_referencia; $resources->id_supplier = $value; $resources->id_product_attribute = 0; try { $opt = array('resource' => 'product_suppliers'); $opt['postXml'] = $xml->asXML(); $xml = $this->webService->add($opt); } catch (PrestaShopWebserviceException $e) { return json_encode(array('status' => false, 'id_fornecedor' => $value, 'errors' => $this->webService->response->errors)); } } } foreach ($suppliers as $value) { if (!in_array($value->id_supplier, $arr)) { try { $opt = array('resource' => 'product_suppliers'); $opt['id'] = $value->id_product_supplier; $xml = $this->webService->delete($opt); } catch (PrestaShopWebserviceException $e) { return json_encode(array('status' => false, 'id_fornecedor' => $value, 'errors' => $this->webService->response->errors)); } } } }