PageSourceSearch

https://www.lazylama.nl/cdn/shop/t/4/assets/cart-add.js?v=154047369692517369791790936249

js lazylama.nl collected 2026-10-07 18:55:32 UTC 3,177 bytes, 2 lines download raw bytes

1import{CartLinesUpdateEvent}from"@shopify/events";import{eanOfControl,setEanOnFormData}from"@theme/ean-property";const SHOP_ROOT=window.Shopify?.routes?.root??"/",readCart=async()=>{const response=await fetch(`${SHOP_ROOT}cart.js`,{headers:{Accept:"application/json"}});if(!response.ok)throw new Error("Cart read failed");return response.json()};export class MaxQuantityError extends Error{}let lastLimitedAdd=Promise.resolve();export const addWithinMax=({productId,maxQuantity,quantity,lineKey},post)=>{if(!maxQuantity)return post();const run=lastLimitedAdd.then(async()=>{let cart;try{cart=await readCart()}catch{throw new MaxQuantityError("We konden je winkelwagen niet controleren. Probeer het opnieuw.")}const lines=(cart.items??[]).filter(item=>item.product_id===productId),current=lineKey?lines.find(item=>item.key===lineKey)?.quantity??0:0,inCart=lines.reduce((sum,item)=>sum+item.quantity,0)-current;if(quantity>current&&inCart+quantity>maxQuantity)throw new MaxQuantityError(inCart>=maxQuantity?`Maximaal ${maxQuantity} per bestelling: dit zit al in je winkelwagen.`:`Maximaal ${maxQuantity} per bestelling: je hebt er al ${inCart} in je winkelwagen.`);return post()});return lastLimitedAdd=run.catch(()=>{}),run},addToCart=async(form,{submitter=null,source="gift-lists"}={})=>{const formData=new FormData(form);submitter instanceof HTMLButtonElement&&submitter.name&&formData.set(submitter.name,submitter.value);const eanControl=submitter?.dataset.ean!=null?submitter:form.querySelector('select[name="id"]');eanControl&&setEanOnFormData(formData,eanOfControl(eanControl));const sectionIds=Array.from(document.querySelectorAll("cart-items-component")).map(item=>item.dataset.sectionId).filter(Boolean);sectionIds.length>0&&(formData.append("sections",sectionIds.join(",")),formData.append("sections_url",window.location.pathname));const limit={productId:Number(form.dataset.productId),maxQuantity:Number(form.dataset.maxQuantity)||0,quantity:Number(formData.get("quantity"))||1};let response,added;try{({response,added}=await addWithinMax(limit,async()=>{const posted=await fetch(`${SHOP_ROOT}cart/add.js`,{method:"POST",headers:{Accept:"application/json","X-Requested-With":"XMLHttpRequest"},body:formData});return{response:posted,added:await posted.json()}}))}catch(error){if(error instanceof MaxQuantityError)throw error;return window.location.assign(`${SHOP_ROOT}cart`),{redirect:!0}}if(added?.status)throw new Error(added.description||added.message||"Dit product kan niet worden toegevoegd.");if(!response.ok)return window.location.assign(`${SHOP_ROOT}cart`),{redirect:!0};try{const cart=await readCart(),deferred=CartLinesUpdateEvent.createPromise();return form.dispatchEvent(new CartLinesUpdateEvent({action:"add",context:"product",lines:[{merchandiseId:String(formData.get("id")),quantity:1}],promise:deferred.promise})),deferred.resolve({cart:CartLinesUpdateEvent.createCartFromAjaxResponse(cart),detail:{items:cart.items,source,itemCount:1,sections:added.sections,didError:!1}}),{redirect:!1}}catch{return window.location.assign(`${SHOP_ROOT}cart`),{redirect:!0}}};
2//# sourceMappingURL=/cdn/shop/t/4/assets/cart-add.js.map?v=154047369692517369791790936249

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.