forked from SymfonyCasts/symfony-ux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlazysidebar-sidebar-controller.diff
42 lines (40 loc) · 1.66 KB
/
lazysidebar-sidebar-controller.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
diff --git a/src/Controller/CartController.php b/src/Controller/CartController.php
index e6bdba1..9096277 100644
--- a/src/Controller/CartController.php
+++ b/src/Controller/CartController.php
@@ -30,6 +30,20 @@ class CartController extends AbstractController
return $this->renderForm('cart/cart.html.twig', [
'cart' => $cartStorage->getOrCreateCart(),
+ ]);
+ }
+
+ /**
+ * @Route("/cart/_featured", name="_app_cart_product_featured")
+ */
+ public function _cartFeaturedProduct(ProductRepository $productRepository): Response
+ {
+ $featuredProduct = $productRepository->findFeatured();
+ $addToCartForm = $this->createForm(AddItemToCartFormType::class, null, [
+ 'product' => $featuredProduct,
+ ]);
+
+ return $this->renderForm('cart/_featuredSidebar.html.twig', [
'featuredProduct' => $featuredProduct,
'addToCartForm' => $addToCartForm,
]);
diff --git a/templates/cart/cart.html.twig b/templates/cart/cart.html.twig
index a2e9ced..41545d0 100644
--- a/templates/cart/cart.html.twig
+++ b/templates/cart/cart.html.twig
@@ -9,9 +9,9 @@
<div class="container-fluid container-xl mt-4">
<div class="row">
<aside class="col-12 col-md-4 order-2 order-md-1">
- {% if featuredProduct %}
- {{ include('cart/_featuredSidebar.html.twig') }}
- {% endif %}
+ <turbo-frame id="cart-sidebar" src="{{ path('_app_cart_product_featured') }}">
+ Loading...
+ </turbo-frame>
</aside>
<div class="col-12 col-md-8 order-1 order-md-2 cart">