Мне нужно использовать метод productRepository из пользовательского расширения ветки. Я могу использовать стандартные методы, такие как «findOneBy», но если я определить пользовательский метод в productRepository (скажу returnVariants()), то я получаю эту ошибку:Sylius: использовать репозиторий продуктов из пользовательского шаблона Twig
An exception has been thrown during the rendering of a template ("Undefined method 'returnVariants'. The method name must start with either findBy or findOneBy!") in SyliusWebBundle:Frontend/Homepage:main.html.twig at line 16.
код расширения пользовательской веточки:
namespace Sylius\Bundle\WebBundle\Twig;
use Symfony\Bridge\Doctrine\RegistryInterface;
class ProductExtension extends \Twig_Extension
{
public function __construct(RegistryInterface $doctrine)
{
$this->doctrine = $doctrine;
}
public function getFunctions()
{
return array(
'product_func' => new \Twig_Function_Method($this, 'productFunc'),
);
}
public function productFunc($id)
{
/* This works */
$product = $this->doctrine->getRepository('SyliusCoreBundle:Product')
->findOneBy(array('id' => $id));
/* This doesn't */
$product = $this->doctrine->getRepository('SyliusCoreBundle:Product')->returnVariants();
return $product->getPrice();
}
Большое вам спасибо за помощь!
Спасибо! Объект не использовал репозиторий. Наконец, я должен отредактировать Product.orm.xml и добавить класс репо, чтобы он работал. – Alex