Mass Update Products' Tax Class via Magento API


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. This script will change the Tax-Class of ALL your products in the $storeId!!<br />
  2. Be careful to use!<br /><br />
  3.  
  4. <pre>
  5. <?php
  6. $host = 'me.com';
  7. $proxy = new SoapClient('http://'.$host.'/index.php/api/soap/?wsdl=1');
  8.  
  9. // Can be added in Magento-Admin -> Web Services
  10. $apiUser = '***';
  11. $apiKey = '***';
  12.  
  13. // the id of the store, which products you want to update
  14. $storeId = 0;
  15.  
  16. // the new TaxId, which you want to assign to ALL products
  17. $newTaxId = 2;
  18.  
  19. try {
  20.  
  21. $sessionId = $proxy->login($apiUser, $apiKey);
  22. $productList = $proxy->call($sessionId, 'product.list', array());
  23.  
  24. foreach ($productList as $product):
  25. $productInfo = $proxy->call($sessionId, 'product.info', array($product['product_id'], $storeId));
  26. print_r($productInfo);
  27.  
  28. // just to be sure: check if the product belongs to the store which i want to update
  29. if (in_array($storeId, $productInfo['websites']))
  30. $proxy->call($sessionId, 'product.update', array($product['product_id'], array('tax_class_id' => $newTaxId), $storeId));
  31.  
  32. echo '<br /><br /><hr /><br /><br />';
  33. endforeach;
  34.  
  35. } catch (Exception $e) {
  36. echo "==> Error: ".$e->getMessage();
  37. exit();
  38. }
  39. ?>
  40. </pre>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.