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]);
}