diff --git a/src/Elcodi/Bundle/CurrencyBundle/Resources/config/commands.yml b/src/Elcodi/Bundle/CurrencyBundle/Resources/config/commands.yml index 3919fc320..2434e77bd 100644 --- a/src/Elcodi/Bundle/CurrencyBundle/Resources/config/commands.yml +++ b/src/Elcodi/Bundle/CurrencyBundle/Resources/config/commands.yml @@ -6,11 +6,13 @@ services: elcodi.core.currency.command.load_exchange_rates: class: %elcodi.core.currency.command.load_exchange_rates.class% arguments: - currency_repository: @elcodi.repository.currency + currency_object_manager: @elcodi.object_manager.currency + currency_exchange_rate_object_manager: @elcodi.object_manager.currency_exchange_rate currency_exchange_rate_factory: @elcodi.factory.currency_exchange_rate - currency_exchange_rate_repository: @elcodi.repository.currency_exchange_rate exchange_rates_provider: @elcodi.exchange_rates_provider - exchange_rate_object_manager: @elcodi.object_manager.currency_exchange_rate + currency_namespace: %elcodi.core.currency.entity.currency.class% + currency_namespace: %elcodi.core.currency.entity.currency_exchange_rate.class% + currency_exchange_rate_namespace: %elcodi.core.currency.entity.currency_exchange_rate.class% default_currency: %elcodi.core.currency.default_currency% tags: - { name: console.command } diff --git a/src/Elcodi/Component/Currency/Command/LoadExchangeRatesCommand.php b/src/Elcodi/Component/Currency/Command/LoadExchangeRatesCommand.php index 9b8ad8fb1..34e498059 100644 --- a/src/Elcodi/Component/Currency/Command/LoadExchangeRatesCommand.php +++ b/src/Elcodi/Component/Currency/Command/LoadExchangeRatesCommand.php @@ -17,6 +17,7 @@ namespace Elcodi\Component\Currency\Command; use Doctrine\Common\Persistence\ObjectManager; +use Doctrine\Common\Persistence\ObjectRepository; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -67,6 +68,20 @@ class LoadExchangeRatesCommand extends Command */ protected $exchangeRateObjectManager; + /** + * @var string + * + * Currency namespace + */ + protected $currencyNamespace; + + /** + * @var string + * + * CurrencyExchangeRate namespace + */ + protected $currencyExchangeRateNamespace; + /** * @var string * @@ -77,29 +92,32 @@ class LoadExchangeRatesCommand extends Command /** * Construct method * - * @param CurrencyRepository $currencyRepository Currency repository - * @param CurrencyExchangeRateFactory $currencyExchangeRateFactory CurrencyExchangeRate factory - * @param CurrencyExchangeRateRepository $currencyExchangeRateRepository CurrencyExchangeRate repository - * @param ExchangeRatesProvider $exchangeRatesProvider ExchangeRates provider - * @param ObjectManager $exchangeRateObjectManager ExchangeRate object manager - * @param string $defaultCurrency Default currency + * @param ObjectManager $currencyObjectManager Currency object manager + * @param ObjectManager $currencyExchangeRateObjectManager CurrencyExchangeRate object manager + * @param CurrencyExchangeRateFactory $currencyExchangeRateFactory CurrencyExchangeRate factory + * @param ExchangeRatesProvider $exchangeRatesProvider ExchangeRates provider + * @param string $currencyNamespace Currency namespace + * @param string $currencyExchangeRateNamespace CurrencyExchangeRate namespace + * @param string $defaultCurrency Default currency */ public function __construct( - CurrencyRepository $currencyRepository, + ObjectManager $currencyObjectManager, + ObjectManager $currencyExchangeRateObjectManager, CurrencyExchangeRateFactory $currencyExchangeRateFactory, - CurrencyExchangeRateRepository $currencyExchangeRateRepository, ExchangeRatesProvider $exchangeRatesProvider, - ObjectManager $exchangeRateObjectManager, + $currencyNamespace, + $currencyExchangeRateNamespace, $defaultCurrency ) { parent::__construct(); - $this->currencyRepository = $currencyRepository; + $this->currencyObjectManager = $currencyObjectManager; + $this->currencyExchangeRateObjectManager = $currencyExchangeRateObjectManager; $this->currencyExchangeRateFactory = $currencyExchangeRateFactory; - $this->currencyExchangeRateRepository = $currencyExchangeRateRepository; $this->exchangeRatesProvider = $exchangeRatesProvider; - $this->exchangeRateObjectManager = $exchangeRateObjectManager; + $this->currencyNamespace = $currencyNamespace; + $this->currencyExchangeRateNamespace = $currencyExchangeRateNamespace; $this->defaultCurrency = $defaultCurrency; } @@ -124,6 +142,18 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + /** + * @var ObjectRepository $currencyRepository + * @var ObjectRepository $currencyExchangeRateRepository + */ + $currencyRepository = $this + ->currencyObjectManager + ->getRepository($this->currencyNamespace); + + $currencyExchangeRateRepository = $this + ->currencyExchangeRateObjectManager + ->getRepository($this->currencyExchangeRateNamespace); + $currencies = $this ->currencyRepository ->findBy([ @@ -148,20 +178,18 @@ protected function execute(InputInterface $input, OutputInterface $output) foreach ($rates as $code => $rate) { - $sourceCurrency = $this - ->currencyRepository - ->findOneByIso([ + $sourceCurrency = $currencyRepository + ->findOneBy([ 'iso' => $this->defaultCurrency ]); - $targetCurrency = $this->currencyRepository - ->findOneByIso([ + $targetCurrency = $currencyRepository + ->findOneBy([ 'iso' => $code ]); //check if this is a new exchange rate, or if we have to create a new one - $exchangeRate = $this - ->currencyExchangeRateRepository + $exchangeRate = $currencyExchangeRateRepository ->findOneBy([ 'sourceCurrency' => $sourceCurrency, 'targetCurrency' => $targetCurrency diff --git a/src/Elcodi/Component/ReferralProgram/EventListener/ReferralProgramEventListener.php b/src/Elcodi/Component/ReferralProgram/EventListener/ReferralProgramEventListener.php index c15186dbb..7ce747984 100644 --- a/src/Elcodi/Component/ReferralProgram/EventListener/ReferralProgramEventListener.php +++ b/src/Elcodi/Component/ReferralProgram/EventListener/ReferralProgramEventListener.php @@ -16,11 +16,11 @@ namespace Elcodi\Component\ReferralProgram\EventListener; -use Elcodi\Component\Cart\Event\OrderOnCreatedEvent; use Symfony\Component\HttpFoundation\Cookie; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; +use Elcodi\Component\Cart\Event\OrderOnCreatedEvent; use Elcodi\Component\CartCoupon\Services\OrderCouponManager; use Elcodi\Component\ReferralProgram\ElcodiReferralProgramCookie; use Elcodi\Component\ReferralProgram\ElcodiReferralProgramRuleTypes;