8000 Updated command construction to be compatible with console by mmoreram · Pull Request #253 · elcodi/elcodi · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on May 30, 2019. It is now read-only.

Updated command construction to be compatible with console #253

Merged
merged 1 commit into from
Aug 29, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
66 changes: 47 additions & 19 deletions src/Elcodi/Component/Currency/Command/LoadExchangeRatesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -67,6 +68,20 @@ class LoadExchangeRatesCommand extends Command
*/
protected $exchangeRateObjectManager;

/**
* @var string
*
* Currency namespace
*/
protected $currencyNamespace;

/**
* @var string
*
* CurrencyExchangeRate namespace
*/
protected $currencyExchangeRateNamespace;

/**
* @var string
*
Expand All @@ -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 10000 $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;
}

Expand All @@ -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([
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
0