OrderOrProformaController.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace Controller;
  3. class OrderOrProformaController
  4. {
  5. public $marketplaceOrders;
  6. public $settingsRepository;
  7. public function __construct($settingsRepository)
  8. {
  9. $this->settingsRepository = $settingsRepository;
  10. }
  11. public function sync()
  12. {
  13. if($this->settingsRepository->getOptionOrderOrProforma() == \Core\App\Factory\SettingsFactory::SELECT_ORDER)
  14. {
  15. $this->syncOrders();
  16. return \Core\App\Factory\SettingsFactory::SELECT_ORDER;
  17. }
  18. if($this->settingsRepository->getOptionOrderOrProforma() == \Core\App\Factory\SettingsFactory::SELECT_PROFORMA)
  19. {
  20. $this->syncProformas();
  21. return \Core\App\Factory\SettingsFactory::SELECT_PROFORMA;
  22. }
  23. }
  24. public function syncOrders()
  25. {
  26. $facturisCustomerRepository = new \Core\FacturisRepository\CustomerRepository(
  27. $this->settingsRepository->getAuthApiKey(),
  28. $this->settingsRepository->getAuthUsername(),
  29. $this->settingsRepository->getAuthPassword(),
  30. $this->settingsRepository->getAuthFiscalCode()
  31. );
  32. $facturisProductRepository = new \Core\FacturisRepository\ProductRepository(
  33. $this->settingsRepository->getAuthApiKey(),
  34. $this->settingsRepository->getAuthUsername(),
  35. $this->settingsRepository->getAuthPassword(),
  36. $this->settingsRepository->getAuthFiscalCode()
  37. );
  38. $marketplaceOrderRepository = new \MarketplaceRepository\OrderRepository(
  39. $this->settingsRepository->getToken(),
  40. $this->settingsRepository->getShop()
  41. );
  42. $marketplaceProductRepository = new \MarketplaceRepository\ProductRepository(
  43. $this->settingsRepository->getToken(),
  44. $this->settingsRepository->getShop()
  45. );
  46. $facturisOrderRepository = new \Core\FacturisRepository\OrderRepository(
  47. $this->settingsRepository->getAuthApiKey(),
  48. $this->settingsRepository->getAuthUsername(),
  49. $this->settingsRepository->getAuthPassword(),
  50. $this->settingsRepository->getAuthFiscalCode()
  51. );
  52. $service = new \Core\App\Service\OrderService(
  53. $marketplaceOrderRepository,
  54. $marketplaceProductRepository,
  55. $facturisCustomerRepository,
  56. $facturisProductRepository,
  57. $facturisOrderRepository,
  58. $this->settingsRepository
  59. );
  60. $service->sync();
  61. }
  62. public function syncProformas()
  63. {
  64. $facturisCustomerRepository = new \Core\FacturisRepository\CustomerRepository(
  65. $this->settingsRepository->getAuthApiKey(),
  66. $this->settingsRepository->getAuthUsername(),
  67. $this->settingsRepository->getAuthPassword(),
  68. $this->settingsRepository->getAuthFiscalCode()
  69. );
  70. $facturisProductRepository = new \Core\FacturisRepository\ProductRepository(
  71. $this->settingsRepository->getAuthApiKey(),
  72. $this->settingsRepository->getAuthUsername(),
  73. $this->settingsRepository->getAuthPassword(),
  74. $this->settingsRepository->getAuthFiscalCode()
  75. );
  76. $marketplaceProformaRepository = new \MarketplaceRepository\ProformaRepository(
  77. $this->settingsRepository->getToken(),
  78. $this->settingsRepository->getShop()
  79. );
  80. $marketplaceProductRepository = new \MarketplaceRepository\ProductRepository(
  81. $this->settingsRepository->getToken(),
  82. $this->settingsRepository->getShop()
  83. );
  84. $facturisProformaRepository = new \Core\FacturisRepository\ProformaRepository(
  85. $this->settingsRepository->getAuthApiKey(),
  86. $this->settingsRepository->getAuthUsername(),
  87. $this->settingsRepository->getAuthPassword(),
  88. $this->settingsRepository->getAuthFiscalCode()
  89. );
  90. $service = new \Core\App\Service\ProformaService(
  91. $marketplaceProformaRepository,
  92. $marketplaceProductRepository,
  93. $facturisCustomerRepository,
  94. $facturisProductRepository,
  95. $facturisProformaRepository,
  96. $this->settingsRepository
  97. );
  98. $service->sync();
  99. }
  100. public function autoSync()
  101. {
  102. if($this->settingsRepository->getOptionAutoOrderSync() == \Core\App\Factory\SettingsFactory::AUTO_SYNC_ENABLED)
  103. {
  104. $this->sync();
  105. }
  106. }
  107. }