Skip to content

Instantly share code, notes, and snippets.

@willboudle
Last active February 3, 2017 22:29
Show Gist options
  • Select an option

  • Save willboudle/842ec3667b2157ff1292 to your computer and use it in GitHub Desktop.

Select an option

Save willboudle/842ec3667b2157ff1292 to your computer and use it in GitHub Desktop.
Retrieve Product's info using API:
<?php
// Check product's status.
function getProductInfo($product_id){
$this->APIUrl= "http://yourdomain.com/index.php/api/soap/?wsdl";
$this->APIUser="APIUser";
$this->APIKey= "APIKey";
$proxy = new SoapClient($this->APIUrl);
$sessionId = $proxy->login($this->APIUser, $this->APIKey);
$exists = true;
try {
$info = $proxy->call($sessionId, 'product.info', $product_id);
} catch (SoapFault $e){
$exists= false;
}
return $exists;
}
?>
<?php
// Update Product's Info
function updateProductInfo(){
$this->APIUrl= "http://yourdomain.com/index.php/api/soap/?wsdl";
$this->APIUser="APIUser";
$this->APIKey= "APIKey";
$proxy = new SoapClient($this->APIUrl);
$sessionId = $proxy->login($this->APIUser, $this->APIKey);
$filters = array(
'sku' => array('like'=>'somesku%')
);
try {
$products = $proxy->call($sessionId, 'product.list', array($filters));
$numProducts = sizeof($products);
for($i=0; $icall($sessionId, 'product.update',array($products[$i]['sku'], array('name'=>$new_product_name, 'meta_keyword'=>$new_meta_keyword,'meta_description'=>$new_meta_description,'meta_title'=>$new_meta_title)));
}
} catch (SoapFault $e){
echo $e->getMessage();
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment