StockController.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace Controller;
  3. class StockController
  4. {
  5. public $settingsRepository;
  6. public function __construct($settingsRepository)
  7. {
  8. $this->settingsRepository = $settingsRepository;
  9. }
  10. public function sync()
  11. {
  12. $marketplaceStockRepository = new \MarketplaceRepository\StockRepository(
  13. $this->settingsRepository->getToken(),
  14. $this->settingsRepository->getShop()
  15. );
  16. $marketplaceProductRepository = new \MarketplaceRepository\ProductRepository(
  17. $this->settingsRepository->getToken(),
  18. $this->settingsRepository->getShop()
  19. );
  20. $facturisStockRepository = new \Core\FacturisRepository\StockRepository(
  21. $this->settingsRepository->getAuthApiKey(),
  22. $this->settingsRepository->getAuthUsername(),
  23. $this->settingsRepository->getAuthPassword(),
  24. $this->settingsRepository->getAuthFiscalCode()
  25. );
  26. $service = new \Core\App\Service\StockService(
  27. $marketplaceStockRepository,
  28. $marketplaceProductRepository,
  29. $facturisStockRepository,
  30. $this->settingsRepository
  31. );
  32. $service->sync();
  33. }
  34. public function autoSync()
  35. {
  36. if($this->settingsRepository->getOptionAutoStockSync() == \Core\App\Factory\SettingsFactory::AUTO_SYNC_ENABLED)
  37. {
  38. $this->sync();
  39. }
  40. }
  41. }