feat: cart

This commit is contained in:
2024-11-27 17:07:03 +01:00
parent f1b25b1fdf
commit fa1d904db5
15 changed files with 448 additions and 109 deletions
+39 -53
View File
@@ -46,58 +46,38 @@
{% include 'components/theme-switch.html' %}
<!-- Show/Hide cart -->
<button hx-on:click="htmx.toggleClass(htmx.find('#myCartDropdown1'), 'hidden'); htmx.addClass(htmx.find('#userDropdown1'), 'hidden')"
id="myCartDropdownButton1"
data-dropdown-toggle="myCartDropdown1" type="button"
class="inline-flex items-center rounded-lg justify-center p-2 hover:bg-gray-100 dark:hover:bg-gray-700 text-sm font-medium leading-none text-gray-900 dark:text-white">
<span class="sr-only">
{% translate 'Carrito' %}
</span>
<svg class="w-5 h-5 lg:me-1" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24"
fill="none" viewBox="0 0 24 24">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M5 4h1.5L9 16m0 0h8m-8 0a2 2 0 1 0 0 4 2 2 0 0 0 0-4Zm8 0a2 2 0 1 0 0 4 2 2 0 0 0 0-4Zm-8.5-3h9.25L19 7H7.312"/>
</svg>
<span class="sm:flex">{% translate 'Carrito' %}</span>
<svg class="hidden sm:flex w-4 h-4 text-gray-900 dark:text-white ms-1" aria-hidden="true"
xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="m19 9-7 7-7-7"/>
</svg>
</button>
<!-- Cart -->
<div id="myCartDropdown1"
class="absolute top-10 hidden z-10 mx-auto max-w-sm space-y-4 overflow-hidden rounded-lg bg-white p-4 antialiased shadow-lg dark:bg-gray-800">
{% include 'components/cart/cart_dropdown.html' %}
</div>
<div id="navbar-cart-dropdown" hx-get="{% url 'web:cart_dropdown' %}" hx-trigger="load"></div>
{% if request.user.is_authenticated %}
<!-- Show/Hide user account dropdown -->
<button hx-on:click="htmx.toggleClass(htmx.find('#userDropdown1'), 'hidden'); htmx.addClass(htmx.find('#myCartDropdown1'), 'hidden')"
id="userDropdownButton1"
data-dropdown-toggle="userDropdown1" type="button"
class="inline-flex items-center rounded-lg justify-center p-2 hover:bg-gray-100 dark:hover:bg-gray-700 text-sm font-medium leading-none text-gray-900 dark:text-white">
<svg class="w-5 h-5 me-1" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24"
fill="none" viewBox="0 0 24 24">
<path stroke="currentColor" stroke-width="2"
d="M7 17v1a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1v-1a3 3 0 0 0-3-3h-4a3 3 0 0 0-3 3Zm8-9a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z"/>
</svg>
<!-- Show/Hide user account dropdown -->
<button
hx-on:click="htmx.toggleClass(htmx.find('#userDropdown1'), 'hidden'); htmx.addClass(htmx.find('#myCartDropdown1'), 'hidden')"
id="userDropdownButton1"
data-dropdown-toggle="userDropdown1" type="button"
class="inline-flex items-center rounded-lg justify-center p-2 hover:bg-gray-100 dark:hover:bg-gray-700 text-sm font-medium leading-none text-gray-900 dark:text-white">
<svg class="w-5 h-5 me-1" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24"
fill="none" viewBox="0 0 24 24">
<path stroke="currentColor" stroke-width="2"
d="M7 17v1a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1v-1a3 3 0 0 0-3-3h-4a3 3 0 0 0-3 3Zm8-9a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z"/>
</svg>
{% translate 'Mi cuenta' %}
<svg class="w-4 h-4 text-gray-900 dark:text-white ms-1" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"
width="24" height="24" fill="none" viewBox="0 0 24 24">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="m19 9-7 7-7-7"/>
</svg>
</button>
<svg class="w-4 h-4 text-gray-900 dark:text-white ms-1" aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
width="24" height="24" fill="none" viewBox="0 0 24 24">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="m19 9-7 7-7-7"/>
</svg>
</button>
<!-- User account dropdown -->
<div id="userDropdown1"
class="absolute top-10 hidden z-10 w-56 divide-y divide-gray-100 overflow-hidden overflow-y-auto rounded-lg bg-white antialiased shadow dark:divide-gray-600 dark:bg-gray-700 right-0">
{% include 'components/users/user_dropdown.html' %}
</div>
<!-- User account dropdown -->
<div id="userDropdown1"
class="absolute top-10 hidden z-10 w-56 divide-y divide-gray-100 overflow-hidden overflow-y-auto rounded-lg bg-white antialiased shadow dark:divide-gray-600 dark:bg-gray-700 right-0">
{% include 'components/users/user_dropdown.html' %}
</div>
{% else %}
<a href="{% url 'users:login' %}" class="inline-flex items-center rounded-lg justify-center p-2 hover:bg-gray-100 dark:hover:bg-gray-700 text-sm font-medium leading-none text-gray-900 dark:text-white">Inicia sesión</a>
<a href="{% url 'users:login' %}"
class="inline-flex items-center rounded-lg justify-center p-2 hover:bg-gray-100 dark:hover:bg-gray-700 text-sm font-medium leading-none text-gray-900 dark:text-white">Inicia
sesión</a>
{% endif %}
<!-- Show/Hide menu items -->
<button hx-on:click="htmx.toggleClass(htmx.find('#ecommerce-navbar-menu-1'), 'hidden')" type="button"
@@ -119,22 +99,28 @@
class="bg-gray-50 dark:bg-gray-700 dark:border-gray-600 border border-gray-200 rounded-lg py-3 hidden px-4 mt-4">
<ul class="text-gray-900 dark:text-white text-sm font-medium dark:text-white space-y-3">
<li>
<a href="{% url 'web:index' %}" class="hover:text-primary-700 dark:hover:text-primary-500">{% translate 'Inicio' %}</a>
<a href="{% url 'web:index' %}"
class="hover:text-primary-700 dark:hover:text-primary-500">{% translate 'Inicio' %}</a>
</li>
<li>
<a href="{% url 'web:index' %}" class="hover:text-primary-700 dark:hover:text-primary-500">{% translate 'Más vendidos' %}</a>
<a href="{% url 'web:index' %}"
class="hover:text-primary-700 dark:hover:text-primary-500">{% translate 'Más vendidos' %}</a>
</li>
<li>
<a href="{% url 'web:index' %}" class="hover:text-primary-700 dark:hover:text-primary-500">{% translate 'Ideas de regalo' %}</a>
<a href="{% url 'web:index' %}"
class="hover:text-primary-700 dark:hover:text-primary-500">{% translate 'Ideas de regalo' %}</a>
</li>
<li>
<a href="{% url 'web:index' %}" class="hover:text-primary-700 dark:hover:text-primary-500">{% translate 'Juegos' %}</a>
<a href="{% url 'web:index' %}"
class="hover:text-primary-700 dark:hover:text-primary-500">{% translate 'Juegos' %}</a>
</li>
<li>
<a href="{% url 'web:index' %}" class="hover:text-primary-700 dark:hover:text-primary-500">{% translate 'Electrónica' %}</a>
<a href="{% url 'web:index' %}"
class="hover:text-primary-700 dark:hover:text-primary-500">{% translate 'Electrónica' %}</a>
</li>
<li>
<a href="{% url 'web:index' %}" class="hover:text-primary-700 dark:hover:text-primary-500">{% translate 'Ofertas del día' %}</a>
<a href="{% url 'web:index' %}"
class="hover:text-primary-700 dark:hover:text-primary-500">{% translate 'Ofertas del día' %}</a>
</li>
</ul>
</div>