Skip to content

Commit

Permalink
Revert "Support Combined Listings and 2k Variants (#3246)" (#3377)
Browse files Browse the repository at this point in the history
* Revert "Support Combined Listings and 2k Variants (#3246)"

This reverts commit a2c6f54.

* Revert stylelint changes
  • Loading branch information
lhoffbeck authored Mar 28, 2024
1 parent 2bf1bf7 commit e488521
Show file tree
Hide file tree
Showing 15 changed files with 312 additions and 442 deletions.
1 change: 0 additions & 1 deletion assets/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -3241,7 +3241,6 @@ details-disclosure > details {
opacity: 1;
animation: none;
transition: none;
transform: none;
}

.scroll-trigger.scroll-trigger--design-mode.animate--slide-in {
Expand Down
5 changes: 0 additions & 5 deletions assets/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,4 @@ const PUB_SUB_EVENTS = {
quantityUpdate: 'quantity-update',
variantChange: 'variant-change',
cartError: 'cart-error',
sectionRefreshed: 'section-refreshed',
};

const SECTION_REFRESH_RESOURCE_TYPE = {
product: 'product',
};
549 changes: 227 additions & 322 deletions assets/global.js

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions assets/pickup-availability.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ if (!customElements.get('pickup-availability')) {
}

fetchAvailability(variantId) {
if (!variantId) return;

let rootUrl = this.dataset.rootUrl;
if (!rootUrl.endsWith('/')) {
rootUrl = rootUrl + '/';
Expand Down
2 changes: 0 additions & 2 deletions assets/quick-add.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
.quick-add-modal .scroll-trigger.scroll-trigger {
animation: none;
opacity: 1;
transform: none;
}

.quick-add-modal__content.quick-add-modal__content--bulk {
Expand Down Expand Up @@ -283,7 +282,6 @@ quick-add-modal .product__column-sticky {
}

quick-add-modal .product:not(.product--no-media) .product__info-wrapper {
padding-top: 2rem;
padding-left: 4rem;
max-width: 54%;
width: calc(54% - var(--grid-desktop-horizontal-spacing) / 2);
Expand Down
74 changes: 36 additions & 38 deletions assets/quick-add.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,85 +25,83 @@ if (!customElements.get('quick-add-modal')) {
.then((response) => response.text())
.then((responseText) => {
const responseHTML = new DOMParser().parseFromString(responseText, 'text/html');
const productElement = responseHTML.querySelector('section[id^="MainProduct-"]');

this.preprocessHTML(productElement);
HTMLUpdateUtility.setInnerHTML(this.modalContent, productElement.innerHTML);
this.productElement = responseHTML.querySelector('section[id^="MainProduct-"]');
this.productElement.classList.forEach((classApplied) => {
if (classApplied.startsWith('color-') || classApplied === 'gradient')
this.modalContent.classList.add(classApplied);
});
this.preventDuplicatedIDs();
this.removeDOMElements();
this.setInnerHTML(this.modalContent, this.productElement.innerHTML);

if (window.Shopify && Shopify.PaymentButton) {
Shopify.PaymentButton.init();
}

if (window.ProductModel) window.ProductModel.loadShopifyXR();

this.removeGalleryListSemantic();
this.updateImageSizes();
this.preventVariantURLSwitching();
super.show(opener);
})
.finally(() => {
this.bindProductChangeCallbacks();
opener.removeAttribute('aria-disabled');
opener.classList.remove('loading');
opener.querySelector('.loading__spinner').classList.add('hidden');
});
}

bindProductChangeCallbacks() {
const swapProductUtility = this.querySelector('variant-selects')?.swapProductUtility;
if (swapProductUtility) {
swapProductUtility.addPreProcessCallback(this.preprocessHTML.bind(this));
swapProductUtility.addPostProcessCallback(() => {
this.modalContent = this.querySelector('[id^="QuickAddInfo-"]');
this.bindProductChangeCallbacks();
});
}
}
setInnerHTML(element, html) {
element.innerHTML = html;

preprocessHTML(productElement) {
productElement.classList.forEach((classApplied) => {
if (classApplied.startsWith('color-') || classApplied === 'gradient')
this.modalContent.classList.add(classApplied);
// Reinjects the script tags to allow execution. By default, scripts are disabled when using element.innerHTML.
element.querySelectorAll('script').forEach((oldScriptTag) => {
const newScriptTag = document.createElement('script');
Array.from(oldScriptTag.attributes).forEach((attribute) => {
newScriptTag.setAttribute(attribute.name, attribute.value);
});
newScriptTag.appendChild(document.createTextNode(oldScriptTag.innerHTML));
oldScriptTag.parentNode.replaceChild(newScriptTag, oldScriptTag);
});
this.preventDuplicatedIDs(productElement);
this.removeDOMElements(productElement);
this.removeGalleryListSemantic(productElement);
this.updateImageSizes(productElement);
this.preventVariantURLSwitching(productElement);
}

preventVariantURLSwitching(productElement) {
const variantPicker = productElement.querySelector('variant-selects');
preventVariantURLSwitching() {
const variantPicker = this.modalContent.querySelector('variant-selects');
if (!variantPicker) return;

variantPicker.setAttribute('data-update-url', 'false');
}

removeDOMElements(productElement) {
const pickupAvailability = productElement.querySelector('pickup-availability');
removeDOMElements() {
const pickupAvailability = this.productElement.querySelector('pickup-availability');
if (pickupAvailability) pickupAvailability.remove();

const productModal = productElement.querySelector('product-modal');
const productModal = this.productElement.querySelector('product-modal');
if (productModal) productModal.remove();

const modalDialog = productElement.querySelectorAll('modal-dialog');
const modalDialog = this.productElement.querySelectorAll('modal-dialog');
if (modalDialog) modalDialog.forEach((modal) => modal.remove());
}

preventDuplicatedIDs(productElement) {
const sectionId = productElement.dataset.section;
productElement.innerHTML = productElement.innerHTML.replaceAll(sectionId, `quickadd-${sectionId}`);
productElement.querySelectorAll('variant-selects, product-info').forEach((element) => {
preventDuplicatedIDs() {
const sectionId = this.productElement.dataset.section;
this.productElement.innerHTML = this.productElement.innerHTML.replaceAll(sectionId, `quickadd-${sectionId}`);
this.productElement.querySelectorAll('variant-selects, product-info').forEach((element) => {
element.dataset.originalSection = sectionId;
});
}

removeGalleryListSemantic(productElement) {
const galleryList = productElement.querySelector('[id^="Slider-Gallery"]');
removeGalleryListSemantic() {
const galleryList = this.modalContent.querySelector('[id^="Slider-Gallery"]');
if (!galleryList) return;

galleryList.setAttribute('role', 'presentation');
galleryList.querySelectorAll('[id^="Slide-"]').forEach((li) => li.setAttribute('role', 'presentation'));
}

updateImageSizes(productElement) {
const product = productElement.querySelector('.product');
updateImageSizes() {
const product = this.modalContent.querySelector('.product');
const desktopColumns = product.classList.contains('product--columns');
if (!desktopColumns) return;

Expand Down
10 changes: 0 additions & 10 deletions assets/quick-order-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ if (!customElements.get('quick-order-list')) {
}

cartUpdateUnsubscriber = undefined;
sectionRefreshUnsubscriber = undefined;

onSubmit(event) {
event.preventDefault();
Expand All @@ -125,20 +124,11 @@ if (!customElements.get('quick-order-list')) {
this.addMultipleDebounce()
});
});
this.sectionRefreshUnsubscriber = subscribe(PUB_SUB_EVENTS.sectionRefreshed, (event) => {
const isParentSectionUpdated =
this.sectionId && (event.data?.sectionId ?? '') === `${this.sectionId.split('__')[0]}__main`;

if (isParentSectionUpdated) {
this.refresh();
}
});
this.sectionId = this.dataset.id;
}

disconnectedCallback() {
this.cartUpdateUnsubscriber?.();
this.sectionRefreshUnsubscriber?.();
}

defineInputsAndQuickOrderTable() {
Expand Down
6 changes: 2 additions & 4 deletions sections/main-product.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,7 @@
{%- when 'complementary' -%}
<product-recommendations
class="complementary-products quick-add-hidden{% if block.settings.make_collapsible_row %} is-accordion{% endif %}{% if block.settings.enable_quick_add %} complementary-products-contains-quick-add{% endif %}"
data-url="{{ routes.product_recommendations_url }}?limit={{ block.settings.product_list_limit }}&intent=complementary"
data-section-id="{{ section.id }}"
data-product-id="{{ product.id }}"
data-url="{{ routes.product_recommendations_url }}?section_id={{ section.id }}&product_id={{ product.id }}&limit={{ block.settings.product_list_limit }}&intent=complementary"
>
{%- if recommendations.performed and recommendations.products_count > 0 -%}
<aside
Expand Down Expand Up @@ -2275,4 +2273,4 @@
}
]
}
{% endschema %}
{% endschema %}
4 changes: 1 addition & 3 deletions sections/related-products.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
<div class="color-{{ section.settings.color_scheme }} gradient">
<product-recommendations
class="related-products page-width section-{{ section.id }}-padding isolate{% if settings.animations_reveal_on_scroll %} scroll-trigger animate--slide-in{% endif %}"
data-url="{{ routes.product_recommendations_url }}?limit={{ section.settings.products_to_show }}"
data-section-id="{{ section.id }}"
data-product-id="{{ product.id }}"
data-url="{{ routes.product_recommendations_url }}?section_id={{ section.id }}&product_id={{ product.id }}&limit={{ section.settings.products_to_show }}"
>
{% if recommendations.performed and recommendations.products_count > 0 %}
<h2 class="related-products__heading inline-richtext {{ section.settings.heading_size }}">
Expand Down
10 changes: 2 additions & 8 deletions snippets/buy-buttons.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@
type="hidden"
name="id"
value="{{ product.selected_or_first_available_variant.id }}"
{% if product.selected_or_first_available_variant.available == false
or quantity_rule_soldout
or product.selected_or_first_available_variant == nil
%}
{% if product.selected_or_first_available_variant.available == false or quantity_rule_soldout %}
disabled
{% endif %}
class="product-variant-id"
Expand All @@ -83,10 +80,7 @@
type="submit"
name="add"
class="product-form__submit button button--full-width {% if show_dynamic_checkout %}button--secondary{% else %}button--primary{% endif %}"
{% if product.selected_or_first_available_variant.available == false
or quantity_rule_soldout
or product.selected_or_first_available_variant == nil
%}
{% if product.selected_or_first_available_variant.available == false or quantity_rule_soldout %}
disabled
{% endif %}
>
Expand Down
2 changes: 0 additions & 2 deletions snippets/price.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
endif
-%}

{%- unless target == nil -%}
<div
class="
price
Expand Down Expand Up @@ -127,4 +126,3 @@
</span>
{%- endif -%}
</div>
{% endunless %}
Loading

0 comments on commit e488521

Please sign in to comment.