<?phpnamespace App\Controller;use Pimcore\Model\DataObject\Category;use Pimcore\Model\DataObject\Product;use Pimcore\Model\Document;use App\Classes\Controller\AbstractFrontController as AbstractFrontController;use App\Classes\DataMapper\Customer\Address\AddressDataMapper;use App\Classes\DataMapper\Product\ProductCardDataMapper;use App\Classes\DataMapper\Product\ProductDataMapper;use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;use Symfony\Component\HttpFoundation\Request;class ProductController extends AbstractFrontController{ #[Template()] public function showAction(Request $request) { $product = Product::getById($request->get('id')); $documentCategory = null; if (!$product || !$product->isPublished()) { // error page throw new \Exception('Product not found!'); } if ($product->getProductType() != 'grouped') { throw new \Exception('Product not found!'); } $mapperProduct = (new ProductDataMapper($product))->toArray($request); $this->view->product = $mapperProduct; $this->view->variants = ProductDataMapper::list($product->getProducts())->toArray($request); $this->view->relatedProducts = ProductCardDataMapper::list($product->getRelatedProducts())->all($request); $this->view->purchasedTogether = ProductCardDataMapper::list($product->getPurchasedTogether())->all($request); $this->view->replacementParts = ProductCardDataMapper::list($product->getReplacementParts())->all($request); $isEU = false; if ($this->getUser()) { $defaultBillingAddress = $this->getUser()->getDefaultBillingAddressObject(); $addresses = (new AddressDataMapper($defaultBillingAddress))->toArray($request); $isEU = $addresses['isEU']; if (!$isEU) { $defaultShippingAddress = $this->getUser()->getDefaultShippingAddressObject(); $addresses = (new AddressDataMapper($defaultShippingAddress))->toArray($request); $isEU = $addresses['isEU']; } } $this->view->isEU = $isEU; $category = $mapperProduct['category']; if ($categoryId = $request->get('navigated_from_object')) { foreach($product->getCategories() as $_category) { if ($_category->getId() != $categoryId) { continue; } $category = $_category; } } if ($category && $category->getCategoryName() != 'Root category') { // get breadcrumbs $db = \Pimcore\Db::get(); $categoryDocumentIds = $db->fetchAll('SELECT cid FROM properties WHERE name = "category" AND data = "' . $category->getId() . '"'); if ($categoryDocumentIds) { foreach ($categoryDocumentIds as $categoryDocumentId) { $document = Document::getById($categoryDocumentId['cid']); if ($document && $document->getProperty('products_filter')){ $documentCategory = $document->getProperty('products_filter')->getParent(); if ($documentCategory->getId() == $category->getId()){ break; } } } $breadcrumbs['category'] = [ 'name' => $category->getCategoryName(), 'href' => $document ? $document->getHref() : '' ]; } $parentCategory = $documentCategory?->getParent(); if ($parentCategory instanceof Category) { $parentDocument = $document->getParent(); if ($parentDocument) { $breadcrumbs['parentCategory'] = [ 'name' => $parentCategory->getCategoryName(), 'href' => $parentDocument ? $parentDocument->getHref() : '' ]; } } $this->view->breadcrumbs = $breadcrumbs ?? []; //get division document (for header, foooter) while ($category->getParent()->getCategoryName() != 'Root category') { $category = $category->getParent(); if (!$category instanceof Category) { break; } } $db = \Pimcore\Db::get(); $rootDocumentId = $db->fetchOne('SELECT cid FROM properties WHERE name = "category" AND data = "' . $category->getId() . '"'); if ($rootDocumentId) { $rootDocument = Document::getById($rootDocumentId); $request->request->set('division', $rootDocumentId); $this->view->document = $rootDocument; $this->view->division = $rootDocument->getKey(); } } } protected function getProductGroup($product) { return $product; }}