product_sync.class.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. trait ProductSync
  3. {
  4. private $productJSON;
  5. private $productPriceJSON;
  6. private $productExtrafieldsJSON;
  7. /**
  8. * Product syncronisation
  9. *
  10. * @return array|mixed|string Data without useless information
  11. *
  12. * @url POST Sync
  13. */
  14. public function Sync()
  15. {
  16. $this->BBUSProductJSON();
  17. $this->curlRunner('bbus/syncproduct', '', 'POST', true);
  18. //$this->BBUSProductPriceJSON();
  19. //$this->BBUSProductExtrafieldsJSON();
  20. //print_r($this->productJSON);
  21. exit;
  22. return 'OK';
  23. }
  24. private function BBUSProductJSON(): void {
  25. $sql = "SELECT * FROM llx_product WHERE rowid > 5000";
  26. $this->productJSON = $this->CreateJSON($sql);
  27. }
  28. private function BBUSProductPriceJSON(): void {
  29. $sql = "SELECT * FROM llx_product_price WHERE fk_object > 5000";
  30. $this->productPriceJSON = $this->CreateJSON($sql);
  31. }
  32. private function BBUSProductExtrafieldsJSON(): void {
  33. $sql = "SELECT * FROM llx_product_extrafields WHERE fk_object > 5000";
  34. $this->productExtrafieldsJSON = $this->CreateJSON($sql);
  35. }
  36. private function CreateJSON($sql): string
  37. {
  38. global $db;
  39. $array = [];
  40. $JSON = '';
  41. $result = $db->query($sql);
  42. if ($db->num_rows($result) > 0) {
  43. while ($row = $db->fetch_object($result)) {
  44. $array[] = $row;
  45. }
  46. $JSON = json_encode($array);
  47. }
  48. return $JSON;
  49. }
  50. private function decodeJSON($JSON):array{
  51. if($JSON !== ''){
  52. return json_decode($JSON);
  53. }
  54. return [];
  55. }
  56. /**
  57. * syncproduct
  58. *
  59. * @param int $product_id Product rowid
  60. *
  61. * @return array|mixed Data without useless information
  62. *
  63. * @url POST syncproduct
  64. *
  65. * @throws RestException 401
  66. * @throws RestException 403
  67. * @throws RestException 404
  68. */
  69. public function syncproduct($JSON)
  70. {
  71. $products = $this->decodeJSON($JSON);
  72. print_r($products);
  73. }
  74. }