AvizeService.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /**
  3. * 2007-2021 PrestaShop
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Academic Free License (AFL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/afl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@prestashop.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
  18. * versions in the future. If you wish to customize PrestaShop for your
  19. * needs please refer to http://www.prestashop.com for more information.
  20. *
  21. * @author PrestaShop SA <contact@prestashop.com>
  22. * @copyright 2007-2021 PrestaShop SA
  23. * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
  24. * International Registered Trademark & Property of PrestaShop SA
  25. */
  26. namespace Core\App\Service;
  27. class AvizeService
  28. {
  29. protected $marketplaceAvizeRepository;
  30. protected $marketplaceProductRepository;
  31. protected $facturisAvizeRepository;
  32. protected $facturisCustomerRepository;
  33. protected $facturisProductRepository;
  34. protected $settingsRepository;
  35. public function __construct(
  36. \Core\App\Repository\Marketplace\AvizeInterface $marketplaceAvizeRepository,
  37. \Core\App\Repository\Marketplace\ProductInterface $marketplaceProductRepository,
  38. \Core\App\Repository\Facturis\CustomerInterface $facturisCustomerRepository,
  39. \Core\App\Repository\Facturis\ProductInterface $facturisProductRepository,
  40. \Core\App\Repository\Facturis\AvizeInterface $facturisAvizeRepository,
  41. \Core\App\Repository\Marketplace\SettingsInterface $settingsRepository
  42. ) {
  43. $this->marketplaceAvizeRepository = $marketplaceAvizeRepository;
  44. $this->marketplaceProductRepository = $marketplaceProductRepository;
  45. $this->facturisAvizeRepository = $facturisAvizeRepository;
  46. $this->facturisCustomerRepository = $facturisCustomerRepository;
  47. $this->facturisProductRepository = $facturisProductRepository;
  48. $this->settingsRepository = $settingsRepository;
  49. }
  50. public function sync()
  51. {
  52. $facturisCustomers = $this->facturisCustomerRepository->getAll();
  53. $facturisProducts = $this->facturisProductRepository->getAll();
  54. $this->marketplaceAvizeRepository->setRemoteCustomers($facturisCustomers);
  55. $this->marketplaceAvizeRepository->setRemoteProducts($facturisProducts);
  56. $this->marketplaceAvizeRepository->setOrderedDaysAgo($this->settingsRepository->getOptionOrderedDaysAgo());
  57. $this->marketplaceAvizeRepository->setAvizeSerie(
  58. $this->settingsRepository->getOptionAvizeSerie()
  59. );
  60. $withOutDiscount = true;
  61. $marketplaceProducts = $this->marketplaceProductRepository->getAll($withOutDiscount);
  62. $this->marketplaceAvizeRepository->setLocalProducts((array) $marketplaceProducts);
  63. $this->marketplaceAvizeRepository->setWithDiscount($this->settingsRepository->getOptionWithDiscount());
  64. $marketplaceAvizes = $this->marketplaceAvizeRepository->getAll();
  65. if (!empty($marketplaceAvizes)) {
  66. foreach ($marketplaceAvizes as $marketplaceAvize) {
  67. $result = $this->facturisAvizeRepository->add($marketplaceAvize);
  68. // $this->marketplaceAvizeRepository->addAvize($marketplaceAvize, $result);
  69. }
  70. }
  71. }
  72. public function add($orderId)
  73. {
  74. $result = array();
  75. $facturisCustomers = $this->facturisCustomerRepository->getAll();
  76. $facturisProducts = $this->facturisProductRepository->getAll();
  77. $this->marketplaceAvizeRepository->setRemoteCustomers($facturisCustomers);
  78. $this->marketplaceAvizeRepository->setRemoteProducts($facturisProducts);
  79. $avizeSerie2 = $this->settingsRepository->getOptionAvizeSerie2();
  80. if (!empty($avizeSerie2)) {
  81. $this->marketplaceAvizeRepository->setAvizeSerie($avizeSerie2);
  82. } else {
  83. $this->marketplaceAvizeRepository->setAvizeSerie($this->settingsRepository->getOptionAvizeSerie());
  84. }
  85. $withOutDiscount = true;
  86. $marketplaceProducts = $this->marketplaceProductRepository->getAll($withOutDiscount);
  87. $this->marketplaceAvizeRepository->setLocalProducts((array) $marketplaceProducts);
  88. $this->marketplaceAvizeRepository->setWithDiscount($this->settingsRepository->getOptionWithDiscount());
  89. $marketplaceAvize = $this->marketplaceAvizeRepository->getByOrderId($orderId);
  90. if (!empty($marketplaceAvize)) {
  91. $result = $this->facturisAvizeRepository->add($marketplaceAvize);
  92. $this->marketplaceAvizeRepository->addAvize($marketplaceAvize, $result);
  93. return $result;
  94. }
  95. return $result;
  96. }
  97. }