Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display merch variations dropdown #472

Merged
merged 19 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions app/models/wagtail.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,13 @@ def sync_from_shopify_product_id(cls, shopify_product_id):
product = shopify.Product.find(shopify_product_id)
metafields = product.metafields()
metafields = metafields_to_dict(metafields)

# TODO adjust this function so that we can get different metafields from merchandise as opposed to books

if not metafields:
print('metafields are empty, skipping product')
return None

if cls.objects.filter(shopify_product_id=shopify_product_id).exists():
return cls.update_instance_for_product(product, metafields)
else:
Expand Down
7 changes: 2 additions & 5 deletions app/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,9 @@
"django.middleware.security.SecurityMiddleware",
]

if USE_WHITENOISE:
MIDDLEWARE += [
"whitenoise.middleware.WhiteNoiseMiddleware",
]

MIDDLEWARE += [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
Expand Down
4 changes: 2 additions & 2 deletions app/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from .base import *

if USE_WHITENOISE:
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"


DEBUG = False
SECRET_KEY = os.getenv("SECRET_KEY")
Expand Down
4 changes: 2 additions & 2 deletions app/templates/app/blocks/event_list_and_map_block.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% map in_place=False center="[-2.5, 53.6]" zoom=5.5 style="mapbox://styles/commonknowledge/cl7cnn4d6004a14nzcmvf0k01" %}
<article class="px-4 my-3 md:tw-hidden">
<h1 class='tw-text-4xl'>{{ value.title }}</h1>
<div class='tw-text-lg'>{{ value.intro|richtext }}</div>
<p>{{ value.intro|richtext }}</p>
{% if not user.is_member %}
{% bootstrap_button href="/join" content="Join LBC and come along" %}
{% endif %}
Expand All @@ -20,7 +20,7 @@ <h1 class='tw-text-4xl'>{{ value.title }}</h1>
data-map-target="config">
<article class="px-4 my-3 tw-hidden md:tw-block">
<h1 class='tw-text-4xl'>{{ value.title }}</h1>
<div class='tw-text-lg'>{{ value.intro|richtext }}</div>
<p>{{ value.intro|richtext }}</p>
{% if not user.is_member %}
{% bootstrap_button href="/join" content="Join LBC and come along" %}
{% endif %}
Expand Down
61 changes: 32 additions & 29 deletions app/templates/app/includes/cart_options.html
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
{% load djmoney books %}

<div class='row'>
{% if not product.variants %}
<div>
<span class="spinner-border spinner-border-sm"
role="status"
aria-hidden="true"></span>
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
Loading purchase options...
</div>
{% elif product.variants|length == 1 %}
<div class="tw-mb-2">
<!-- If there's only one variant, show it without a dropdown -->
{% with variant=product.variants.0 %}
<p>
{% if variant.title != "Default Title" %}{{ variant.title }} - {% endif %}
{% money_localize variant.price "GBP" %}
{% if variant.compare_at_price is not None %}
<s>{% money_localize variant.compare_at_price "GBP" %}</s>
{% endif %}
</p>
{% endwith %}
</div>
<div>
<button id="addToCartButton" class="btn btn-outline-secondary btn-disable-strikethrough" data-product-variant-id-param="{{ product.variants.0.id }}" data-product-target="addToCartButton" {% if product.variants.0.inventory_quantity == 0 and product.variants.0.inventory_policy == 'deny' %} disabled="true" {% elif loading or disabled %} disabled="true" {% else %} data-bs-toggle="offcanvas" data-bs-target="#cart" data-action="click->product#add"{% endif %}>Add to cart</button>
</div>
{% else %}
{% for variant in product.variants %}
<div class='tw-mb-2'>
{% if variant.title != "Default Title" %}<h5>{{ variant.title }}</h5>{% endif %}
{% if variant.inventory_quantity == 0 and variant.inventory_policy == 'deny' %}
Out of Stock
{% elif loading %}
<span class="spinner-border spinner-border-sm"
role="status"
aria-hidden="true"></span>
<span>Loading...</span>
{% else %}
<button class="btn btn-outline-secondary btn-disable-strikethrough"
{% if variant.inventory_quantity == 0 and variant.inventory_policy == 'deny' %} disabled="true" {% elif loading or disabled %} disabled="true" {% else %} data-bs-toggle="offcanvas" data-bs-target="#cart" data-action="click->product#add" data-product-variant-id-param="{{ variant.id }}" {% endif %}>
Add to cart
</button>
{% endif %}
<div class='tw-mt-2 fs-5 tw-font-bold'>
{% if variant.compare_at_price is not None %}
<b>{% money_localize variant.price "GBP" %}</b> <s>{% money_localize variant.compare_at_price "GBP" %}</s>
{% else %}
<div class="tw-mb-2">
<select id="variantSelector" class="form-select" {% if loading or disabled %}disabled="true"{% endif %} data-action="change->product#updateAddToCartButton" data-product-target="variantSelector">
{% for variant in product.variants %}
<option value="{{ variant.id }}" data-variant-id="{{ variant.id }}" {% if variant.inventory_quantity == 0 and variant.inventory_policy == 'deny' %}disabled{% endif %}>
{% if variant.title != "Default Title" %}{{ variant.title }} -{% endif %}
{% money_localize variant.price "GBP" %}
{% endif %}

</div>
</div>
{% endfor %}
{% if variant.compare_at_price is not None %}
<s>{% money_localize variant.compare_at_price "GBP" %}</s>
{% endif %}
</option>
{% endfor %}
</select>
</div>
<div>
<button class="btn btn-outline-secondary btn-disable-strikethrough" data-product-variant-id-param="{{ product.variants.0.id }}" data-product-target="addToCartButton" {% if product.variants.0.inventory_quantity == 0 and product.variants.0.inventory_policy == 'deny' %} disabled="true" {% elif loading or disabled %} disabled="true" {% else %} data-bs-toggle="offcanvas" data-bs-target="#cart" data-action="click->product#add"{% endif %}>Add to cart</button>
</div>
{% endif %}
</div>
4 changes: 2 additions & 2 deletions app/templates/app/includes/event_list_and_map.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% map in_place=False center="[-2.5, 53.6]" zoom=5.5 style="mapbox://styles/commonknowledge/cl7cnn4d6004a14nzcmvf0k01" %}
<article class="px-4 my-3 md:tw-hidden">
<h1 class='tw-text-4xl'>{{ title }}</h1>
<div class='tw-text-lg'>{{ intro|richtext }}</div>
<p>{{ intro|richtext }}</p>
{% if not user.is_member %}
{% bootstrap_button href="/join" content="Join LBC and come along" %}
{% endif %}
Expand All @@ -25,7 +25,7 @@ <h1 class='tw-text-4xl'>{{ title }}</h1>
data-list-filter-option-passive-classes-value="tw-bg-slate-300">
<article class="px-4 my-3 tw-hidden md:tw-block">
<h1 class='tw-text-4xl'>{{ title }}</h1>
<div class='tw-text-lg'>{{ intro|richtext }}</div>
<p>{{ intro|richtext }}</p>
{% if not user.is_member %}
{% bootstrap_button href="/join" content="Join LBC and come along" %}
{% endif %}
Expand Down
6 changes: 3 additions & 3 deletions app/templates/app/includes/newsletter_signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
method="post"
id="mc-embedded-subscribe-form"
name="mc-embedded-subscribe-form"
class="validate"
class="validate "
target="_blank"
novalidate>
<fieldset>
<legend class="h1 fw-bold mb-3">
<fieldset class="tw-p-3">
<legend class="h2 fw-bold mb-3">
{% firstof heading "Subscribe to the newsletter" %}
</legend>
<div class="mb-3">
Expand Down
12 changes: 10 additions & 2 deletions frontend/controllers/product-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import { isAfter } from "date-fns";

export default class ShopifyBuyControllerBase extends Controller {
// Targets
static targets = ["template"];
static targets = ["template", "variantSelector", "addToCartButton"];

public templateTargets?: HTMLElement[];
public variantSelectorTarget!: HTMLSelectElement;
public addToCartButtonTarget!: HTMLButtonElement;

// Values
static values = {
Expand Down Expand Up @@ -40,6 +43,11 @@ export default class ShopifyBuyControllerBase extends Controller {
this.getCart();
}

updateAddToCartButton() {
const selectedVariantId = this.variantSelectorTarget.value;
this.addToCartButtonTarget.setAttribute('data-product-variant-id-param', selectedVariantId);
}
Moggach marked this conversation as resolved.
Show resolved Hide resolved

private LOCALSTORAGE_CHECKOUT_ID = "checkoutId";

get checkoutId() {
Expand Down Expand Up @@ -320,4 +328,4 @@ function currency(
function length(arr: any[]) {
if (!arr) return 0;
return arr.length || 0;
}
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@
"ts-jest": "^27.1.4",
"typescript": "^4.6.3",
"vite": "^5.0.2"
}
},
"packageManager": "[email protected]"

}
15 changes: 15 additions & 0 deletions render-worker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
services:
- name: leftbookclub-worker
type: worker
env: python
plan: starter
buildCommand: "poetry install"
startCommand: "poetry run python manage.py start_worker"
numInstances: 1
concurrency:
type: fixed
min: 1
max: 2
gracefulShutdown:
signal: SIGINT
timeout: 5
Loading