Elcodi\Store\ProductBundle\Controller\PurchasableController::viewAction PHP Метод

viewAction() публичный Метод

Purchasable view
public viewAction ( integer $id, string $slug ) : array
$id integer Purchasable id
$slug string Product slug
Результат array
    public function viewAction($id, $slug)
    {
        $purchasable = $this->get('elcodi.repository.purchasable')->find($id);
        if (!$purchasable instanceof PurchasableInterface) {
            throw new EntityNotFoundException('Purchasable not found');
        }
        /**
         * We must check that the purchasable slug is right. Otherwise we must
         * return a Redirection 301 to the right url
         */
        if ($slug !== $purchasable->getSlug()) {
            $route = $this->get('request_stack')->getCurrentRequest()->get('_route');
            return $this->redirectToRoute($route, ['id' => $purchasable->getId(), 'slug' => $purchasable->getSlug()], 301);
        }
        $useStock = $this->get('elcodi.store')->getUseStock();
        $template = $this->resolveTemplateName($purchasable);
        $variableName = $this->resolveVariableName($purchasable);
        return $this->renderTemplate($template, [$variableName => $purchasable, 'useStock' => $useStock]);
    }