/** * Generates a dynamic route with replaced parameters * * @param array $replacements * * @return string */ public function getDynamicPath(array $replacements = []) { $route = $this->requestHelper->getAttributesBagParam('_route'); $currentAttributesParams = $this->requestHelper->getAttributesBagParam('_route_params'); $currentQueryParams = $this->requestHelper->getCurrentRequest()->query->all(); $routeParams = array_replace($currentAttributesParams, $replacements); $routeParams = array_merge($routeParams, $currentQueryParams); return $this->generator->generate($route, $routeParams); }
/** * {@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]; }
/** * {@inheritdoc} */ public function format($amount, $currency = null, $locale = null) { if (null === $currency) { $currency = $this->requestHelper->getCurrentCurrency(); } if (null === $locale) { $locale = $this->requestHelper->getCurrentLocale(); } $formatter = new \NumberFormatter($locale, \NumberFormatter::CURRENCY); if (false === ($result = $formatter->formatCurrency($amount, $currency))) { throw new CurrencyFormatterException($amount, $currency, $locale); } return $result; }
/** * {@inheritdoc} */ public function getCurrentRoute() { $routeName = $this->requestHelper->getAttributesBagParam('_route'); $route = $this->router->getRouteCollection()->get($routeName); if (null === $route) { throw new \RuntimeException('Cannot determine current route from request'); } return $this->router->getRouteCollection()->get($routeName); }
/** * Checks whether passed route is the same as in request * * @param string $route * * @return bool */ public function checkRouteIsActive($route) { $currentRoute = $this->requestHelper->getAttributesBagParam('_route'); return $route === $currentRoute; }
/** * Checks whether the sorting option is active * * @param $column * @param $direction * * @return bool */ protected function checkSortingIsActive($column, $direction) { $currentOrderBy = $this->requestHelper->getAttributesBagParam('orderBy'); $currentOrderDir = $this->requestHelper->getAttributesBagParam('orderDir'); return $column === $currentOrderBy && $direction === $currentOrderDir; }
/** * 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\\AppBundle\\Entity\\CurrencyRate', 'currency_rate', Expr\Join::WITH, 'currency_rate.currencyFrom = product.sellPrice.currency AND currency_rate.currencyTo = :targetCurrency'); $queryBuilder->setParameter('targetCurrency', $this->requestHelper->getCurrentCurrency()); }