abinjohnedamanaabinjohnedamana MemberComments: 36 Received thanks: 9 Member since: February 2019 edited February 21

I want to pass some custom data to the product review form when the review from loads after the review saved. How to do that using events?

    /**
     * @Route("/product/{productId}/reviews", name="frontend.product.reviews", methods={"GET","POST"}, defaults={"XmlHttpRequest"=true})
     */
    public function loadReviews(Request $request, RequestDataBag $data, SalesChannelContext $context): Response
    {
        $reviews = $this->reviewPageletLoader->load($request, $context);

        return $this->renderStorefront('storefront/page/product-detail/review/review.html.twig', [
            'reviews' => $reviews,
            'ratingSuccess' => $request->get('success'),
        ]);
    }

This is the review loading action in ProductController.php (shopware controller).

 

I am using ProductEvents::PRODUCT_REVIEW_LOADED event. but unfortunately, I am not able to find any solution to this. how to do that?

Answers

  • abinjohnedamanaabinjohnedamana MemberComments: 36 Received thanks: 9 Member since: February 2019

    We can pass custom data to view the page by using StorefrontRenderEvent

        public static function getSubscribedEvents(): array
        {
            return [
                StorefrontRenderEvent::class => 'onStorefrontRender'
            ];
        }

        public function onStorefrontRender(StorefrontRenderEvent $event)
        {
            $route = $event->getRequest()->get('_route');

            if($route == 'frontend.product.reviews')
            {
                $event->setParameter('testParam', 'testParamValue');
            }
        }

    Thanked by 1ShapeAndShift
Sign In or Register to comment.