src/Controller/DefaultController.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Pimcore\Model\DataObject\Product;
  4. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Pimcore\Bundle\EcommerceFrameworkBundle\Factory;
  7. use Pimcore\Model\DataObject\Category;
  8. use Pimcore\Controller\FrontendController;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. class DefaultController extends FrontendController
  12. {
  13.     /**
  14.      * @param Request $request
  15.      * @return Response
  16.      */
  17.     public function defaultAction(Request $request): Response
  18.     {
  19.         return $this->render('default/default.html.twig');
  20.     }
  21.     /**
  22.      * @Route("/catalog")
  23.      * @return \Symfony\Component\HttpFoundation\JsonResponse
  24.      */
  25.     public function catalogAction(Request $request) {
  26.         $products = [];        
  27.         $productList Factory::getInstance()->getIndexService()->getProductListForTenant('Catalog');
  28.         // $productList->setCategory(Category::getById(1160));
  29.         // print_r(get_class_methods($productList));
  30.         foreach($productList as $product) {
  31.             $products[] = [
  32.                 'id' => $product->getId(),
  33.                 'name' => $product->getName(),
  34.                 'UPC' => $product->getUPC(),
  35.                 'Model' => $product->getModel(),
  36.                 'Product Number' => $product->getProductNumber(),
  37.                 // 'Short Description' => $product->getShortDescription(),
  38.                 // 'Long Description' => $product->getLongDescription(),
  39.                 // 'Color' => $product->getColor(),
  40.                 // 'Colour' => $product->getColour(),
  41.             ];
  42.         }
  43.         // return $this->json($products);
  44.         return $this->render('default/product_catalog.html.twig',['products'=>$products]);
  45.     }
  46.     
  47. }