protected function getQueryBuilder(DataSetRequestInterface $request) : QueryBuilder { $queryBuilder = parent::getQueryBuilder($request); $this->filterNotEnabled($queryBuilder); $this->filterZeroPrices($queryBuilder); $queryBuilder->leftJoin(CurrencyRate::class, 'currency_rate', Expr\Join::WITH, 'currency_rate.currencyFrom = product.sellPrice.currency AND currency_rate.currencyTo = :targetCurrency'); $queryBuilder->setParameter('targetCurrency', $this->requestHelper->getCurrentCurrency()); $queryBuilder->setParameter('date', (new \DateTime())->setTime(0, 0, 1)); return $queryBuilder; }
/** * {@inheritdoc} */ public function getExchangeRate($baseCurrency = null, $targetCurrency = null) { $baseCurrency = null === $baseCurrency ? $this->requestHelper->getCurrentCurrency() : $baseCurrency; $targetCurrency = null === $targetCurrency ? $this->requestHelper->getCurrentCurrency() : $targetCurrency; $this->loadExchangeRates($targetCurrency); if (!isset($this->exchangeRates[$targetCurrency][$baseCurrency])) { throw new \InvalidArgumentException(sprintf('No exchange rate found for base "%s" and target "%s" currency.', $baseCurrency, $targetCurrency)); } return $this->exchangeRates[$targetCurrency][$baseCurrency]; }
/** * {@inheritdoc} */ public function getExchangeRate($baseCurrency = null, $targetCurrency = null) { $baseCurrency = null === $baseCurrency ? $this->requestHelper->getCurrentCurrency() : $baseCurrency; $targetCurrency = null === $targetCurrency ? $this->requestHelper->getCurrentCurrency() : $targetCurrency; $this->loadExchangeRates($targetCurrency); if (!isset($this->exchangeRates[$targetCurrency][$baseCurrency])) { throw new MissingCurrencyRateException($baseCurrency, $targetCurrency); } return $this->exchangeRates[$targetCurrency][$baseCurrency]; }
public function getCurrentOrder() : OrderInterface { if (null === $this->currentOrder) { $currency = $this->requestHelper->getCurrentCurrency(); $sessionId = $this->requestHelper->getSessionId(); $client = $this->securityHelper->getCurrentClient(); $shop = $this->shopStorage->getCurrentShop(); $this->currentOrder = $this->orderManager->getOrder($sessionId, $client, $shop, $currency); } return $this->currentOrder; }
/** * {@inheritdoc} */ public function format($amount, $currency = null, $locale = null) { if (null === $currency) { $currency = $this->requestHelper->getCurrentCurrency(); } $locale = $this->getLocale($locale); $formatter = new \NumberFormatter($locale, \NumberFormatter::CURRENCY); if (false === ($result = $formatter->formatCurrency($amount, $currency))) { throw new CurrencyFormatterException($amount, $currency, $locale); } return $result; }
public function create() : OrderInterface { $order = new Order(); $order->setConfirmed(false); $order->setProducts($this->createEmptyCollection()); $order->setProductTotal(new OrderProductTotal()); $order->setModifiers($this->createEmptyCollection()); $order->setPayments($this->createEmptyCollection()); $order->setOrderStatusHistory($this->createEmptyCollection()); $order->setComment(''); $order->setCurrency($this->requestHelper->getCurrentCurrency()); $order->setSummary(new OrderSummary()); $order->setShop($this->shopStorage->getCurrentShop()); $order->setClient($this->securityHelper->getCurrentClient()); $order->setSessionId($this->requestHelper->getSessionId()); $client = $this->securityHelper->getCurrentClient(); if ($client instanceof ClientInterface) { $order->setClientDetails($client->getClientDetails()); $order->setContactDetails($client->getContactDetails()); $order->setBillingAddress($client->getBillingAddress()); $order->setShippingAddress($client->getShippingAddress()); } else { $order->setClientDetails($this->detailsFactory->create()); $order->setContactDetails($this->contactDetailsFactory->create()); $order->setBillingAddress($this->billingAddressFactory->create()); $order->setShippingAddress($this->shippingAddressFactory->create()); } return $order; }
/** * Adds an additional left-join to currency_rate to calculate final prices in dataset * * @param QueryBuilder $queryBuilder */ private function addCurrencyRateConditions(QueryBuilder $queryBuilder) { $queryBuilder->leftJoin('WellCommerce\\Bundle\\CurrencyBundle\\Entity\\CurrencyRate', 'currency_rate', Expr\Join::WITH, 'currency_rate.currencyFrom = product.sellPrice.currency AND currency_rate.currencyTo = :targetCurrency'); $queryBuilder->setParameter('targetCurrency', $this->requestHelper->getCurrentCurrency()); }