Skip to content

Commit

Permalink
Hide vol pricing and qty rules when variant is unavailable (#2889)
Browse files Browse the repository at this point in the history
  • Loading branch information
sofiamatulis committed Aug 3, 2023
1 parent 7a6d018 commit 07c1828
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
30 changes: 21 additions & 9 deletions assets/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ class SlideshowComponent extends SliderComponent {

setSlidePosition(position) {
if (this.setPositionTimeout) clearTimeout(this.setPositionTimeout);
this.setPositionTimeout = setTimeout (() => {
this.setPositionTimeout = setTimeout(() => {
this.slider.scrollTo({
left: position,
});
Expand Down Expand Up @@ -1110,12 +1110,18 @@ class VariantSelects extends HTMLElement {
const pricePerItemSource = html.getElementById(`Price-Per-Item-${this.dataset.originalSection ? this.dataset.originalSection : this.dataset.section}`);

const volumePricingDestination = document.getElementById(`Volume-${this.dataset.section}`);
const qtyRules = document.getElementById(`Quantity-Rules-${this.dataset.section}`);
const volumeNote = document.getElementById(`Volume-Note-${this.dataset.section}`);

if (volumeNote) volumeNote.classList.remove('hidden');
if (volumePricingDestination) volumePricingDestination.classList.remove('hidden');
if (qtyRules) qtyRules.classList.remove('hidden');

if (source && destination) destination.innerHTML = source.innerHTML;
if (inventorySource && inventoryDestination) inventoryDestination.innerHTML = inventorySource.innerHTML;
if (skuSource && skuDestination) {
skuDestination.innerHTML = skuSource.innerHTML;
skuDestination.classList.toggle('visibility-hidden', skuSource.classList.contains('visibility-hidden'));
skuDestination.classList.toggle('hidden', skuSource.classList.contains('hidden'));
}

if (volumePricingSource && volumePricingDestination) {
Expand All @@ -1124,15 +1130,15 @@ class VariantSelects extends HTMLElement {

if (pricePerItemSource && pricePerItemDestination) {
pricePerItemDestination.innerHTML = pricePerItemSource.innerHTML;
pricePerItemDestination.classList.toggle('visibility-hidden', pricePerItemSource.classList.contains('visibility-hidden'));
pricePerItemDestination.classList.toggle('hidden', pricePerItemSource.classList.contains('hidden'));
}

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

if (price) price.classList.remove('visibility-hidden');
if (price) price.classList.remove('hidden');

if (inventoryDestination)
inventoryDestination.classList.toggle('visibility-hidden', inventorySource.innerText === '');
inventoryDestination.classList.toggle('hidden', inventorySource.innerText === '');

const addButtonUpdated = html.getElementById(`ProductSubmitButton-${sectionId}`);
this.toggleAddButton(
Expand Down Expand Up @@ -1176,13 +1182,19 @@ class VariantSelects extends HTMLElement {
const inventory = document.getElementById(`Inventory-${this.dataset.section}`);
const sku = document.getElementById(`Sku-${this.dataset.section}`);
const pricePerItem = document.getElementById(`Price-Per-Item-${this.dataset.section}`);
const volumeNote = document.getElementById(`Volume-Note-${this.dataset.section}`);
const volumeTable = document.getElementById(`Volume-${this.dataset.section}`);
const qtyRules = document.getElementById(`Quantity-Rules-${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');
if (sku) sku.classList.add('visibility-hidden');
if (pricePerItem) pricePerItem.classList.add('visibility-hidden');
if (price) price.classList.add('hidden');
if (inventory) inventory.classList.add('hidden');
if (sku) sku.classList.add('hidden');
if (pricePerItem) pricePerItem.classList.add('hidden');
if (volumeNote) volumeNote.classList.add('hidden');
if (volumeTable) volumeTable.classList.add('hidden');
if (qtyRules) qtyRules.classList.add('hidden');
}

getVariantData() {
Expand Down
4 changes: 2 additions & 2 deletions sections/featured-product.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
-%}
</div>
{%- if product.quantity_price_breaks_configured? -%}
<div class="volume-pricing-note">
<div class="volume-pricing-note" id="Volume-Note-{{ section.id }}">
<span>{{ 'products.product.volume_pricing.note' | t }}</span>
</div>
{%- endif -%}
Expand Down Expand Up @@ -361,7 +361,7 @@
</price-per-item>
{%- endif -%}
</div>
<div class="quantity__rules caption no-js-hidden">
<div class="quantity__rules caption no-js-hidden" id="Quantity-Rules-{{ section.id }}">
{%- if product.selected_or_first_available_variant.quantity_rule.increment > 1 -%}
<span class="divider">
{{-
Expand Down
4 changes: 2 additions & 2 deletions sections/main-product.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
-%}
</div>
{%- if product.quantity_price_breaks_configured? -%}
<div class="volume-pricing-note">
<div class="volume-pricing-note" id="Volume-Note-{{ section.id }}">
<span>{{ 'products.product.volume_pricing.note' | t }}</span>
</div>
{%- endif -%}
Expand Down Expand Up @@ -334,7 +334,7 @@
</price-per-item>
{%- endif -%}
</div>
<div class="quantity__rules caption no-js-hidden">
<div class="quantity__rules caption no-js-hidden" id="Quantity-Rules-{{ section.id }}">
{%- if product.selected_or_first_available_variant.quantity_rule.increment > 1 -%}
<span class="divider">
{{-
Expand Down

0 comments on commit 07c1828

Please sign in to comment.