src/Controller/ProductCategoryController.php line 54

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Model\ProductCategory;
  4. use Exception;
  5. use Pimcore\Model\Document;
  6. use Pimcore\Model\Document\Page;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  9. class ProductCategoryController extends DefaultFrontendController
  10. {
  11.     /**
  12.      * @Template
  13.      * @param Request $request
  14.      * @return array
  15.      * @throws Exception
  16.      *
  17.      */
  18.     public function singleAction(Request $request): array
  19.     {
  20.         $relatedCategoryObject $this->getDocumentEditable('relation''productCategory')->getElement();
  21.         $this->addAreaBrickData('faq-brick', [
  22.             /** @see Relation::getElement() can also return `false`;  ** SMACK **, bad Pimcore! */
  23.             'faqs' => $relatedCategoryObject $relatedCategoryObject->getFaqs() : null,
  24.             'faqs_source' => "Product Categorie",
  25.         ]);
  26.         $parentPageController $this->document->getParent()->getController();
  27.         return $this->data($request, [
  28.             'layout' => $parentPageController == "App\Controller\ProductCategoryController::singleAction" "sub" :"main",
  29.             'productCategory' => $relatedCategoryObject,
  30.             'childCategoriesObjects' =>$this->getChildCategoriesObjects(),
  31.             'childCategories' => $this->getChildCategories(),
  32.             'childProducts' => $this->getChildProducts(),
  33.             /** @see Relation::getElement() can also return `false`;  ** SMACK **, bad Pimcore! */
  34.             'overrideImage' => $relatedCategoryObject $relatedCategoryObject->getThumbnailImage() : null,
  35.             /** @see Relation::getElement() can also return `false`;  ** SMACK **, bad Pimcore! */
  36.             'productCategoryProperties' => $relatedCategoryObject $relatedCategoryObject?->formatPropertyItems() : null,
  37.         ]);
  38.     }
  39.     /**
  40.      * @Template
  41.      * @param Request $request
  42.      * @return array
  43.      * @throws Exception
  44.      */
  45.     public function archiveAction(Request $request): array
  46.     {
  47.         return $this->data($request);
  48.     }
  49.     private function getChildCategoriesObjects()
  50.     {
  51.         $return = [];
  52.         foreach ($this->document->getChildren() as $childPage) {
  53.             if ("App\Controller\ProductCategoryController::singleAction" == $childPage->getObjectVars()['controller']) {
  54.                 /** @var Page $childDocument */
  55.                 $childDocument Document::getById($childPage->getId());
  56.                 if ($relatedCategoryObject $childDocument->getEditable('productCategory')?->getElement()) {
  57.                     $return[] = $relatedCategoryObject;
  58.                 }
  59.             }
  60.         }
  61.         return $return;
  62.     }
  63.     private function getChildCategories()
  64.     {
  65.         foreach ($this->document->getChildren() as $childPage) {
  66.             if ("App\Controller\ProductCategoryController::singleAction" == $childPage->getObjectVars()['controller']) {
  67.                 $return[] = $childPage;
  68.             }
  69.         }
  70.         return $return ?? false;
  71.     }
  72.     private function getChildProducts()
  73.     {
  74.         foreach ($this->document->getChildren() as $childPage) {
  75.             if ("App\Controller\ProductController::singleAction" == $childPage->getObjectVars()['controller']) {
  76.                 $return[] = $childPage;
  77.             }
  78.         }
  79.         return $return ?? false;
  80.     }
  81. }