123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- /**
- * 2007-2021 PrestaShop
- *
- * NOTICE OF LICENSE
- *
- * This source file is subject to the Academic Free License (AFL 3.0)
- * that is bundled with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://opensource.org/licenses/afl-3.0.php
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@prestashop.com so we can send you a copy immediately.
- *
- * DISCLAIMER
- *
- * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
- * versions in the future. If you wish to customize PrestaShop for your
- * needs please refer to http://www.prestashop.com for more information.
- *
- * @author PrestaShop SA <contact@prestashop.com>
- * @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;
- }
- }
|