|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace App\Controller;
|
|
namespace App\Controller;
|
|
|
|
|
|
|
|
+use App\Entity\Category;
|
|
use App\Entity\Product;
|
|
use App\Entity\Product;
|
|
use App\Repository\ProductRepository;
|
|
use App\Repository\ProductRepository;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
@@ -19,7 +20,7 @@ class ProductController extends Controller
|
|
* path = "/product"
|
|
* path = "/product"
|
|
* )
|
|
* )
|
|
*
|
|
*
|
|
- * @param \Doctrine\ORM\EntityManagerInterface $em
|
|
+ * @param \App\Repository\ProductRepository $repository
|
|
*
|
|
*
|
|
* @return \Symfony\Component\HttpFoundation\Response
|
|
* @return \Symfony\Component\HttpFoundation\Response
|
|
*/
|
|
*/
|
|
@@ -31,12 +32,16 @@ class ProductController extends Controller
|
|
$productsSQL = $repository->findProductsLessThanSQL($priceLimit);
|
|
$productsSQL = $repository->findProductsLessThanSQL($priceLimit);
|
|
|
|
|
|
|
|
|
|
- assert($productsDQL === $productsQB);
|
|
+ $dql_qb = ($productsDQL === $productsQB);
|
|
|
|
|
|
-
|
|
+
|
|
- assert($productsDQL == $productsSQL);
|
|
+ $dql_sql = ($productsDQL == $productsSQL);
|
|
|
|
|
|
- return $this->render('product/index.html.twig', ['products' => $productsQB]);
|
|
+ return $this->render('product/index.html.twig', [
|
|
|
|
+ 'products' => $productsQB,
|
|
|
|
+ 'dql_qb' => $dql_qb,
|
|
|
|
+ 'dql_sql' => $dql_sql,
|
|
|
|
+ ]);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -54,11 +59,17 @@ class ProductController extends Controller
|
|
->setPrice(19.99)
|
|
->setPrice(19.99)
|
|
->setDescription('Ergonomic and stylish!');
|
|
->setDescription('Ergonomic and stylish!');
|
|
|
|
|
|
|
|
+ $cat = $em->getRepository(Category::class)->findOneBy([
|
|
|
|
+ 'name' => CategoryController::DEVICES,
|
|
|
|
+ ]);
|
|
|
|
+ $product->setCategory($cat);
|
|
|
|
+
|
|
|
|
|
|
$em->persist($product);
|
|
$em->persist($product);
|
|
|
|
|
|
|
|
|
|
$em->flush();
|
|
$em->flush();
|
|
|
|
+ $products = $cat->getProducts();
|
|
|
|
|
|
return new Response('Saved new product with id ' . $product->getId(),
|
|
return new Response('Saved new product with id ' . $product->getId(),
|
|
Response::HTTP_CREATED);
|
|
Response::HTTP_CREATED);
|