Add cart stock limits

This commit is contained in:
Nathan Chapman 2022-11-05 11:27:48 -06:00
parent 6c8abec2d5
commit 0dd19b2d5b
5 changed files with 44 additions and 2 deletions

View File

@ -71,6 +71,14 @@ class ProductCategory(models.Model):
verbose_name_plural = 'Product Categories'
class ProductManager(models.Manager):
def get_queryset(self):
return super().get_queryset().prefetch_related(
'productphoto_set',
'options'
)
class Product(models.Model):
category = models.ForeignKey(
ProductCategory,
@ -92,6 +100,8 @@ class Product(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
objects = ProductManager()
def __str__(self):
return self.name
@ -124,6 +134,12 @@ class ProductVariant(models.Model):
on_delete=models.CASCADE,
related_name='variants'
)
image = models.ForeignKey(
'ProductPhoto',
on_delete=models.SET_NULL,
related_name='+',
null=True
)
name = models.CharField(max_length=255)
sku = models.CharField(max_length=255, unique=True)
stripe_id = models.CharField(max_length=255, blank=True)
@ -145,6 +161,7 @@ class ProductVariant(models.Model):
null=True,
validators=[MinValueValidator(0)]
)
sorting = models.PositiveIntegerField(blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
@ -155,7 +172,7 @@ class ProductVariant(models.Model):
return f'{self.product}: {self.name}'
class Meta:
ordering = ['weight']
ordering = ['sorting', 'weight']
class ProductOption(models.Model):
@ -491,6 +508,13 @@ class SiteSettings(SingletonBase):
related_name='+',
on_delete=models.SET_NULL
)
free_shipping_min = models.DecimalField(
max_digits=settings.DEFAULT_MAX_DIGITS,
decimal_places=settings.DEFAULT_DECIMAL_PLACES,
blank=True,
null=True,
help_text='Minimum dollar amount in the cart subtotal to qualify for free shipping'
)
def __str__(self):
return 'Site Settings'

View File

@ -23,5 +23,17 @@
{% endfor %}
</div>
</section>
<section class="object__panel">
<div class="object__item panel__header panel__header--flex">
<h4>Site Settings</h4>
<a href="{% url 'dashboard:settings-update' site_settings.pk %}" class="action-button order__fulfill">Edit</a>
</div>
<div class="panel__item">
<p>USPS User ID: {{ site_settings.usps_user_id }}</p>
<p>Default shipping rate: {{ site_settings.default_shipping_rate }}</p>
<p>Free shipping min: ${{ site_settings.free_shipping_min }}</p>
</div>
</section>
</article>
{% endblock %}

View File

@ -30,7 +30,7 @@
</figure>
<span>{{product.sku}}</span>
<span>{{item.quantity}}</span>
<span>${{item.variant.price}}</span>
<span>${{item.unit_price}}</span>
<span>${{item.get_total}}</span>
{% endwith %}
</div>

View File

@ -12,6 +12,11 @@ urlpatterns = [
views.DashboardConfigView.as_view(),
name='config'
),
path(
'settings/<int:pk>/update/',
views.SiteSettingsUpdateView.as_view(),
name='settings-update'
),
path(
'catalog/',
views.CatalogView.as_view(),

View File

@ -54,6 +54,7 @@
<input type="submit" value="Apply" class="action-button">
</p>
</form>
<h5>Free shipping on orders over ${{ site_settings.free_shipping_min|floatformat:"2" }}</h5>
<div class="cart__table-wrapper">
<table class="cart__totals">
<tr>