ExpfacturaService.php 5.1 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 ExpfacturaService
  28. {
  29. protected $marketplaceExpfacturaRepository;
  30. protected $marketplaceProductRepository;
  31. protected $facturisExpfacturaRepository;
  32. protected $facturisCustomerRepository;
  33. protected $facturisProductRepository;
  34. protected $settingsRepository;
  35. public function __construct(
  36. \Core\App\Repository\Marketplace\ExpfacturaInterface $marketplaceExpfacturaRepository,
  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\ExpfacturaInterface $facturisExpfacturaRepository,
  41. \Core\App\Repository\Marketplace\SettingsInterface $settingsRepository
  42. ) {
  43. $this->marketplaceExpfacturaRepository = $marketplaceExpfacturaRepository;
  44. $this->marketplaceProductRepository = $marketplaceProductRepository;
  45. $this->facturisExpfacturaRepository = $facturisExpfacturaRepository;
  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->marketplaceExpfacturaRepository->setRemoteCustomers($facturisCustomers);
  55. $this->marketplaceExpfacturaRepository->setRemoteProducts($facturisProducts);
  56. $this->marketplaceExpfacturaRepository->setOrderedDaysAgo($this->settingsRepository->getOptionOrderedDaysAgo());
  57. $this->marketplaceExpfacturaRepository->setExpfacturaSerie(
  58. $this->settingsRepository->getOptionExpfacturaSerie()
  59. );
  60. $withOutDiscount = true;
  61. $marketplaceProducts = $this->marketplaceProductRepository->getAll($withOutDiscount);
  62. $this->marketplaceExpfacturaRepository->setLocalProducts((array) $marketplaceProducts);
  63. $this->marketplaceExpfacturaRepository->setWithDiscount($this->settingsRepository->getOptionWithDiscount());
  64. $marketplaceExpfacturas = $this->marketplaceExpfacturaRepository->getAll();
  65. if (!empty($marketplaceExpfacturas)) {
  66. foreach ($marketplaceExpfacturas as $marketplaceExpfactura) {
  67. $result = $this->facturisExpfacturaRepository->add($marketplaceExpfactura);
  68. // $this->marketplaceExpfacturaRepository->addExpfactura($marketplaceExpfactura, $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->marketplaceExpfacturaRepository->setRemoteCustomers($facturisCustomers);
  78. $this->marketplaceExpfacturaRepository->setRemoteProducts($facturisProducts);
  79. $expfacturaSerie2 = $this->settingsRepository->getOptionExpfacturaSerie2();
  80. if (!empty($expfacturaSerie2)) {
  81. $this->marketplaceExpfacturaRepository->setExpfacturaSerie($expfacturaSerie2);
  82. } else {
  83. $this->marketplaceExpfacturaRepository->setExpfacturaSerie($this->settingsRepository->getOptionExpfacturaSerie());
  84. }
  85. $withOutDiscount = true;
  86. $marketplaceProducts = $this->marketplaceProductRepository->getAll($withOutDiscount);
  87. $this->marketplaceExpfacturaRepository->setLocalProducts((array) $marketplaceProducts);
  88. $this->marketplaceExpfacturaRepository->setWithDiscount($this->settingsRepository->getOptionWithDiscount());
  89. $marketplaceExpfactura = $this->marketplaceExpfacturaRepository->getByOrderId($orderId);
  90. if (!empty($marketplaceExpfactura)) {
  91. $result = $this->facturisExpfacturaRepository->add($marketplaceExpfactura);
  92. $this->marketplaceExpfacturaRepository->addExpfactura($marketplaceExpfactura, $result);
  93. return $result;
  94. }
  95. return $result;
  96. }
  97. }