如何从Shopware 6中的类别实体获取类别URL?

问题描述 投票:0回答:1

我正在从类别存储库中获取一些类别,并希望将来获得其URL进行链接。

$categoryRepository = $this->container->get('sales_channel.category.repository')->search($criteria, $event->getSalesChannelContext())->getElements();

是否有一些吸气剂方法可以帮助我达到该结果?

这是实体:

Shopware\Core\Content\Category\CategoryEntity
symfony e-commerce backend shopware
1个回答
1
投票

如果将相应的关联添加到$criteria,则可以通过$categoryEntity->getSeoUrls()获得Urls。这将返回一个SeoUrlCollection,您可以在其中执行getPathInfo()getSeoPathInfo()

foreach ($categoryRepository as $catEntity) {
    foreach ($catEntity->getSeoUrls()->getElements() as $seoUrlEntity) {
        $seoUrlEntity->getPathInfo();
        $seoUrlEntity->getSeoPathInfo();
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.