/** * Builds frontend main menu. * * @return ItemInterface */ public function createMainMenu() { $menu = $this->factory->createItem('root', ['childrenAttributes' => ['class' => 'nav nav-pills']]); $menu->setCurrentUri($this->request->getRequestUri()); $cart = $this->cartContext->getCart(); $cartTotals = ['items' => $cart->getTotalQuantity(), 'total' => $cart->getTotal()]; $menu->addChild('cart', ['route' => 'sylius_cart_summary', 'linkAttributes' => ['title' => $this->translate('sylius.frontend.menu.main.cart', ['%items%' => $cartTotals['items'], '%total%' => $this->priceHelper->convertAndFormatAmount($cartTotals['total'])])], 'labelAttributes' => ['icon' => 'icon-shopping-cart icon-large']])->setLabel($this->translate('sylius.frontend.menu.main.cart', ['%items%' => $cartTotals['items'], '%total%' => $this->priceHelper->convertAndFormatAmount($cartTotals['total'])])); if ($this->authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')) { $route = $this->request === null ? '' : $this->request->get('_route'); if (1 === preg_match('/^(sylius_account)/', $route)) { $menu->addChild('shop', ['route' => 'sylius_homepage', 'linkAttributes' => ['title' => $this->translate('sylius.frontend.menu.account.shop')], 'labelAttributes' => ['icon' => 'icon-th icon-large', 'iconOnly' => false]])->setLabel($this->translate('sylius.frontend.menu.account.shop')); } else { $menu->addChild('account', ['route' => 'sylius_account_profile_show', 'linkAttributes' => ['title' => $this->translate('sylius.frontend.menu.main.account')], 'labelAttributes' => ['icon' => 'icon-user icon-large', 'iconOnly' => false]])->setLabel($this->translate('sylius.frontend.menu.main.account')); } $menu->addChild('logout', ['route' => 'sylius_user_security_logout', 'linkAttributes' => ['title' => $this->translate('sylius.frontend.menu.main.logout')], 'labelAttributes' => ['icon' => 'icon-off icon-large', 'iconOnly' => false]])->setLabel($this->translate('sylius.frontend.menu.main.logout')); } else { $menu->addChild('login', ['route' => 'sylius_user_security_login', 'linkAttributes' => ['title' => $this->translate('sylius.frontend.menu.main.login')], 'labelAttributes' => ['icon' => 'icon-lock icon-large', 'iconOnly' => false]])->setLabel($this->translate('sylius.frontend.menu.main.login')); $menu->addChild('register', ['route' => 'sylius_user_registration', 'linkAttributes' => ['title' => $this->translate('sylius.frontend.menu.main.register')], 'labelAttributes' => ['icon' => 'icon-user icon-large', 'iconOnly' => false]])->setLabel($this->translate('sylius.frontend.menu.main.register')); } if ($this->authorizationChecker->isGranted('ROLE_ADMINISTRATION_ACCESS') || $this->authorizationChecker->isGranted('ROLE_PREVIOUS_ADMIN')) { $routeParams = ['route' => 'sylius_backend_dashboard', 'linkAttributes' => ['title' => $this->translate('sylius.frontend.menu.main.administration')], 'labelAttributes' => ['icon' => 'icon-briefcase icon-large', 'iconOnly' => false]]; if ($this->authorizationChecker->isGranted('ROLE_PREVIOUS_ADMIN')) { $routeParams = array_merge($routeParams, ['route' => 'sylius_switch_user_return', 'routeParameters' => ['username' => $this->tokenStorage->getToken()->getUsername(), '_switch_user' => '_exit']]); } $menu->addChild('administration', $routeParams)->setLabel($this->translate('sylius.frontend.menu.main.administration')); } $this->eventDispatcher->dispatch(MenuBuilderEvent::FRONTEND_MAIN, new MenuBuilderEvent($this->factory, $menu)); return $menu; }
/** * {@inheritdoc} */ public function convertAndFormatAmount($amount, $currencyCode = null, $locale = null) { $currencyCode = $currencyCode ?: $this->currencyContext->getCurrencyCode(); return $this->decoratedHelper->convertAndFormatAmount($amount, $currencyCode, $locale); }
function it_decorates_the_helper_with_current_currency_if_it_is_not_passed(PriceHelperInterface $decoratedHelper, CurrencyContextInterface $currencyContext) { $currencyContext->getCurrencyCode()->willReturn('EUR'); $decoratedHelper->convertAndFormatAmount(42, 'EUR', null, null)->willReturn('€0.42'); $this->convertAndFormatAmount(42)->shouldReturn('€0.42'); }