Return to Snippet

Revision: 25480
at March 31, 2010 10:02 by nick108


Updated Code
This script will change the Tax-Class of ALL your products in the $storeId!!<br />
Be careful to use!<br /><br />

<pre>
<?php 
$host = 'me.com';
$proxy = new SoapClient('http://'.$host.'/index.php/api/soap/?wsdl=1');
 
// Can be added in Magento-Admin -> Web Services
$apiUser = '***';
$apiKey  = '***';

// the id of the store, which products you want to update
$storeId = 0;

// the new TaxId, which you want to assign to ALL products
$newTaxId = 2;

try {

  $sessionId = $proxy->login($apiUser, $apiKey);
  $productList = $proxy->call($sessionId, 'product.list', array());

  foreach ($productList as $product):
    $productInfo = $proxy->call($sessionId, 'product.info', array($product['product_id'], $storeId));
      print_r($productInfo);

    // just to be sure: check if the product belongs to the store which i want to update
    if (in_array($storeId, $productInfo['websites']))
        $proxy->call($sessionId, 'product.update', array($product['product_id'], array('tax_class_id' => $newTaxId), $storeId));
        
    echo '<br /><br /><hr /><br /><br />';
  endforeach;

} catch (Exception $e) {
  echo "==> Error: ".$e->getMessage();
  exit();
}
?>
</pre>

Revision: 25479
at March 31, 2010 09:16 by nick108


Initial Code
This script will change the Tax-Class of ALL your products in the $storeId!!<br />
Be careful to use!<br /><br />

<pre>
<?php 
$host = 'me.com';
$proxy = new SoapClient('http://'.$host.'/index.php/api/soap/?wsdl=1');
 
// Can be added in Magento-Admin -> Web Services
$apiUser = '***';
$apiKey  = '***';

// the id of the store, which products you want to update
$storeId = 0;

// the new TaxId, which you want to assign to ALL products
$newTaxId = 2;

try {

  $sessionId = $proxy->login($apiUser, $apiKey);
  $productList = $proxy->call($sessionId, 'product.list', array());

  foreach ($productList as $product):
    $productInfo = $proxy->call($sessionId, 'product.info', array($product['product_id'], $storeId));
      print_r($productInfo);

    // just to be sure: check if the product belongs to the store which i want to update
    if (in_array($storeId, $productInfo['websites']))
        $proxy->call($sessionId, 'product.update', array($product['sku'], array('tax_class_id' => $newTaxId), $storeId));
        
    echo '<br /><br /><hr /><br /><br />';
  endforeach;

} catch (Exception $e) {
  echo "==> Error: ".$e->getMessage();
  exit();
}
?>
</pre>

Initial URL


Initial Description


Initial Title
Mass Update Products' Tax Class via Magento API

Initial Tags
update, api, magento

Initial Language
PHP