ensureRouter example

$view->loadTemplate('frontend/detail/' . $product['template']);
        } elseif (!empty($product['mode'])) {
            $view->loadTemplate('frontend/blog/detail.tpl');
        } elseif ($tpl === 'ajax') {
            $view->loadTemplate('frontend/detail/ajax.tpl');
        }

        $product = $this->container->get('modules')->Articles()->sGetConfiguratorImage($product);
        $product['sBundles'] = false;

        if (!empty($this->container->get(Config::class)->get('InquiryID'))) {
            $view->assign('sInquiry', $this->Front()->ensureRouter()->assemble([
                'sViewport' => 'support',
                'sFid' => $this->container->get(Config::class)->get('InquiryID'),
                'sInquiry' => 'detail',
                'sOrdernumber' => $product['ordernumber'],
            ]));
        }

        if (!empty($product['categoryID'])) {
            $breadcrumb = array_reverse($this->container->get('modules')->Categories()->sGetCategoriesByParent($product['categoryID']));
            $categoryInfo = end($breadcrumb);
        } else {
            


                if (isset($extractParams)) {
                    return '<?php echo htmlspecialchars(Shopware()->Front()->ensureRouter()->assemble(array(' . $params . ')+(array) ' . $extractParams . ')); ?>';
                }

                return '<?php echo htmlspecialchars(Shopware()->Front()->ensureRouter()->assemble(array(' . $params . '))); ?>';
            }
            $params[$index] = is_numeric($param) ? $param : substr($param, 1, -1);
        }

        $url = Shopware()->Front()->ensureRouter()->assemble($params);

        return '<?php echo ' . var_export(htmlspecialchars($url), true) . ';?>';
    }
}
                $this->sendMail(Shopware()->System()->_POST['newsletter'], 'sNEWSLETTERCONFIRMATION');
            }
        } else {
            $this->View()->assign('sStatus', Shopware()->Modules()->Admin()->sNewsletterSubscription(Shopware()->System()->_POST['newsletter']));

            if ($this->View()->getAssign('sStatus')['code'] == 3) {
                if ($this->View()->getAssign('sStatus')['isNewRegistration']) {
                    Shopware()->Modules()->Admin()->sNewsletterSubscription(Shopware()->System()->_POST['newsletter'], true);
                    $hash = Random::getAlphanumericString(32);
                    $data = serialize(Shopware()->System()->_POST->toArray());

                    $link = $this->Front()->ensureRouter()->assemble(['sViewport' => 'newsletter', 'action' => 'index', 'sConfirmation' => $hash]);

                    $this->sendMail(Shopware()->System()->_POST['newsletter'], 'sOPTINNEWSLETTER', $link);

                    Shopware()->Db()->query(' INSERT INTO s_core_optin (datum,hash,data,type) VALUES ( now(),?,?,"swNewsletter" ) ', [$hash$data]);
                }

                
Shopware()->System()->_POST = [
            'email' => $user['email'],
            'passwordMD5' => $user['password'],
        ];
        Shopware()->Modules()->Admin()->sLogin(true);

        $hash = $this->container->get(OptinServiceInterface::class)->add(OptinServiceInterface::TYPE_CUSTOMER_LOGIN_FROM_BACKEND, 300, [
            'sessionId' => Shopware()->Session()->get('sessionId'),
            'shopId' => $shop->getId(),
        ]);

        $url = $this->Front()->ensureRouter()->assemble([
            'action' => 'performOrderRedirect',
            'hash' => $hash,
            'fullPath' => true,
        ]);

        if ($shop->getHost()) {
            // change the url to the subshop url             $url = str_replace('://' . $this->Request()->getHttpHost(), '://' . $shop->getHost()$url);
        }

        $this->redirect($url);
    }
if (!empty($title)) {
            $queryArray['title'] = $title;
        }
        $queryArray['module'] = 'frontend';

        $newQueryArray = [];
        foreach ($queryArray as $key => $queryItem) {
            $newQueryArray[(string) $key] = $queryItem;
        }

        return $this->front->ensureRouter()->assemble($newQueryArray);
    }
}
$repository = $this->get('models')->getRepository(Shop::class);
        $shop = $repository->getActiveById($shopId);

        if (!$shop instanceof Shop) {
            throw new Exception('Invalid shop provided.');
        }

        $this->get(ShopRegistrationServiceInterface::class)->registerShop($shop);

        Shopware()->Session()->set('Admin', true);

        $url = $this->Front()->ensureRouter()->assemble(
            [
                'module' => 'frontend',
                'controller' => 'detail',
                'sArticle' => $productId,
            ]
        );

        $this->Response()->headers->setCookie(new Cookie('shop', (string) $shopId, 0, $shop->getBasePath()));
        $this->redirect($url);
    }

    

    public function redirect($url, array $options = [])
    {
        if (\is_array($url)) {
            $url = $this->Front()->ensureRouter()->assemble($url);
        }
        if (!preg_match('#^(https?|ftp)://#', $url)) {
            if (!str_starts_with($url, '/')) {
                $url = $this->Request()->getBaseUrl() . '/' . $url;
            }
            $uri = $this->Request()->getScheme() . '://' . $this->Request()->getHttpHost();
            $url = $uri . $url;
        }

        $this->Response()->setRedirect($urlempty($options['code']) ? 302 : (int) $options['code']);
    }

    
 else {
            // Check if mail address is already subscribed, return             if ($this->db->fetchOne('SELECT id FROM s_campaigns_mailaddresses WHERE email = ?', [$email])) {
                return false;
            }

            $optInNewsletter = $this->config->get('optinnewsletter');
            if ($optInNewsletter) {
                $hash = Random::getAlphanumericString(32);
                $data = serialize(['newsletter' => $email, 'subscribeToNewsletter' => true]);

                $link = $this->front->ensureRouter()->assemble([
                    'sViewport' => 'newsletter',
                    'action' => 'index',
                    'sConfirmation' => $hash,
                    'module' => 'frontend',
                ]);

                $this->sendMail($email, 'sOPTINNEWSLETTER', $link);

                $this->db->insert(
                    's_core_optin',
                    [
                        
        $globalParams = $context->getGlobalParams();
        $newContext->setGlobalParams($globalParams);
        $router->setContext($newContext);
    }

    public function onPreDispatch(Enlight_Controller_EventArgs $args)
    {
        /** @var Enlight_Controller_Front $front */
        $front = $args->getSubject();
        $request = $front->Request();
        /** @var RouterInterface $router */
        $router = $front->ensureRouter();
        // Fix context on forward         $context = $router->getContext();
        $context->setGlobalParams($context::getGlobalParamsFromRequest($request));
    }

    private function convertIteratorToArray(iterable $iterator): array
    {
        if (\is_array($iterator)) {
            return $iterator;
        }

        
$partnerId = $this->Request()->getParam('sPartner');

        $repository = $this->get('models')->getRepository(Shop::class);
        $shop = $repository->getActiveDefault();

        if (!$shop instanceof Shop) {
            throw new Exception('Invalid shop provided.');
        }

        $this->get(ShopRegistrationServiceInterface::class)->registerShop($shop);

        $url = $this->Front()->ensureRouter()->assemble(['module' => 'frontend', 'controller' => 'index']);

        $this->redirect($url . '?sPartner=' . urlencode($partnerId));
    }

    protected function initAcl()
    {
        /* * permission to list all partner */
        $this->addAclPermission('getList', 'read', 'Insufficient Permissions');

        
$AlreadyNotified = $connection->fetchAssoc(' SELECT * FROM `s_articles_notification` WHERE `ordernumber`=? AND `mail` = ? AND send = 0 ', [$notifyOrderNumber$email]);

                if (empty($AlreadyNotified)) {
                    $action->View()->assign('NotifyAlreadyRegistered', false);

                    $hash = Random::getAlphanumericString(32);
                    $link = $action->Front()->ensureRouter()->assemble([
                        'sViewport' => 'detail',
                        'sArticle' => $id,
                        'sNotificationConfirmation' => $hash,
                        'sNotify' => '1',
                        'action' => 'notifyConfirm',
                        'number' => $notifyOrderNumber,
                    ]);

                    /** @var Shopware_Components_Modules $modules */
                    $modules = $this->get('modules');

                    
$this->modelManager->refresh($customer);
    }

    private function getPartnerId(Customer $customer): int
    {
        return (int) $this->connection->fetchColumn('SELECT id FROM s_emarketing_partner WHERE idcode = ?', [$customer->getAffiliate()]);
    }

    private function doubleOptInVerificationMail(ShopStruct $shop, Customer $customer, string $hash): void
    {
        $container = Shopware()->Container();
        $router = Shopware()->Front()->ensureRouter();

        $shopModel = $this->modelManager->getRepository(ShopModel::class)->getById($shop->getId());
        if ($shopModel === null) {
            throw new ModelNotFoundException(ShopModel::class$shop->getId());
        }
        $router->setContext(
            Context::createFromShop(
                $shopModel,
                $this->config
            )
        );
        
if (!empty(Shopware()->Config()->get('CaptchaColor'))) {
                /** @var \Shopware\Components\Captcha\CaptchaValidator $captchaValidator */
                $captchaValidator = $this->container->get('shopware.captcha.validator');

                if (!$captchaValidator->validate($this->Request())) {
                    $variables['sError'] = true;
                }
            }

            if ($variables['sError'] == false) {
                // Prepare eMail                 $product['linkDetails'] = $this->Front()->ensureRouter()->assemble(['sViewport' => 'detail', 'sArticle' => $product['articleID']]);

                $context = [
                    'sName' => $this->sSYSTEM->_POST['sName'],
                    'sArticle' => html_entity_decode($product['articleName']),
                    'sLink' => $product['linkDetails'],
                ];

                if ($this->sSYSTEM->_POST['sComment']) {
                    $context['sComment'] = strip_tags(html_entity_decode($this->sSYSTEM->_POST['sComment']));
                } else {
                    $context['sComment'] = '';
                }
private function getUrls(Type $type): array
    {
        $shops = $this->getModelManager()->getRepository(Shop::class)->getActiveShopsFixed();

        $urls = [];

        foreach ($shops as $shop) {
            $shop->registerResources();

            $urls[] = [
                'name' => $shop->getName(),
                'url' => $this->Front()->ensureRouter()->assemble([
                    'controller' => $type->getControllerName(),
                    'module' => 'frontend',
                    'action' => 'index',
                    'fullPath' => true,
                ]),
            ];
        }

        return $urls;
    }
}
if ($product) {
                $blogArticleData['sRelatedArticles'][] = $product;
            }
        }

        // Adding average vote data to the blog article         $avgVoteQuery = $this->repository->getAverageVoteQuery($blogArticleId$shop->getId());
        $blogArticleData['sVoteAverage'] = $avgVoteQuery->getOneOrNullResult(AbstractQuery::HYDRATE_SINGLE_SCALAR);

        // Generate breadcrumb         $breadcrumb = $this->getCategoryBreadcrumb($blogArticleData['categoryId']);
        $blogDetailLink = $this->Front()->ensureRouter()->assemble([
            'sViewport' => 'blog', 'sCategory' => $blogArticleData['categoryId'],
            'action' => 'detail', 'blogArticle' => $blogArticleId,
        ]);

        $breadcrumb[] = ['link' => $blogDetailLink, 'name' => $blogArticleData['title']];

        $this->View()->assign([
            'sBreadcrumb' => $breadcrumb,
            'sArticle' => $blogArticleData,
            'rand' => Random::getAlphanumericString(32),
            'sNumberPages' => 1,
        ]);
Home | Imprint | This part of the site doesn't use cookies.