OrderService.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace Core\App\Service;
  3. class OrderService {
  4. protected $marketplaceOrderRepository;
  5. protected $marketplaceProductRepository;
  6. protected $facturisOrderRepository;
  7. protected $facturisCustomerRepository;
  8. protected $facturisProductRepository;
  9. protected $settingsRepository;
  10. public function __construct(
  11. \Core\App\Repository\Marketplace\OrderInterface $marketplaceOrderRepository,
  12. \Core\App\Repository\Marketplace\ProductInterface $marketplaceProductRepository,
  13. \Core\App\Repository\Facturis\CustomerInterface $facturisCustomerRepository,
  14. \Core\App\Repository\Facturis\ProductInterface $facturisProductRepository,
  15. \Core\App\Repository\Facturis\OrderInterface $facturisOrderRepository,
  16. \Core\App\Repository\Marketplace\SettingsInterface $settingsRepository
  17. )
  18. {
  19. $this->marketplaceOrderRepository = $marketplaceOrderRepository;
  20. $this->marketplaceProductRepository = $marketplaceProductRepository;
  21. $this->facturisOrderRepository = $facturisOrderRepository;
  22. $this->facturisCustomerRepository = $facturisCustomerRepository;
  23. $this->facturisProductRepository = $facturisProductRepository;
  24. $this->settingsRepository = $settingsRepository;
  25. }
  26. public function sync() {
  27. $facturisCustomers = $this->facturisCustomerRepository->getAll();
  28. $facturisProducts = $this->facturisProductRepository->getAll();
  29. $this->marketplaceOrderRepository->setRemoteCustomers($facturisCustomers);
  30. $this->marketplaceOrderRepository->setRemoteProducts($facturisProducts);
  31. $this->marketplaceOrderRepository->setOrderedDaysAgo($this->settingsRepository->getOptionOrderedDaysAgo());
  32. $this->marketplaceOrderRepository->setWithDiscount($this->settingsRepository->getOptionWithDiscount());
  33. $withOutDiscount = true;
  34. $marketplaceProducts = $this->marketplaceProductRepository->getAll($withOutDiscount);
  35. $this->marketplaceOrderRepository->setLocalProducts((array) $marketplaceProducts);
  36. $marketplaceOrders = $this->marketplaceOrderRepository->getAll();
  37. if(!empty($marketplaceOrders))
  38. {
  39. foreach($marketplaceOrders as $marketplaceOrder)
  40. {
  41. $this->facturisOrderRepository->add($marketplaceOrder);
  42. }
  43. }
  44. }
  45. }