src/CoreBundle/Controller/ProductController.php line 66

Open in your IDE?
  1. <?php
  2. namespace CoreBundle\Controller;
  3. use CoreBundle\Helper\CoreBundleHelper;
  4. use CoreBundle\Helper\ProductVariants;
  5. use CoreBundle\Model\DefaultProductCategory;
  6. use CoreBundle\Services\ProductPricesHistoryService;
  7. use CoreBundle\Services\ProductService;
  8. use Doctrine\DBAL\DBALException;
  9. use Pimcore\Bundle\EcommerceFrameworkBundle\IndexService\ProductList\ProductListInterface;
  10. use Pimcore\Model\DataObject\AbstractObject;
  11. use Pimcore\Model\DataObject\Folder;
  12. use Pimcore\Model\DataObject\ProductFood;
  13. use Symfony\Component\HttpFoundation\Request;
  14. class ProductController extends AbstractController
  15. {
  16.     /**
  17.      * @var ProductPricesHistoryService
  18.      */
  19.     protected $pricesHistoryService;
  20.     /**
  21.      * @var ProductService
  22.      */
  23.     private $productService;
  24.     /**
  25.      * @param ProductPricesHistoryService $pricesHistoryService
  26.      * @param ProductService $productService
  27.      */
  28.     public function __construct(ProductPricesHistoryService $pricesHistoryServiceProductService $productService)
  29.     {
  30.         $this->pricesHistoryService $pricesHistoryService;
  31.         $this->productService $productService;
  32.     }
  33.     /**
  34.      * @param Request $request
  35.      *
  36.      * @return void
  37.      * @throws DBALException
  38.      */
  39.     public function listByProductCategoryIdAction(Request $request): void
  40.     {
  41.         $productCategory DefaultProductCategory::getProductCategoryById($this->view->document->getProperty("productCategoryId"), $this);
  42.         $products =  CoreBundleHelper::getCoreProductList($this->view->applicationChannel->getPath().$this->view->applicationChannel->getKey());
  43.         $products->setCategory(DefaultProductCategory::getProductCategoryById($productCategory->getId(), $this));
  44.         $products->setVariantMode(ProductListInterface::VARIANT_MODE_HIDE);
  45.         $products->load();
  46.         $refinedProductList $this->productService->prepareProductList($productstrue);
  47.         $productStockInformCustomerData = [];
  48.         $user $this->getUser();
  49.         foreach ($refinedProductList as $product) {
  50.             $productStockInformCustomerData[$product['pimId']] = AbstractController::getProductStockInformCustomerExists($user$product['pimId']);
  51.         }
  52.         $this->view->productStockInformCustomerData $productStockInformCustomerData;
  53.         $this->view->uri $request->getUri();
  54.         $this->view->user $user;
  55.         $this->view->productCategory $productCategory;
  56.         $this->view->products $refinedProductList;
  57.     }
  58.     public function showByArticleNumberAction(Request $request)
  59.     {
  60.         $product CoreBundleHelper::getProductByArticleNumber($request->get("articlenumber"), $this);
  61.         if (!$product) {
  62.             throw $this->createNotFoundException();
  63.         }
  64.         if($request->get("name") != $product->getUrlTitle()){
  65.             return $this->redirectToRoute("shopHandlerProductDetail", ["articlenumber" => $request->get("articlenumber"), "name" => $product->getUrlTitle()]);
  66.         }
  67.         // Get the variants for a given product
  68.         $productVariants = new ProductVariants();
  69.         $productVariants->get($product);
  70.         $showReferencePrice $isProductFood = ($product instanceof ProductFood);
  71.         $this->view->minimumPrice30DaysAllCountries $this->pricesHistoryService->getMinimumPrice($product);
  72.         $this->view->language $request->getLocale();
  73.         $this->view->product $product;
  74.         $this->view->variants $productVariants->variants;
  75.         $this->view->highlightedProductId $productVariants->highlightedProductId;
  76.         $this->view->showReferencePrice $showReferencePrice;
  77.         $this->view->isProductFood $isProductFood;
  78.         // Set SEO title and description if available
  79.         $this->view->seoTitle $product->getSeoTitle() ?? null;
  80.         $this->view->seoDescription $product->getSeoDescription() ?? null;
  81.         $user $this->getUser();
  82.         $this->view->user $user;
  83.         if ($request->get('email')) {
  84.             $this->view->email $request->get('email');
  85.         }
  86.         $this->view->productStockInformCustomerData AbstractController::getProductStockInformCustomerExists($user$product->getId());
  87.         return $this->render('Product/showByArticleNumber.html.twig'$this->view->getAllParameters());
  88.     }
  89.     public function showByArticleIdAction(Request $request)
  90.     {
  91.         $product CoreBundleHelper::getProductById($request->get('articleid'));
  92.         $variants       null;
  93.         $parentObject   $product->getParent();
  94.         if($parentObject instanceof Folder){
  95.             $variants   $product->getChildren([AbstractObject::OBJECT_TYPE_VARIANT]);
  96.             $variants[] = $product;
  97.         }else{
  98.             $variants   $parentObject->getChildren([AbstractObject::OBJECT_TYPE_VARIANT]);
  99.             $variants[] = $parentObject;
  100.         }
  101.         $showReferencePrice = ($product instanceof ProductFood);
  102.         $this->cleanVariants($variants$product);
  103.         $this->sortVariants($variants);
  104.         $this->view->minimumPrice30DaysAllCountries $this->pricesHistoryService->getMinimumPrice($product);
  105.         $this->view->language $request->get("language");
  106.         $this->view->product $product;
  107.         $this->view->variants $variants;
  108.         $this->view->showReferencePrice $showReferencePrice;
  109.     }
  110. }