forked from SymfonyCasts/symfony-ux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2ndcontroller-refactor-cart-to-partial.diff
168 lines (168 loc) · 6.85 KB
/
2ndcontroller-refactor-cart-to-partial.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
diff --git a/templates/cart/_cartList.html.twig b/templates/cart/_cartList.html.twig
new file mode 100644
index 0000000..5da81fc
--- /dev/null
+++ b/templates/cart/_cartList.html.twig
@@ -0,0 +1,75 @@
+<div>
+ <div class="row p-3">
+ <div class="col-3">
+ Item Name
+ </div>
+ <div class="col-3">
+ Quantity
+ </div>
+ <div class="col-3">
+ Price
+ </div>
+ <div class="col-3"></div>
+ </div>
+ {% for item in cart.items %}
+ <div
+ class="cart-item row p-3"
+ data-action="submit-confirm:async:submitted->cart-list#removeItem"
+ >
+ <div class="col-2">
+ {{ item.product.name }}
+ </div>
+ <div class="col-1">
+ {% if item.color %}
+ <span class="color-square" style="background-color: rgb({{ item.color.red }}, {{ item.color.green }}, {{ item.color.blue }});"></span>
+ {% endif %}
+ </div>
+ <div class="col-3">
+ {{ item.quantity }}
+ </div>
+ <div class="col-3">
+ {{ item.totalString|format_currency('USD') }}
+ </div>
+ <div class="col-3">
+ <form
+ action="{{ path('app_cart_remove_item', {
+ productId: item.product.id,
+ colorId: item.color ? item.color.id: null,
+ }) }}"
+ method="POST"
+ {{ stimulus_controller('submit-confirm', {
+ title: 'Remove this item?',
+ icon: 'warning',
+ confirmButtonText: 'Yes, remove it',
+ submitAsync: true,
+ }) }}
+ data-action="submit-confirm#onSubmit"
+ >
+ <input type="hidden" name="_token" value="{{ csrf_token('remove_item') }}" />
+
+ <button class="btn btn-info btn-sm">
+ Remove
+ </button>
+ </form>
+ </div>
+ </div>
+ {% else %}
+ <div class="col-12">
+ Your cart is empty! Get to shopping!
+ </div>
+ {% endfor %}
+
+ {% if cart.items|length > 0 %}
+ <div class="p-3">
+ Total: <strong>{{ cart.totalString|format_currency('USD') }}</strong>
+ </div>
+ {% endif %}
+</div>
+
+{% if cart.items|length > 0 %}
+<div>
+ <a href="{{ path('app_checkout') }}" class="btn btn-primary">
+ Check Out >>
+ </a>
+</div>
+{% endif %}
diff --git a/templates/cart/cart.html.twig b/templates/cart/cart.html.twig
index 8868958..4822828 100644
--- a/templates/cart/cart.html.twig
+++ b/templates/cart/cart.html.twig
@@ -15,81 +15,7 @@
class="component-light p-3"
{{ stimulus_controller('cart-list') }}
>
- <div>
- <div class="row p-3">
- <div class="col-3">
- Item Name
- </div>
- <div class="col-3">
- Quantity
- </div>
- <div class="col-3">
- Price
- </div>
- <div class="col-3"></div>
- </div>
- {% for item in cart.items %}
- <div
- class="cart-item row p-3"
- data-action="submit-confirm:async:submitted->cart-list#removeItem"
- >
- <div class="col-2">
- {{ item.product.name }}
- </div>
- <div class="col-1">
- {% if item.color %}
- <span class="color-square" style="background-color: rgb({{ item.color.red }}, {{ item.color.green }}, {{ item.color.blue }});"></span>
- {% endif %}
- </div>
- <div class="col-3">
- {{ item.quantity }}
- </div>
- <div class="col-3">
- {{ item.totalString|format_currency('USD') }}
- </div>
- <div class="col-3">
- <form
- action="{{ path('app_cart_remove_item', {
- productId: item.product.id,
- colorId: item.color ? item.color.id: null,
- }) }}"
- method="POST"
- {{ stimulus_controller('submit-confirm', {
- title: 'Remove this item?',
- icon: 'warning',
- confirmButtonText: 'Yes, remove it',
- submitAsync: true,
- }) }}
- data-action="submit-confirm#onSubmit"
- >
- <input type="hidden" name="_token" value="{{ csrf_token('remove_item') }}" />
-
- <button class="btn btn-info btn-sm">
- Remove
- </button>
- </form>
- </div>
- </div>
- {% else %}
- <div class="col-12">
- Your cart is empty! Get to shopping!
- </div>
- {% endfor %}
-
- {% if cart.items|length > 0 %}
- <div class="p-3">
- Total: <strong>{{ cart.totalString|format_currency('USD') }}</strong>
- </div>
- {% endif %}
- </div>
-
- {% if cart.items|length > 0 %}
- <div>
- <a href="{{ path('app_checkout') }}" class="btn btn-primary">
- Check Out >>
- </a>
- </div>
- {% endif %}
+ {{ include('cart/_cartList.html.twig') }}
</div>
</div>
</div>