getCategory example



    public function load(Request $request, SalesChannelContext $context): NavigationPage
    {
        $page = $this->genericLoader->load($request$context);
        $page = NavigationPage::createFrom($page);

        $navigationId = $request->get('navigationId', $context->getSalesChannel()->getNavigationCategoryId());

        $category = $this->cmsPageRoute
            ->load($navigationId$request$context)
            ->getCategory();

        if (!$category->getActive()) {
            throw new CategoryNotFoundException($category->getId());
        }

        $this->loadMetaData($category$page$context->getSalesChannel());
        $page->setNavigationId($category->getId());

        if ($category->getCmsPage()) {
            $page->setCmsPage($category->getCmsPage());
        }

        
class BlockTest extends TestCase
{
    public function testFromXml(): void
    {
        $cmsExtensions = CmsExtensions::createFromXmlFile(__DIR__ . '/../_fixtures/valid/cmsExtensionsWithBlocks.xml');
        static::assertNotNull($cmsExtensions->getBlocks());

        static::assertCount(2, $cmsExtensions->getBlocks()->getBlocks());

        $firstBlock = $cmsExtensions->getBlocks()->getBlocks()[0];
        static::assertEquals('first-block-name', $firstBlock->getName());
        static::assertEquals('text-image', $firstBlock->getCategory());
        static::assertCount(3, $firstBlock->getSlots());
        static::assertCount(6, $firstBlock->getDefaultConfig()->toArray('en-GB'));
        static::assertEquals(
            [
                'en-GB' => 'First block from app',
                'de-DE' => 'Erster Block einer App',
            ],
            $firstBlock->getLabel()
        );
    }

    
/** * Listing of all manufacturer products. * Templates extends from the normal listing template. * * @return void */
    public function manufacturerAction(ShopContextInterface $context)
    {
        $manufacturerId = $this->Request()->getParam('sSupplier');

        if (!$this->Request()->getParam('sCategory')) {
            $categoryId = $context->getShop()->getCategory()->getId();

            $this->Request()->setParam('sCategory', $categoryId);

            $sortings = $this->customSortingService->getSortingsOfCategories([$categoryId]$context);

            $sortings = array_shift($sortings);

            $this->setDefaultSorting($sortings);

            $this->view->assign('sortings', $sortings);
        }

        
/** * Navigation id is required to load the slot config for the navigation */
    #[Route(path: '/widgets/cms/navigation/{navigationId}', name: 'frontend.cms.navigation.page', defaults: ['navigationId' => null, 'XmlHttpRequest' => true], methods: ['GET', 'POST'])]     public function category(?string $navigationId, Request $request, SalesChannelContext $salesChannelContext): Response
    {
        if (!$navigationId) {
            throw RoutingException::missingRequestParameter('navigationId');
        }

        $category = $this->categoryRoute->load($navigationId$request$salesChannelContext)->getCategory();

        $page = $category->getCmsPage();
        if (!$page) {
            throw new PageNotFoundException('');
        }

        $this->hook(new CmsPageLoadedHook($page$salesChannelContext));

        $response = $this->renderStorefront('@Storefront/storefront/page/content/detail.html.twig', ['cmsPage' => $page]);
        $response->headers->set('x-robots-tag', 'noindex');

        
ShopContextInterface $context
    ): ?TreeFacetResult {
        $ids = $this->fetchCategoriesOfProducts($reverted$context);

        if (empty($ids)) {
            return null;
        }

        $ids = $this->filterSystemCategories($ids$context);

        $ids = $this->categoryDepthService->get(
            $context->getShop()->getCategory(),
            $facet->getDepth(),
            $ids
        );

        $categories = $this->categoryService->getList($ids$context);

        return $this->categoryTreeFacetResultBuilder->buildFacetResult(
            $categories,
            $this->getFilteredIds($criteria),
            $context->getShop()->getCategory()->getId(),
            $facet
        );
SQL;

        $stmt = $this->connection->executeQuery(
            $sql,
            [
                'ids' => $ids,
                'sessionId' => $this->session->get('sessionId'),
                'mainCategoryId' => $this->contextService->getContext()->getShop()->getCategory()->getId(),
            ],
            [
                'ids' => Connection::PARAM_INT_ARRAY,
                'sessionId' => \PDO::PARAM_STR,
                'mainCategoryId' => \PDO::PARAM_INT,
            ]
        );

        $additionalInformation = $stmt->fetchAll(\PDO::FETCH_GROUP | \PDO::FETCH_UNIQUE);
        $products = Shopware()->Container()->get(ListProductGatewayInterface::class)->getList(
            array_column($additionalInformation, 'ordernumber'),
            
$this->route = $route;
        /** @var Shop $shop */
        $shop = $container->get('shop');
        $this->shop = $shop;
    }

    /** * {@inheritdoc} */
    public function getInvalidationDate(Request $request)
    {
        $categoryId = (int) $this->shop->getCategory()->getId();
        $emotions = $this->getNextDateQuery($categoryId)->execute()->fetchAll();
        $dates = array_filter(
            array_merge(
                array_column($emotions, 'valid_from'),
                array_column($emotions, 'valid_to')
            )
        );

        return $this->getMostRecentDate($dates);
    }

    
$event = new CategoryRouteCacheTagsEvent($navigationId$tags$request$response$context, null);
        $this->dispatcher->dispatch($event);

        return array_unique(array_filter($event->getTags()));
    }

    /** * @return array<string> */
    private function extractProductIds(CategoryRouteResponse $response): array
    {
        $page = $response->getCategory()->getCmsPage();

        if ($page === null) {
            return [];
        }

        $ids = [];
        $streamIds = [];

        $slots = $page->getElementsOfType('product-slider');
        /** @var CmsSlotEntity $slot */
        foreach ($slots as $slot) {
            
$this->template->registerPlugin(
                Smarty::PLUGIN_FUNCTION,
                'createSupplierPath',
                [$this, 'createSupplierPath']
            );
        }

        $this->data = $this->template->createData();

        $this->data->assign('sConfig', $this->config);
        $this->data->assign('sRouter', $this);
        $this->data->assign('sCategoryStart', Shopware()->Shop()->getCategory()->getId());
    }

    /** * Main method for re-creating the rewrite table. Triggers all other (more specific) methods * * @param string $lastUpdate * * @throws SmartyException * @throws \Enlight_Event_Exception * @throws Zend_Db_Adapter_Exception * @throws Exception * * @return string */
class CategoryUrlProvider extends BaseUrlProvider
{
    /** * {@inheritdoc} */
    public function getUrls(Context $routingContext, ShopContextInterface $shopContext)
    {
        if ($this->allExported) {
            return [];
        }

        $parentId = $shopContext->getShop()->getCategory()->getId();
        $categoryRepository = $this->modelManager->getRepository(Category::class);
        $categories = $categoryRepository->getActiveChildrenList($parentId$shopContext->getFallbackCustomerGroup()->getId(), null, $shopContext->getShop()->getId());

        foreach ($categories as $key => &$category) {
            if (!empty($category['external'])) {
                unset($categories[$key]);
                continue;
            }

            $category['urlParams'] = [
                'sViewport' => 'cat',
                
$cacheIds[] = 'a' . $article['articleID'];
        }

        return $cacheIds;
    }

    /** * @return array */
    private function getHomePageCacheIds(ShopContextInterface $context)
    {
        $categoryId = (int) $context->getShop()->getCategory()->getId();

        return ['c' . $categoryId];
    }

    /** * @return array */
    private function getRecommendationCacheIds(View $view)
    {
        $cacheIds = [];
        $article = $view->getAssign('sArticle');

        
$struct = new self();
        $struct->setId($shop->getId());
        $struct->setParentId($shop->getMain() ? $shop->getMain()->getId() : $shop->getId());

        $struct->setCustomerScope($shop->getMain() ? $shop->getMain()->getCustomerScope() : $shop->getCustomerScope());
        $struct->setIsDefault($shop->getDefault());
        $struct->setName($shop->getName());
        $struct->setHost($shop->getHost());
        $struct->setPath($shop->getBasePath());
        $struct->setUrl($shop->getBaseUrl());
        $struct->setSecure($shop->getSecure());
        if ($shop->getCategory()) {
            $struct->setCategory(
                Category::createFromCategoryEntity($shop->getCategory())
            );
        }

        if ($shop->getFallback()) {
            $struct->setFallbackId(
                $shop->getFallback()->getId()
            );
        }

        
return false;
        }

        if ($this->config->get('hideNoInStock') && !$product->isAvailable() && !$product->hasAvailableVariant()) {
            return false;
        }

        $ids = array_map(function DCategory $category) {
            return $category->getId();
        }$product->getCategories());

        return \in_array($context->getShop()->getCategory()->getId()$ids);
    }

    private function allowBuyInListing(ListProduct $product): bool
    {
        return !$product->hasConfigurator()
            && $product->isAvailable()
            && $product->getUnit()
            && $product->getUnit()->getMinPurchase() <= 1
            && !$product->displayFromPrice();
    }

    
'link' => $link,
        ];
    }

    /** * Gets all suppliers that have products for the current shop * * @throws Exception */
    private function getSupplierForSitemap(): array
    {
        $categoryId = $this->get(ContextServiceInterface::class)->getShopContext()->getShop()->getCategory()->getId();

        return $this->get(Connection::class)->createQueryBuilder()
            ->select(['manufacturer.id', 'manufacturer.name'])
            ->from('s_articles_supplier', 'manufacturer')
            ->innerJoin('manufacturer', 's_articles', 'product', 'product.supplierID = manufacturer.id')
            ->innerJoin('product', 's_articles_categories_ro', 'categories', 'categories.articleID = product.id AND categories.categoryID = :categoryId')
            ->setParameter(':categoryId', $categoryId)
            ->groupBy('manufacturer.id')
            ->execute()
            ->fetchAllAssociative();
    }
}

        $this->allExported = false;
    }

    /** * Gets all suppliers that have products for the current shop * * @return array<array<string, mixed>> */
    private function getManufacturersForSitemap(ShopContextInterface $shopContext): array
    {
        $categoryId = $shopContext->getShop()->getCategory()->getId();

        return $this->connection->createQueryBuilder()
            ->select(['manufacturer.id', 'manufacturer.name', 'manufacturer.changed'])
            ->from('s_articles_supplier', 'manufacturer')
            ->innerJoin('manufacturer', 's_articles', 'product', 'product.supplierID = manufacturer.id')
            ->innerJoin('product', 's_articles_categories_ro', 'categories', 'categories.articleID = product.id AND categories.categoryID = :categoryId')
            ->setParameter(':categoryId', $categoryId)
            ->groupBy('manufacturer.id')
            ->execute()
            ->fetchAll(PDO::FETCH_ASSOC);
    }
}
Home | Imprint | This part of the site doesn't use cookies.