PageSourceSearch

https://us.pighen.com/cdn/shop/t/3/assets/bbd-rebuy-crosssells.js?v=33976329341440041011777531581

js pighen.com collected 2026-10-04 08:51:31 UTC 4,366 bytes, 2 lines download raw bytes

1import{sectionRenderer}from"@theme/section-renderer";import{ThemeEvents}from"@theme/events";class BbdRebuyCrosssells extends HTMLElement{#mutationObserver=new MutationObserver(mutations=>{for(const mutation of mutations)if(!(mutation.target!==this||mutation.type!=="attributes")&&mutation.attributeName!=="data-error"&&!(mutation.attributeName==="class"&&this.classList.contains("hidden"))&&!(mutation.attributeName==="data-recommendations-performed"&&this.dataset.recommendationsPerformed==="true")){this.#loadRecommendations();break}});#cachedRecommendations={};#onCartUpdateBound=null;#activeFetch=null;connectedCallback(){this.#loadRecommendations(),this.#mutationObserver.observe(this,{attributes:!0}),this.#onCartUpdateBound=this.#onCartUpdate.bind(this),document.addEventListener(ThemeEvents.cartUpdate,this.#onCartUpdateBound)}disconnectedCallback(){this.#mutationObserver.disconnect(),document.removeEventListener(ThemeEvents.cartUpdate,this.#onCartUpdateBound)}#onCartUpdate(){this.#loadRecommendations()}#buildCartItemsQueryString(items){return items.map((item,index)=>{const prefix=`cart[items][${index}]`;return`${encodeURIComponent(`${prefix}[product_id]`)}=${item.product_id}&${encodeURIComponent(`${prefix}[variant_id]`)}=${item.variant_id}&${encodeURIComponent(`${prefix}[quantity]`)}=${item.quantity}`}).join("&")}async#loadRecommendations(){const{rebuyId,apiKey,customerId}=this.dataset;if(!rebuyId||!apiKey){this.#handleError(new Error("Rebuy Widget ID and API Key are required"));return}this.#activeFetch?.abort();const controller=new AbortController;this.#activeFetch=controller;try{const cart=await(await fetch("/cart.js",{signal:controller.signal})).json();if(!cart.items||cart.items.length===0){this.#handleError(new Error("Cart is empty"));return}for(const item of cart.items){const productId=item.product_id,variantId=item.variant_id,params=new URLSearchParams({key:apiKey,shopify_product_ids:productId,shopify_variant_ids:variantId,cart_subtotal:cart.total_price,cart_line_count:cart.item_count,cart_item_count:cart.item_count,limit:"10"});customerId&&params.set("shopify_customer_id",customerId);const url=`https://rebuyengine.com/api/v1/custom/id/${rebuyId}?${params.toString()}`,cachedResponse=this.#cachedRecommendations[url];if(cachedResponse&&cachedResponse.data?.length>0){this.#renderRecommendations(cachedResponse);return}const response=await fetch(url,{signal:controller.signal});if(response.ok){const data=await response.json();if(data.data&&data.data.length>0){this.#cachedRecommendations[url]=data,this.#renderRecommendations(data);return}}}this.#handleError(new Error("No recommendations returned for any product in the cart"))}catch(error){if(error.name==="AbortError")return;this.#handleError(error)}finally{this.#activeFetch=null}}async#renderRecommendations(data){const products=data.data||[];if(products.length===0){this.#handleError(new Error("No recommendations returned from Rebuy"));return}const productIds=products.map(product=>product.id),searchQuery=productIds.map(id=>`id:${id}`).join(" OR "),sectionId=this.dataset.sectionId,url=new URL(Theme.routes.predictive_search_url,window.location.origin);url.searchParams.set("q",searchQuery),url.searchParams.set("resources[type]","product"),url.searchParams.set("resources[limit]",String(Math.min(productIds.length,10)));try{const htmlText=await sectionRenderer.getSectionHTML(sectionId,!1,url),newSection=new DOMParser().parseFromString(htmlText,"text/html").querySelector(`bbd-rebuy-crosssells[id="${this.id}"]`);newSection&&newSection.innerHTML.trim().length?(this.innerHTML=newSection.innerHTML,this.dataset.recommendationsPerformed="true",new IntersectionObserver((entries,obs)=>{entries[0]?.isIntersecting&&(obs.disconnect(),this.dispatchEvent(new CustomEvent("datalayer:list-ready",{bubbles:!0,detail:{container:this}})))},{rootMargin:"0px 0px 200px 0px"}).observe(this)):this.#handleError(new Error("Failed to render recommendations HTML"))}catch(error){this.#handleError(error)}}#handleError(error){console.error("BBD Rebuy Cross Sells error:",error.message),this.classList.add("hidden"),this.dataset.error="Error loading Rebuy recommendations"}}customElements.get("bbd-rebuy-crosssells")||customElements.define("bbd-rebuy-crosssells",BbdRebuyCrosssells);
2//# sourceMappingURL=/cdn/shop/t/3/assets/bbd-rebuy-crosssells.js.map?v=33976329341440041011777531581

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.