2017-12-08 10 views
0

を働いていないスラグによる検索製品:Sylius、私が使用して、スラグによって製品をフィルタ処理しようとしている

$this->get('sylius.repository.product')->findOneBy(array('slug' => $slug)); 

は、私がfindByとfindOneBySlugを使用して試してみたが、それは常に製品が「持っていないことを言いますスラッグ」プロパティ:

Unrecognized field: slug 

または

Entity 'Sylius\Component\Core\Model\Product' has no field 'slug'. You can therefore not call 'findOneBySlug' on the entities' repository 

が、そのウェブサイト上の文書は、それが動作するはずの言葉: http://docs.sylius.org/en/latest/components_and_bundles/bundles/SyliusProductBundle/product.html

$product = $repository->findOneBy(array('slug' => 'my-super-product')); // Get one product by defined criteria. 

答えて

2

slugは、製品の翻訳で提供されていますので、私は、それが動作しないと思います。リポジトリには便利な方法がいくつかあります(例:findOneByChannelAndSlugまたはfindByName)。

/** 
* @param string $name 
* @param string $locale 
* @return array 
*/ 
public function findBySlug(string $slug, string $locale): ?ProductInterface 
{ 
    return $this->createQueryBuilder('o') 
     ->innerJoin('o.translations', 'translation', 'WITH', 'translation.locale = :locale') 
     ->andWhere('translation.slug = :slug') 
     ->setParameter('slug', $slug) 
     ->setParameter('locale', $locale) 
     ->getQuery() 
     ->getOneOrNullResult() 
    ; 
} 
:製品のリポジトリを拡張する際に

また、あなたはそれを自分で構築することができます

関連する問題