我要嵌入的產品列表到視圖中的文檔中描述: http://docs.sylius.org/en/latest/cookbook/embedding-products.html(參見:http://docs.sylius.org/en/latest/customization/repository.html)Sylius:不能夠嵌入產品列表進入查看/自定義庫
我複製&主要是從上面的頁面粘貼代碼片段。我生成的文件src/AppBundle/Repository/ProductRepository.php
從文檔代碼:
<?php
namespace AppBundle\Repository;
use Sylius\Bundle\CoreBundle\Doctrine\ORM\ProductRepository as BaseProductRepository;
use Sylius\Component\Core\Model\ChannelInterface;
class ProductRepository extends BaseProductRepository
{
/**
* {@inheritdoc}
*/
public function findLatestByChannelAndTaxonCode(ChannelInterface $channel, $code, $count)
{
return $this->createQueryBuilder('o')
->innerJoin('o.channels', 'channel')
->addOrderBy('o.createdAt', 'desc')
->andWhere('o.enabled = true')
->andWhere('channel = :channel')
->innerJoin('o.taxons', 'taxon')
->andWhere('taxon.code = :code')
->setParameter('channel', $channel)
->setParameter('code', $code)
->setMaxResults($count)
->getQuery()
->getResult()
;
}
}
然後我註冊它app/config/config.yml
(再次1:1個複製&粘貼):
sylius_product:
resources:
product:
classes:
repository: AppBundle\Repository\ProductRepository
我在app/config/routing.yml
配置的路由( 1:1複製&粘貼)。
app_shop_partial_product_index_latest_by_taxon_code:
path: /latest/{code}/{count} # configure a new path that has all the needed variables
methods: [GET]
defaults:
_controller: sylius.controller.product:indexAction # you make a call on the Product Controller's index action
_sylius:
template: $template
repository:
method: findLatestByChannelAndTaxonCode # here use the new repository method
arguments:
- "expr:service('sylius.context.channel').getChannel()"
- $code
- $count
然後,我希望它在我的index.html.twig渲染:
<h2 class="ui horizontal section divider header">My custom title</h2>
{{ render(url('app_shop_partial_product_index_latest_by_taxon_code', {'code': 'mugs', 'count': 4, 'template': '@SyliusShop/Product/_horizontalList.html.twig'})) }}
標題是可見的,我使用的樣本數據,所以有一個現有的類羣與代碼「杯子。但沒有可見的產品列表。
我跳過文檔中的內容嗎?我是Symfony的新手,所以也許我忘了一些明顯的東西?我怎樣才能自己調試呢?
編輯:的文檔的當前版本已經過時,看到https://github.com/Sylius/Sylius/issues/8212