Sonata\ProductBundle\Controller\ProductController::viewAction PHP Method

viewAction() public method

public viewAction ( $productId, $slug ) : Response
$productId
$slug
return Symfony\Component\HttpFoundation\Response
    public function viewAction($productId, $slug)
    {
        $product = $this->get('sonata.product.set.manager')->findEnabledFromIdAndSlug($productId, $slug);
        if (!$product) {
            throw new NotFoundHttpException(sprintf('Unable to find the product with id=%d', $productId));
        }
        /** @var \Sonata\Component\Product\Pool $productPool */
        $productPool = $this->get('sonata.product.pool');
        $provider = $productPool->getProvider($product);
        if ($provider->hasVariations($product)) {
            if (!$provider->hasEnabledVariations($product)) {
                throw new NotFoundHttpException('Product has no activated variation');
            }
            // We display the cheapest variation
            $product = $provider->getCheapestEnabledVariation($product);
        }
        $action = sprintf('%s:view', $provider->getBaseControllerName());
        $response = $this->forward($action, array('provider' => $provider, 'product' => $product));
        if ($this->get('kernel')->isDebug()) {
            $response->setContent(sprintf("\n<!-- [Sonata] Product code: %s, id: %s, action: %s  -->\n%s\n<!-- [Sonata] end product -->\n", $this->get('sonata.product.pool')->getProductCode($product), $product->getId(), $action, $response->getContent()));
        }
        return $response;
    }