SyncController.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace Controller;
  3. class SyncController
  4. {
  5. public $language;
  6. const TIME_LIMIT = 18000;
  7. public function __construct($db, $language, $shop = '')
  8. {
  9. set_time_limit( self::TIME_LIMIT );
  10. $this->language = $language;
  11. $this->settingsRepository = new \MarketplaceRepository\SettingsRepository($db, $shop);
  12. }
  13. public function sync()
  14. {
  15. if(isset($_POST['fsync_datatype']))
  16. {
  17. switch($_POST['fsync_datatype'])
  18. {
  19. case 'product': $result = $this->syncProduct();break;
  20. case 'order': $result = $this->syncOrderOrProforma();break;
  21. case 'stock': $result = $this->syncStock();break;
  22. default: $result = '';break;
  23. }
  24. }
  25. else
  26. {
  27. $result = '';
  28. }
  29. return $result;
  30. }
  31. public function syncProduct()
  32. {
  33. $controller = new \Controller\ProductController(
  34. $this->settingsRepository
  35. );
  36. $controller->sync();
  37. return $this->language->get('success_sync_prod');
  38. }
  39. public function syncOrderOrProforma()
  40. {
  41. $controller = new \Controller\OrderOrProformaController(
  42. $this->settingsRepository
  43. );
  44. $response = $controller->sync();
  45. if($response == \Core\App\Factory\SettingsFactory::SELECT_ORDER)
  46. {
  47. return $this->language->get('success_sync_order');
  48. }
  49. if($response == \Core\App\Factory\SettingsFactory::SELECT_PROFORMA)
  50. {
  51. return $this->language->get('success_sync_proforma');
  52. }
  53. }
  54. public function syncStock()
  55. {
  56. $controller = new \Controller\StockController(
  57. $this->settingsRepository
  58. );
  59. $controller->sync();
  60. return $this->language->get('success_sync_stock');
  61. }
  62. public function autoSync()
  63. {
  64. $orderController = new \Controller\OrderOrProformaController(
  65. $this->settingsRepository
  66. );
  67. $stockController = new \Controller\StockController(
  68. $this->settingsRepository
  69. );
  70. $orderController->autoSync();
  71. $stockController->autoSync();
  72. }
  73. }