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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add inventory status block #1976

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions assets/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -849,12 +849,22 @@ class VariantSelects extends HTMLElement {
if (source && destination) destination.innerHTML = source.innerHTML;

const price = document.getElementById(`price-${this.dataset.section}`);
const inventory = document.getElementById(`inventory-${this.dataset.section}`);

if (price) price.classList.remove('visibility-hidden');
if (inventory) inventory.classList.remove('visibility-hidden'), this.updateInventory(html);
this.toggleAddButton(!this.currentVariant.available, window.variantStrings.soldOut);
});
}

updateInventory(html) {
const id = `inventory-${this.dataset.section}`;
const destination = document.getElementById(id);
const source = html.getElementById(id);

if (source && destination) destination.innerHTML = source.innerHTML;
}

toggleAddButton(disable = true, text, modifyClass = true) {
const productForm = document.getElementById(`product-form-${this.dataset.section}`);
if (!productForm) return;
Expand All @@ -878,9 +888,11 @@ class VariantSelects extends HTMLElement {
const addButton = button.querySelector('[name="add"]');
const addButtonText = button.querySelector('[name="add"] > span');
const price = document.getElementById(`price-${this.dataset.section}`);
const inventory = document.getElementById(`inventory-${this.dataset.section}`);
if (!addButton) return;
addButtonText.textContent = window.variantStrings.unavailable;
if (price) price.classList.add('visibility-hidden');
if (inventory) inventory.classList.add('visibility-hidden');
}

getVariantData() {
Expand Down
1 change: 1 addition & 0 deletions locales/en.default.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"choose_options": "Choose options",
"choose_product_options": "Choose options for {{ product_name }}",
"description": "Description",
"inventory": "{{ quantity }} in stock",
"on_sale": "Sale",
"product_variants": "Product variants",
"media": {
Expand Down
34 changes: 34 additions & 0 deletions locales/en.default.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,23 @@
"price": {
"name": "Price"
},
"inventory": {
"name": "Inventory status",
"settings": {
"text_style": {
"label": "Text style",
"options__1": {
"label": "Body"
},
"options__2": {
"label": "Subtitle"
},
"options__3": {
"label": "Uppercase"
}
}
}
},
"quantity_selector": {
"name": "Quantity selector"
},
Expand Down Expand Up @@ -1645,6 +1662,23 @@
"price": {
"name": "Price"
},
"inventory": {
"name": "Inventory status",
"settings": {
"text_style": {
"label": "Text style",
"options__1": {
"label": "Body"
},
"options__2": {
"label": "Subtitle"
},
"options__3": {
"label": "Uppercase"
}
}
}
},
"quantity_selector": {
"name": "Quantity selector"
},
Expand Down
39 changes: 39 additions & 0 deletions sections/featured-product.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@
{%- endform -%}
</div>
{%- endif -%}
{%- when 'inventory' -%}
<p
class="product__text product__text--inventory no-js-hidden{% if block.settings.text_style == 'uppercase' %} caption-with-letter-spacing{% elsif block.settings.text_style == 'subtitle' %} subtitle{% endif %}"
id="inventory-{{ section.id }}"
{{ block.shopify_attributes }}
>
{{- block.settings.text -}}
{%- if product.selected_or_first_available_variant.available and product.selected_or_first_available_variant.inventory_management == 'shopify' -%}
{{ 'products.product.inventory' | t: quantity: product.selected_or_first_available_variant.inventory_quantity }}
{%- endif -%}
</p>
{%- when 'quantity_selector' -%}
<div
class="product-form__input product-form__quantity{% if settings.inputs_shadow_vertical_offset != 0 and settings.inputs_shadow_vertical_offset < 0 %} product-form__quantity-top{% endif %}"
Expand Down Expand Up @@ -306,6 +317,7 @@
{{ variant.title }}
{%- if variant.available == false %} - {{ 'products.product.sold_out' | t }}{% endif %}
- {{ variant.price | money | strip_html }}
{% if variant.available and variant.inventory_management == 'shopify' -%} - {{ 'products.product.inventory' | t: quantity: variant.inventory_quantity }}{% endif %}
</option>
{%- endfor -%}
</select>
Expand Down Expand Up @@ -695,6 +707,33 @@
"name": "t:sections.featured-product.blocks.price.name",
"limit": 1
},
{
"type": "inventory",
"name": "t:sections.featured-product.blocks.inventory.name",
"limit": 1,
"settings": [
{
"type": "select",
"id": "text_style",
"options": [
{
"value": "body",
"label": "t:sections.featured-product.blocks.inventory.settings.text_style.options__1.label"
},
{
"value": "subtitle",
"label": "t:sections.featured-product.blocks.inventory.settings.text_style.options__2.label"
},
{
"value": "uppercase",
"label": "t:sections.featured-product.blocks.inventory.settings.text_style.options__3.label"
}
],
"default": "body",
"label": "t:sections.featured-product.blocks.inventory.settings.text_style.label"
}
]
},
{
"type": "quantity_selector",
"name": "t:sections.featured-product.blocks.quantity_selector.name",
Expand Down
39 changes: 39 additions & 0 deletions sections/main-product.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,17 @@
{{ form | payment_terms }}
{%- endform -%}
</div>
{%- when 'inventory' -%}
<p
class="product__text product__text--inventory no-js-hidden{% if block.settings.text_style == 'uppercase' %} caption-with-letter-spacing{% elsif block.settings.text_style == 'subtitle' %} subtitle{% endif %}"
id="inventory-{{ section.id }}"
{{ block.shopify_attributes }}
>
{{- block.settings.text -}}
{%- if product.selected_or_first_available_variant.available and product.selected_or_first_available_variant.inventory_management == 'shopify' -%}
{{ 'products.product.inventory' | t: quantity: product.selected_or_first_available_variant.inventory_quantity }}
{%- endif -%}
</p>
{%- when 'description' -%}
{%- if product.description != blank -%}
<div class="product__description rte quick-add-hidden">
Expand Down Expand Up @@ -572,6 +583,7 @@
{{ variant.title }}
{%- if variant.available == false %} - {{ 'products.product.sold_out' | t }}{% endif %}
- {{ variant.price | money | strip_html }}
{% if variant.available and variant.inventory_management == 'shopify' -%} - {{ 'products.product.inventory' | t: quantity: variant.inventory_quantity }}{% endif %}
</option>
{%- endfor -%}
</select>
Expand Down Expand Up @@ -1215,6 +1227,33 @@
"name": "t:sections.main-product.blocks.price.name",
"limit": 1
},
{
"type": "inventory",
"name": "t:sections.main-product.blocks.inventory.name",
"limit": 1,
"settings": [
{
"type": "select",
"id": "text_style",
"options": [
{
"value": "body",
"label": "t:sections.main-product.blocks.inventory.settings.text_style.options__1.label"
},
{
"value": "subtitle",
"label": "t:sections.main-product.blocks.inventory.settings.text_style.options__2.label"
},
{
"value": "uppercase",
"label": "t:sections.main-product.blocks.inventory.settings.text_style.options__3.label"
}
],
"default": "body",
"label": "t:sections.main-product.blocks.inventory.settings.text_style.label"
}
]
},
{
"type": "quantity_selector",
"name": "t:sections.main-product.blocks.quantity_selector.name",
Expand Down