* @copyright 2007-2021 PrestaShop SA * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ namespace Core\App\Service; class ExpfacturaService { protected $marketplaceExpfacturaRepository; protected $marketplaceProductRepository; protected $facturisExpfacturaRepository; protected $facturisCustomerRepository; protected $facturisProductRepository; protected $settingsRepository; public function __construct( \Core\App\Repository\Marketplace\ExpfacturaInterface $marketplaceExpfacturaRepository, \Core\App\Repository\Marketplace\ProductInterface $marketplaceProductRepository, \Core\App\Repository\Facturis\CustomerInterface $facturisCustomerRepository, \Core\App\Repository\Facturis\ProductInterface $facturisProductRepository, \Core\App\Repository\Facturis\ExpfacturaInterface $facturisExpfacturaRepository, \Core\App\Repository\Marketplace\SettingsInterface $settingsRepository ) { $this->marketplaceExpfacturaRepository = $marketplaceExpfacturaRepository; $this->marketplaceProductRepository = $marketplaceProductRepository; $this->facturisExpfacturaRepository = $facturisExpfacturaRepository; $this->facturisCustomerRepository = $facturisCustomerRepository; $this->facturisProductRepository = $facturisProductRepository; $this->settingsRepository = $settingsRepository; } public function sync() { $facturisCustomers = $this->facturisCustomerRepository->getAll(); $facturisProducts = $this->facturisProductRepository->getAll(); $this->marketplaceExpfacturaRepository->setRemoteCustomers($facturisCustomers); $this->marketplaceExpfacturaRepository->setRemoteProducts($facturisProducts); $this->marketplaceExpfacturaRepository->setOrderedDaysAgo($this->settingsRepository->getOptionOrderedDaysAgo()); $this->marketplaceExpfacturaRepository->setExpfacturaSerie( $this->settingsRepository->getOptionExpfacturaSerie() ); $withOutDiscount = true; $marketplaceProducts = $this->marketplaceProductRepository->getAll($withOutDiscount); $this->marketplaceExpfacturaRepository->setLocalProducts((array) $marketplaceProducts); $this->marketplaceExpfacturaRepository->setWithDiscount($this->settingsRepository->getOptionWithDiscount()); $marketplaceExpfacturas = $this->marketplaceExpfacturaRepository->getAll(); if (!empty($marketplaceExpfacturas)) { foreach ($marketplaceExpfacturas as $marketplaceExpfactura) { $result = $this->facturisExpfacturaRepository->add($marketplaceExpfactura); // $this->marketplaceExpfacturaRepository->addExpfactura($marketplaceExpfactura, $result); } } } public function add($orderId) { $result = array(); $facturisCustomers = $this->facturisCustomerRepository->getAll(); $facturisProducts = $this->facturisProductRepository->getAll(); $this->marketplaceExpfacturaRepository->setRemoteCustomers($facturisCustomers); $this->marketplaceExpfacturaRepository->setRemoteProducts($facturisProducts); $expfacturaSerie2 = $this->settingsRepository->getOptionExpfacturaSerie2(); if (!empty($expfacturaSerie2)) { $this->marketplaceExpfacturaRepository->setExpfacturaSerie($expfacturaSerie2); } else { $this->marketplaceExpfacturaRepository->setExpfacturaSerie($this->settingsRepository->getOptionExpfacturaSerie()); } $withOutDiscount = true; $marketplaceProducts = $this->marketplaceProductRepository->getAll($withOutDiscount); $this->marketplaceExpfacturaRepository->setLocalProducts((array) $marketplaceProducts); $this->marketplaceExpfacturaRepository->setWithDiscount($this->settingsRepository->getOptionWithDiscount()); $marketplaceExpfactura = $this->marketplaceExpfacturaRepository->getByOrderId($orderId); if (!empty($marketplaceExpfactura)) { $result = $this->facturisExpfacturaRepository->add($marketplaceExpfactura); $this->marketplaceExpfacturaRepository->addExpfactura($marketplaceExpfactura, $result); return $result; } return $result; } }