Add alternative image when hovering over product

This commit is contained in:
Nathan Chapman 2022-04-20 19:56:49 -06:00
parent 3ee5fa61b1
commit 72e4ab8cda
19 changed files with 64 additions and 22 deletions

View File

@ -62,6 +62,15 @@ class Product(models.Model):
def get_absolute_url(self): def get_absolute_url(self):
return reverse('dashboard:product-detail', kwargs={'pk': self.pk}) return reverse('dashboard:product-detail', kwargs={'pk': self.pk})
def get_first_img(self):
return self.productphoto_set.first()
def get_second_img(self):
try:
return self.productphoto_set.all()[1]
except IndexError:
pass
class Meta: class Meta:
ordering = ['sorting', 'name'] ordering = ['sorting', 'name']

View File

@ -28,7 +28,7 @@
<div class="object__item object__item--col5"> <div class="object__item object__item--col5">
{% with product=item.product %} {% with product=item.product %}
<figure class="item__figure"> <figure class="item__figure">
<img class="product__image product__image--small" src="{{product.productphoto_set.first.image.url}}" alt="{{product.productphoto_set.first.image}}"> <img class="product__image product__image--small" src="{{product.get_first_img.image.url}}" alt="{{product.get_first_img.image}}">
<figcaption><strong>{{product.name}}</strong><br>Grind: {{item.customer_note}}</figcaption> <figcaption><strong>{{product.name}}</strong><br>Grind: {{item.customer_note}}</figcaption>
</figure> </figure>
<span>{{product.sku}}</span> <span>{{product.sku}}</span>

View File

@ -27,7 +27,7 @@
{% with product=form.instance.product %} {% with product=form.instance.product %}
{{form.id}} {{form.id}}
<figure class="item__figure"> <figure class="item__figure">
<img class="product__image product__image--small" src="{{product.productphoto_set.first.image.url}}" alt="{{product.productphoto_set.first.image}}"> <img class="product__image product__image--small" src="{{product.get_first_img.image.url}}" alt="{{product.get_first_img.image}}">
<figcaption><strong>{{product.name}}</strong></figcaption> <figcaption><strong>{{product.name}}</strong></figcaption>
</figure> </figure>
<span>{{product.sku}}</span> <span>{{product.sku}}</span>

View File

@ -8,7 +8,7 @@
</header> </header>
<section class="product__detail object__panel"> <section class="product__detail object__panel">
<figure class="product__figure"> <figure class="product__figure">
<img class="" src="{{product.productphoto_set.first.image.url}}" alt="{{product.productphoto_set.first.image}}"> <img class="" src="{{product.get_first_img.image.url}}" alt="{{product.get_first_img.image}}">
</figure> </figure>
<form method="post">{% csrf_token %} <form method="post">{% csrf_token %}
<p>Are you sure you want to delete "{{ object }}"?</p> <p>Are you sure you want to delete "{{ object }}"?</p>

View File

@ -12,7 +12,7 @@
</header> </header>
<section class="product__detail object__panel"> <section class="product__detail object__panel">
<figure class="product__figure"> <figure class="product__figure">
<img class="" src="{{product.productphoto_set.first.image.url}}" alt="{{product.productphoto_set.first.image}}"> <img class="" src="{{product.get_first_img.image.url}}" alt="{{product.get_first_img.image}}">
</figure> </figure>
<div> <div>
<h1>{{product.name}}</h1> <h1>{{product.name}}</h1>

View File

@ -17,7 +17,7 @@
{% for product in product_list %} {% for product in product_list %}
<a class="object__item object__item--link object__item--col4" href="{% url 'dashboard:product-detail' product.pk %}"> <a class="object__item object__item--link object__item--col4" href="{% url 'dashboard:product-detail' product.pk %}">
<figure class="product__figure"> <figure class="product__figure">
<img class="product__image" src="{{product.productphoto_set.first.image.url}}" alt="{{product.productphoto_set.first.image}}"> <img class="product__image" src="{{product.get_first_img.image.url}}" alt="{{product.get_first_img.image}}">
</figure> </figure>
<strong>{{product.name}}</strong> <strong>{{product.name}}</strong>
<span>{{product.visible_in_listings|yesno:"Yes,No"}}</span> <span>{{product.visible_in_listings|yesno:"Yes,No"}}</span>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 129 KiB

View File

@ -1,5 +1,9 @@
import { getCookie, setCookie } from "./cookie.js" import { getCookie, setCookie } from "./cookie.js"
/*
* Newsletter modal
*/
// Get the modal // Get the modal
const modal = document.querySelector(".modal-menu"); const modal = document.querySelector(".modal-menu");

View File

@ -0,0 +1,17 @@
/*
* Image hover swap
*/
function valueSwap(v1, v2) {
return [v2, v1]
}
const productItemImages = document.querySelectorAll('.product__with-img-swap')
productItemImages.forEach(productItemImage => {
productItemImage.addEventListener('mouseover', event => {
[event.target.src, event.target.dataset.altimgSrc] = valueSwap(event.target.src, event.target.dataset.altimgSrc)
})
productItemImage.addEventListener('mouseout', event => {
[event.target.src, event.target.dataset.altimgSrc] = valueSwap(event.target.src, event.target.dataset.altimgSrc)
})
})

View File

@ -246,6 +246,10 @@ footer > section {
margin: 0 auto; margin: 0 auto;
} }
section:not(:last-child) {
margin-bottom: 1rem;
}
/* ========================================================================== /* ==========================================================================
Modal Modal
@ -390,6 +394,7 @@ footer > section {
margin: 0; margin: 0;
padding: 0; padding: 0;
display: flex; display: flex;
flex-wrap: wrap;
} }
.nav__menu { .nav__menu {
@ -538,6 +543,11 @@ article + article {
color: var(--fg-alt-color); color: var(--fg-alt-color);
} }
.product__first-img--hidden,
.product__second-img--hidden {
display: none;
}
@media screen and (max-width: 900px) { @media screen and (max-width: 900px) {
.product__list { .product__list {
grid-template-columns: 1fr; grid-template-columns: 1fr;

View File

@ -14,7 +14,7 @@ COTACT_FORM_TEMPLATE = 'storefront/contact_form'
def contact_form_email(formdata): def contact_form_email(formdata):
send_templated_mail( send_templated_mail(
template_name=COTACT_FORM_TEMPLATE, template_name=COTACT_FORM_TEMPLATE,
from_email=formdata['email_address'], from_email=settings.DEFAULT_FROM_EMAIL,
recipient_list=[settings.DEFAULT_CONTACT_EMAIL], recipient_list=[settings.DEFAULT_CONTACT_EMAIL],
context=formdata context=formdata
) )

View File

@ -10,7 +10,7 @@
<div class="cart__item"> <div class="cart__item">
{% with product=item.product %} {% with product=item.product %}
<figure class="item__figure"> <figure class="item__figure">
<img class="item__image" src="{{product.productphoto_set.first.image.url}}" alt="{{product.productphoto_set.first.image}}"> <img class="item__image" src="{{product.get_first_img.image.url}}" alt="{{product.get_first_img.image}}">
</figure> </figure>
<div class="item__info"> <div class="item__info">
<h4>{{product.name}}</h4> <h4>{{product.name}}</h4>

View File

@ -12,7 +12,7 @@
</figure> </figure>
</section> </section>
<section> <section>
<p>We pay a steep premium for these beans, which are typically from smaller farms that are organized into co-ops. These farms take pride in their coffees, as the farmers make a living wage and their families are able to live in a healthier, more secure environment than farmers who grow a conventional coffee crop. The quality of our coffee is consistent, in part due to the quality of organic and fair trade beans.</p> <p>We value fair, guaranteed wages for growers and sustainable stewardship of the land where its grown. We pay a steep premium for these beans, which are typically from smaller farms that are organized into co-ops. These farms take pride in their coffees, as the farmers make a living wage and their families are able to live in a healthier, more secure environment than farmers who grow a conventional coffee crop. The quality of our coffee is consistent, in part due to the quality of organic and fair trade beans.</p>
<figure style="text-align: center;"> <figure style="text-align: center;">
<img class="site__ft-stamp" src="{% static 'images/fair_trade_stamp.png' %}" alt="Fair trade"> <img class="site__ft-stamp" src="{% static 'images/fair_trade_stamp.png' %}" alt="Fair trade">
</figure> </figure>

View File

@ -23,7 +23,7 @@
<tr> <tr>
{% with product=item.product %} {% with product=item.product %}
<td> <td>
<img src="{{product.productphoto_set.first.image.url}}" alt="{{product.productphoto_set.first.image}}"> <img src="{{product.get_first_img.image.url}}" alt="{{product.get_first_img.image}}">
</td> </td>
<td><strong>{{product.name}}</strong></td> <td><strong>{{product.name}}</strong></td>
<td>{{item.quantity}}</td> <td>{{item.quantity}}</td>

View File

@ -30,7 +30,7 @@
<div class="cart__item"> <div class="cart__item">
{% with product=item.product %} {% with product=item.product %}
<figure> <figure>
<img src="{{product.productphoto_set.first.image.url}}" alt="{{product.productphoto_set.first.image}}"> <img src="{{product.get_first_img.image.url}}" alt="{{product.get_first_img.image}}">
</figure> </figure>
<div> <div>
<h4>{{product.name}}</h4> <h4>{{product.name}}</h4>

View File

@ -15,9 +15,7 @@
</div> </div>
<div class="_form_element _x92496915 _full_width _clear" > <div class="_form_element _x92496915 _full_width _clear" >
<div class="_html-code"> <div class="_html-code">
<p> <p>Subscribe to get 10% off your first order!</p>
Subscribe to get 10% off your first order!
</p>
</div> </div>
</div> </div>
<div class="_form_element _x55366865 _full_width " > <div class="_form_element _x55366865 _full_width " >
@ -30,9 +28,7 @@
<!-- This STARTS the Custom Objects section --> <!-- This STARTS the Custom Objects section -->
</div><br> </div><br>
<div class="_form_element _x53687886 _full_width " > <div class="_form_element _x53687886 _full_width " >
<label for="email" class="_form-label"> <label for="email" class="_form-label">Email*</label>
Email*
</label>
<div class="_field-wrapper"> <div class="_field-wrapper">
<input type="text" id="email" name="email" placeholder="Type your email" required/> <input type="text" id="email" name="email" placeholder="Type your email" required/>
</div> </div>

View File

@ -13,7 +13,7 @@
{% endfor %} {% endfor %}
</section> </section>
<figure class="gallery__image-wrapper"> <figure class="gallery__image-wrapper">
<img class="gallery__image" src="{{ product.productphoto_set.first.image.url }}" alt="{{ product.name }}"> <img class="gallery__image" src="{{ product.get_first_img.image.url }}" alt="{{ product.name }}">
</figure> </figure>
<section class="product__info"> <section class="product__info">
<h1>{{product.name}}</h1> <h1>{{product.name}}</h1>

View File

@ -1,4 +1,9 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% load static %}
{% block head %}
<script defer src="{% static 'scripts/product_list.js' %}"></script>
{% endblock %}
{% block content %} {% block content %}
<article> <article>
@ -6,7 +11,7 @@
{% for product in product_list %} {% for product in product_list %}
<a class="product__item" href="{% url 'storefront:product-detail' product.pk %}"> <a class="product__item" href="{% url 'storefront:product-detail' product.pk %}">
<figure class="product__figure"> <figure class="product__figure">
<img class="product__image" src="{{product.productphoto_set.first.image.url}}" alt="{{product.productphoto_set.first.image}}"> <img class="product__image product__with-img-swap" data-altimg-src="{{product.get_second_img.image.url}}" src="{{product.get_first_img.image.url}}" alt="{{product.get_first_img.image}}">
</figure> </figure>
<div> <div>
<h3>{{ product.name }}</h3> <h3>{{ product.name }}</h3>

View File

@ -28,7 +28,7 @@
<div class="modal-menu"> <div class="modal-menu">
<div class="modal-menu__content"> <div class="modal-menu__content">
<div class="modal-menu__header"> <div class="modal-menu__header">
<h4>Sign up for our newsletter</h4> <h4>Newsletter</h4>
<span class="close-modal">&times;</span> <span class="close-modal">&times;</span>
</div> </div>
<div class="modal-menu__form"> <div class="modal-menu__form">
@ -44,6 +44,7 @@
<li><a class="nav__link" href="{% url 'storefront:product-list' %}">Shop</a></li> <li><a class="nav__link" href="{% url 'storefront:product-list' %}">Shop</a></li>
<li><a class="nav__link" href="https://bltcoffee.com/">Cafe</a></li> <li><a class="nav__link" href="https://bltcoffee.com/">Cafe</a></li>
<li><a class="nav__link" href="{% url 'storefront:fair-trade' %}">Fair trade</a></li> <li><a class="nav__link" href="{% url 'storefront:fair-trade' %}">Fair trade</a></li>
<li><a class="nav__link" href="{% url 'storefront:reviews' %}">Reviews</a></li>
<li><a class="nav__link" href="{% url 'storefront:about' %}">About</a></li> <li><a class="nav__link" href="{% url 'storefront:about' %}">About</a></li>
<li><a class="nav__link" href="{% url 'storefront:contact' %}">Contact</a></li> <li><a class="nav__link" href="{% url 'storefront:contact' %}">Contact</a></li>
</ul> </ul>
@ -80,12 +81,12 @@
<p><button class="show-modal">Subscribe to our newsletter</button></p> <p><button class="show-modal">Subscribe to our newsletter</button></p>
<p> <p>
<strong>Problem with your online order or have a question?</strong><br> <strong>Problem with your online order or have a question?</strong><br>
Please contact us, were happy to help you over the phone<br> Please <a href="{% url 'storefront:contact' %}">contact us</a>, were happy to help you over the phone<br>
<a href="tel:+13603855856">(360) 385-5856</a> between 8:00 am and 10:00 pm Pacific Time.<br> <a href="tel:+13603855856">(360) 385-5856</a> between 8:00 am and 10:00 pm Pacific Time.<br>
<address>100 Tyler St, Port Townsend, WA 98368</address> <address>854 East Park Ave. Suite 1, Port Townsend, WA 98368</address>
</p> </p>
<p> <p>
<small>Copyright © 2016-{% now "Y" %} Better Living Food Company Inc.<br> <small>Copyright &copy; 2016-{% now "Y" %} Better Living Food Company Inc.<br>
<a href="{% url 'storefront:contact' %}">Contact</a>&nbsp;|&nbsp;Fair Trade&nbsp;|&nbsp;Organic <a href="{% url 'storefront:contact' %}">Contact</a>&nbsp;|&nbsp;Fair Trade&nbsp;|&nbsp;Organic
</small> </small>
<br><br> <br><br>