src/Frontend/Modules/Commerce/Actions/Index.php
/**
     * Parse products overview in a category.
     */
Parse products overview in a category.
Parse products overview in a category .
private function parseCategory(Category $category): void
    {
        $currentPage = $this->url->getParameter(Language::lbl('Page'), 'int', 1);
        $itemsPerPage = $this->get('fork.settings')->get('Commerce', 'overview_num_items', 10);
        $filtersShowMoreCount = $this->get('fork.settings')->get('Commerce', 'filters_show_more_num_items', 5);
        $productRepository = $this->getProductRepository();
        $specificationRepository = $this->getSpecificationRepository();
        $productOffset = ($currentPage - 1) * $itemsPerPage;
        $baseUrl = '/' . implode('/', array_merge($this->url->getPages(), $this->url->getParameters(false)));
        $this->loadTemplate('Commerce/Layout/Templates/Category.html.twig');
        if ($category->getParent()) {
            $this->categoryPageTitles($category->getParent());
        }
        $this->setMeta($category->getMeta());
        $this->addCSS('Commerce.css');
        $this->addJSData('filterUrl', $baseUrl);
        $this->addJSData('category', $category->getId());
        $this->categoryToBreadcrumb($category);
        $sortOrders = ProductSorting::getAll();
        $currentSortOrder = $this->getRequest()->get('sort', Product::SORT_STANDARD);
        if (array_key_exists($currentSortOrder, $sortOrders)) {
            $sortOrders[$currentSortOrder]['selected'] = true;
        }
        $filters = $specificationRepository->findFiltersByCategory($category);
        if ($productFilters = $this->getProductFilters()) {
            $products = $productRepository->filterProducts(
                $productFilters,
                $category,
                $itemsPerPage,
                $productOffset,
                $currentSortOrder
            );
            $itemCount = $productRepository->filterProductsCount($productFilters, $category);
            $this->pagination = $this->buildPaginationConfig($itemCount);
        } else {
            $products = $productRepository->findLimitedByCategory(
                $category,
                $itemsPerPage,
                $productOffset,
                $currentSortOrder
            );
            $itemCount = $category->getActiveProducts()->count();
            $this->pagination = $this->buildPaginationConfig($itemCount);
        }
        $this->template->assign('categories', $this->getCategoryRepository()->findParents(Locale::frontendLanguage()));
        $this->template->assign('category', $category);
        $this->template->assign('products', $products);
        $this->template->assign('filters', $filters);
        $this->template->assign('sortOrders', $sortOrders);
        $this->template->assign('filtersShowMoreCount', $filtersShowMoreCount);
        $this->parsePagination();
    }
private function parseCategory ( Category $ category ) : void { $ currentPage = $ this -> url -> getParameter ( Language :: lbl ( 'Page' ) , 'int' , 1 ) ; $ itemsPerPage = $ this -> get ( 'fork.settings' ) -> get ( 'Commerce' , 'overview_num_items' , 10 ) ; $ filtersShowMoreCount = $ this -> get ( 'fork.settings' ) -> get ( 'Commerce' , 'filters_show_more_num_items' , 5 ) ; $ productRepository = $ this -> getProductRepository ( ) ; $ specificationRepository = $ this -> getSpecificationRepository ( ) ; $ productOffset = ( $ currentPage - 1 ) * $ itemsPerPage ; $ baseUrl = '/' . implode ( '/' , array_merge ( $ this -> url -> getPages ( ) , $ this -> url -> getParameters ( false ) ) ) ; $ this -> loadTemplate ( 'Commerce/Layout/Templates/Category.html.twig' ) ; if ( $ category -> getParent ( ) ) { $ this -> categoryPageTitles ( $ category -> getParent ( ) ) ; } $ this -> setMeta ( $ category -> getMeta ( ) ) ; $ this -> addCSS ( 'Commerce.css' ) ; $ this -> addJSData ( 'filterUrl' , $ baseUrl ) ; $ this -> addJSData ( 'category' , $ category -> getId ( ) ) ; $ this -> categoryToBreadcrumb ( $ category ) ; $ sortOrders = ProductSorting :: getAll ( ) ; $ currentSortOrder = $ this -> getRequest ( ) -> get ( 'sort' , Product :: SORT_STANDARD ) ; if ( array_key_exists ( $ currentSortOrder , $ sortOrders ) ) { $ sortOrders [ $ currentSortOrder ] [ 'selected' ] = true ; } $ filters = $ specificationRepository -> findFiltersByCategory ( $ category ) ; if ( $ productFilters = $ this -> getProductFilters ( ) ) { $ products = $ productRepository -> filterProducts ( $ productFilters , $ category , $ itemsPerPage , $ productOffset , $ currentSortOrder ) ; $ itemCount = $ productRepository -> filterProductsCount ( $ productFilters , $ category ) ; $ this -> pagination = $ this -> buildPaginationConfig ( $ itemCount ) ; } else { $ products = $ productRepository -> findLimitedByCategory ( $ category , $ itemsPerPage , $ productOffset , $ currentSortOrder ) ; $ itemCount = $ category -> getActiveProducts ( ) -> count ( ) ; $ this -> pagination = $ this -> buildPaginationConfig ( $ itemCount ) ; } $ this -> template -> assign ( 'categories' , $ this -> getCategoryRepository ( ) -> findParents ( Locale :: frontendLanguage ( ) ) ) ; $ this -> template -> assign ( 'category' , $ category ) ; $ this -> template -> assign ( 'products' , $ products ) ; $ this -> template -> assign ( 'filters' , $ filters ) ; $ this -> template -> assign ( 'sortOrders' , $ sortOrders ) ; $ this -> template -> assign ( 'filtersShowMoreCount' , $ filtersShowMoreCount ) ; $ this -> parsePagination ( ) ; }
Parse products overview in a category.
Parse products overview in a category .
// Set some default variables // Set page defaults // add css // Add JS // Add categories to breadcrumbs // Define the sort orders // Get the filters for current category // Fetch the products // Assign to our template