What Are The Best Alternatives To Overriding A Shopware 6/Symfony Controller Function

34 Views Asked by At

I want to add more data to Shopware 6.4 core controller function

    /**
     * @Since("6.3.3.0")
     * @HttpCache()
     * @Route("/detail/{productId}", name="frontend.detail.page", methods={"GET"})
     */
    public function index(SalesChannelContext $context, Request $request): Response
    {
        $page = $this->productPageLoader->load($request, $context);

        $this->hook(new ProductPageLoadedHook($page, $context));

        $ratingSuccess = $request->get('success');

        /**
         * @deprecated tag:v6.5.0 - remove complete if statement, cms page id is always set
         *
         * Fallback layout for non-assigned product layout
         */
        if (!$page->getCmsPage()) {
            Feature::throwException('v6.5.0.0', 'Fallback will be removed because cms page is always set in subscriber.');

            return $this->renderStorefront('@Storefront/storefront/page/product-detail/index.html.twig', ['page' => $page, 'ratingSuccess' => $ratingSuccess]);
        }

        return $this->renderStorefront('@Storefront/storefront/page/content/product-detail.html.twig', ['page' => $page]);
    }

To more experience Symfony/Shopware developers, I would like to add more data to the index function

$page->setCountries($this->getCountries($salesChannelContext));

Are there other alternatives to overriding the function and what are your recommendations (pros and cons)?

0

There are 0 best solutions below