Jump to content

Recommended Posts

Hi,

 

I'm trying to get an specific product via web service with php and the library from prestashop PSWebServiceLibrary.php.

I already try the examples provided from prestashop to get data via web service and work fine getting an product by id but i want to get the product by reference so i can update the data of some products from an external program.

 

I think its something like this in first place but this doesn't work:

for ($i = 1; $i <= $total_products; $i++) {
try
{
$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
$opt = array('resource' => 'products');
if (isset($_GET['reference']))
$opt['reference'] = $_GET['reference'];
$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';
}
}

My final program will interacte an existing database from an external program with the daily stocks of products via web service into the web site build with prestashop. So i need to run a loop with all my products in an existing external program and from each product check if exists in the site prestashop by reference and then update the stock of then product and so on..

 

Can anyone help me?

 

Tanks in advance,

Rúben Martins

Link to comment
Share on other sites

  • 1 month later...
function getProductByReference($ref){

    global $webService;

    $opt['resource'] = 'products';

    $opt['filter']['reference'] = $ref;

    $xml = $webService->get($opt);

    $x = ($xml->products[0]->product->attributes());

    $ProductId = $x['id'];

    return $ProductId;

}

  • Like 2
Link to comment
Share on other sites

  • 11 months later...

 

function getProductByReference($ref){
    global $webService;
    $opt['resource'] = 'products';
    $opt['filter']['reference'] = $ref;
    $xml = $webService->get($opt);
    $x = ($xml->products[0]->product->attributes());
    $ProductId = $x['id'];
    return $ProductId;
}

 

with a similar code gives me the following error:
Node no longer exists
 
How can i fix it?
 
 
the code:
function getCombinationByEan($ean,$id_product){
global $webService;
$opt['resource'] = 'combinations';
$opt['filter']['ean13'] = $ean;
// $opt['filter']['id_product'] = $id_product;
$xml = $webService->get($opt);
//var_dump($xml); 
if($xml){
$x = ($xml->combinations[0]->combination->attributes());
$ProductId = $x['id'];
//var_dump($ProductId,$ean);exit;
return $ProductId;
}
else
return null;
}
  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...