ProductSync.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. require_once("DataBase_Net/Product_Net.php");
  3. require_once("DataBase/Product.php");
  4. require_once("DataBase_Net/Price_Net.php");
  5. require_once("DataBase/Price.php");
  6. require_once("DataBase/Priceset.php");
  7. // sync Product database
  8. $product = new Product();
  9. $product_net = new Product_Net();
  10. $price = new Price();
  11. $price_net = new Price_Net();
  12. $priceset = new Priceset();
  13. $new_product_count = 0;
  14. $del_product_count = 0;
  15. // delete remote products if not locally available anymore
  16. $remote_product = $product_net->get('', array('product_id'));
  17. foreach($remote_product as $tmp)
  18. {
  19. if($product->exists($tmp[0], " available=1 ") == false)
  20. {
  21. $product_net->delete($tmp[0]);
  22. // delete also the prices
  23. $local_pricesets = $priceset->get('');
  24. foreach($local_pricesets as $tmp_priceset)
  25. {
  26. $tmp_price = $price_net->getPrice($tmp_priceset[0], $tmp[0]);
  27. if(count($tmp_price) > 0)
  28. $price_net->delete($tmp_price[0][0]);
  29. }
  30. $del_product_count++;
  31. }
  32. }
  33. // add products remote if newly available locally
  34. $remote_products = $product_net->get('', array('product_id'));
  35. $local_products = $product->get('', array('product_id'), " available=1 ");
  36. foreach($local_products as $tmp)
  37. {
  38. $found = false;
  39. foreach($remote_products as $remote_tmp)
  40. {
  41. if($remote_tmp[0] == $tmp[0])
  42. {
  43. $found = true;
  44. break;
  45. }
  46. }
  47. $tmp_data = $product->get($tmp[0], array( "name",
  48. "details",
  49. "category_id",
  50. "tax_id",
  51. "available",
  52. "group_id",
  53. "order_number",
  54. "anmerkung"));
  55. if(!$found)
  56. {
  57. $product_net->create($tmp[0], $tmp_data[0]);
  58. $new_product_count++;
  59. }
  60. else
  61. {
  62. $product_net->update($tmp[0], $tmp_data[0]);
  63. }
  64. }
  65. $main_box->add(new NTKLabel("", "neue Produkte online: ".$new_product_count), 200, 0, "background-color: #dfe7f3;");
  66. $main_box->add(new NTKLabel("", "online Produkte gel&ouml;scht: ".$del_product_count), 200, 0, "background-color: #dfe7f3;");
  67. // check for prices on products
  68. $local_products = $product->get('', array('product_id'), " available=1 ");
  69. $local_pricesets = $priceset->get('');
  70. foreach($local_products as $tmp)
  71. {
  72. foreach($local_pricesets as $tmp_priceset)
  73. {
  74. $tmp_price = $price->getPrice($tmp_priceset[0], $tmp[0]);
  75. if(count($tmp_price) <= 0)
  76. continue;
  77. if($price_net->exists($tmp_priceset[0], $tmp[0]))
  78. $price_net->update($tmp_priceset[0], $tmp[0], array_slice($tmp_price[0], 3));
  79. else
  80. $price_net->create($tmp_priceset[0], $tmp[0], array_slice($tmp_price[0], 3));
  81. }
  82. }
  83. ?>