PluginProbe ʕ •ᴥ•ʔ
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 4.6.3
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v4.6.3
4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.11.0 1.11.1 1.11.2 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.9.0 1.9.1 1.9.2 1.9.3 1.9.4 1.9.5 2.0.0 2.0.1 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.10.0 2.10.1 2.11.0 2.11.1 2.11.2 2.11.3 2.11.4 2.12.0 2.13.0 2.14.0 2.14.1 2.15.0 2.15.1 2.16.0 2.16.1 2.16.2 2.16.3 2.17.0 2.17.1 2.17.2 2.18.0 2.19.0 2.19.2 2.19.3 2.19.4 2.2.0 2.2.1 2.20.0 2.20.1 2.20.2 2.20.3 2.20.4 2.20.5 2.20.6 2.21.0 2.22.0 2.22.1 2.23.0 2.24.0 2.25.0 2.25.1 2.25.2 2.26.0 2.27.0 2.27.1 2.28.0 2.29.0 2.29.1 2.29.2 2.29.3 2.29.4 2.3.0 2.3.1 2.30.0 2.31.0 2.31.1 2.31.2 2.31.3 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.40.0 2.40.1 2.5.0 2.5.1 2.5.2 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.9.0 3.0.0 3.0.0-RC1 3.0.0-RC2 3.0.0-beta1 3.0.0-beta2 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.10.0 3.10.1 3.11.0 3.12.0 3.13.0 3.13.1 3.13.2 3.13.3 3.13.4 3.14.0 3.15.0 3.15.1 3.15.2 3.15.3 3.15.4 3.15.5 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.16.6 3.16.7 3.16.8 3.17.0 3.17.1 3.17.2 3.17.3 3.17.4 3.17.5 3.17.6 3.18.0 3.19.0 3.19.1 3.19.2 3.2.0 3.2.1 3.2.2 3.20.0 3.20.1 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 4.0.0 4.0.1 4.0.2 4.0.3 trunk 4.1.0 0.2.19.1 4.1.1 1.0.0 4.2.0 1.0.1 1.0.2
surecart / packages / blocks-next / build / scripts / product-page / index.js
surecart / packages / blocks-next / build / scripts / product-page Last commit date
index.asset.php 1 month ago index.js 1 month ago
index.js
2 lines
1 import*as t from"@wordpress/interactivity";var e={660:function(t,e,n){function o(t,e){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;const o=new CustomEvent("scProductViewed",{detail:{id:t?.id,name:t?.name,price:e,permalink:t?.permalink,prices:t?.prices,variant_options:t?.variant_options?.data,product_collections:t?.product_collections,quantity:n},bubbles:!0});document.dispatchEvent(o)}n.r(e),n.d(e,{scProductViewed:function(){return o}})}},n={};function o(t){var i=n[t];if(void 0!==i)return i.exports;var a=n[t]={exports:{}};return e[t](a,a.exports,o),a.exports}o.d=function(t,e){for(var n in e)o.o(e,n)&&!o.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var i={};!function(){o.d(i,{O:function(){return s},M:function(){return c}});var e,n,a=(e={getContext:function(){return t.getContext},getElement:function(){return t.getElement},store:function(){return t.store},withSyncEvent:function(){return t.withSyncEvent}},n={},o.d(n,e),n);const r=(t,e)=>t?.has_unlimited_stock??e?.has_unlimited_stock??!1,s=t=>{let{variants:e,values:n}=t;const o=Object.keys(n||{});for(const t of e){const e=["option_1","option_2","option_3"].map((e=>t[e])).filter((t=>null!=t));if(e?.length===o?.length&&o.every((e=>t[e]===n[e])))return t}return null},c=function(t,e,n){let o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[],i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,a=arguments.length>5&&void 0!==arguments[5]&&arguments[5];const s=t=>r(t,i)?1/0:t.available_stock,c=t=>t.length?Math.max(...t.map(s))<=0:a;if(1===t){const t=(o||[]).filter?.((t=>t.option_1===e));return c(t)}return c(2===t?(o||[]).filter((t=>t?.option_1===n.option_1&&t.option_2===e)):(o||[]).filter((t=>t?.option_1===n.option_1&&t?.option_2===n.option_2&&t.option_3===e)))},u=t=>{const e=t?.urlPrefix?`${t.urlPrefix}-`:"";if(t?.componentProductId){const n=!!t.componentHasUnlimitedStock;return{values:t.componentOptionValues||{},variants:t.componentVariants||[],product:{has_unlimited_stock:n},missingMeansUnavailable:!n,commit(e,n){t.componentOptionValues||(t.componentOptionValues={}),t.componentOptionValues[`option_${e}`]=n,t.bundleComponentVariants||(t.bundleComponentVariants={});const o=s({variants:t.componentVariants||[],values:t.componentOptionValues});o?.id?t.bundleComponentVariants[t.componentProductId]=o.id:delete t.bundleComponentVariants[t.componentProductId]},urlKey:n=>`${e}bundle-${t.componentProductSlug||t.componentProductId}-${n}`}}return{values:t?.variantValues||{},variants:t?.variants||[],product:t?.product||null,missingMeansUnavailable:!1,commit(e,n){t.variantValues||(t.variantValues={}),t.variantValues[`option_${e}`]=n,t.product?.id&&document.dispatchEvent(new CustomEvent("scVariantValuesUpdated",{detail:{productId:t.product.id,variantValues:{...t.variantValues}}}))},urlKey:t=>`${e}${t}`}},{actions:l}=(0,a.store)("surecart/checkout"),{actions:d,state:p}=(0,a.store)("surecart/cart"),{addQueryArgs:m}=wp.url,{sprintf:g,__}=wp.i18n,{scProductViewed:v}=o(660),y=t=>"keydown"===t.type&&"Enter"!==t.key&&"Space"!==t.code,{state:f,actions:b}=(0,a.store)("surecart/product-page",{state:{get quantity(){const{selectedPrice:t,quantity:e}=(0,a.getContext)();return t?.ad_hoc?1:e},get selectedAmount(){const t=(0,a.getContext)();if(!t)return!0;const{selectedPrice:e,prices:n}=t;return n?.length>1?e?.amount||"":f.selectedVariant?.amount||e?.amount||""},get selectedDisplayAmount(){const{prices:t,selectedPrice:e}=(0,a.getContext)();return t?.length>1?e?.display_amount||"":f.selectedVariant?.display_amount||e?.display_amount||""},get selectedVariant(){const t=(0,a.getContext)();if(!t)return{};const{variants:e,variantValues:n}=t;return n?s({variants:e,values:n||{}}):{}},get selectedVariantImage(){const t=(0,a.getContext)();if(!t)return{};const e=f.selectedVariant?.line_item_image?.src?f.selectedVariant.line_item_image:t.product?.preview_image||{};return{...e,src:e?.["data-src"]||e?.src,srcset:e?.["data-srcset"]||e?.srcset,sizes:e?.["data-sizes"]||e?.sizes}},get isOnSale(){const t=(0,a.getContext)();if(!t)return!0;const{selectedPrice:e}=t;return e?.is_on_sale||!1},get isOptionUnavailable(){const t=(0,a.getContext)();if(!t)return!0;const{optionNumber:e,option_value:n}=t,o=u(t);return c(parseInt(e),n,o.values,o.variants,o.product,o.missingMeansUnavailable)},get isOptionSelected(){const t=(0,a.getContext)();if(!t)return!0;const{optionNumber:e,option_value:n}=t,{values:o}=u(t);return o?.[`option_${e}`]===n},get isOptionValueSelected(){const t=(0,a.getContext)();if(!t)return!0;const{optionValue:e,variantValues:n}=t;return!e||Object.values(n).map((t=>t.toLowerCase())).includes(e.toLowerCase())},get shouldDisplayImage(){const t=(0,a.getContext)();if(!t)return!0;const{variants:e}=t;return!e?.length||f.isOptionValueSelected},get imageDisplay(){return f.shouldDisplayImage?"initial":"none"},get isPriceSelected(){const t=(0,a.getContext)();if(!t)return!0;const{price:e,selectedPrice:n}=t;return n?.id===e?.id},get checkoutUrl(){const{checkoutUrl:t}=(0,a.getContext)();return m(t,{line_items:[f.lineItem],no_cart:!0})},get buttonText(){const t=(0,a.getContext)();if(!t)return!0;const{buttonText:e,outOfStockText:n,unavailableText:o,selectComponentOptionsText:i}=t;return f.isSoldOut||f.isBundleComponentSoldOut?n:f.isBundleIncomplete?i||e:f.isUnavailable?o:e},get isUnavailable(){const t=(0,a.getContext)();if(!t)return!0;const{product:e,variants:n}=t;return!(!e?.archived&&!f?.isSoldOut&&(!n?.length||f.selectedVariant?.id)&&!f.isBundleIncomplete&&!f.isBundleComponentSoldOut)},get isBundleIncomplete(){const t=(0,a.getContext)();if(!t)return!1;const e=t.bundleVariableComponentIds||[];if(!e.length)return!1;const n=t.bundleComponentVariants||{};return e.some((t=>!n?.[t]))},get isBundleComponentSoldOut(){const t=(0,a.getContext)();return!!t&&(e=t.bundleComponents,n=t.bundleComponentVariants,Object.entries(e||{}).some((t=>{let[e,o]=t;if(!o)return!1;const i=o.variants||[];if(i.length){const t=(n||{})[e];if(!t)return!1;const a=i.find((e=>e.id===t));return!a||!r(a,o)&&(a.available_stock||0)<=0}return!o.has_unlimited_stock&&(o.available_stock||0)<=0})));var e,n},get isSoldOut(){const t=(0,a.getContext)();if(!t)return!0;const{product:e}=t;return f.selectedVariant?.id?!r(f.selectedVariant,e)&&f.selectedVariant.available_stock<=0:!e?.has_unlimited_stock&&e?.available_stock<=0},get lineItem(){const{adHocAmount:t,selectedPrice:e,note:n,noteLabel:o,bundleComponentVariants:i}=(0,a.getContext)(),r=Object.entries(i||{}).reduce(((t,e)=>{let[n,o]=e;return o&&(t[n]=o),t}),{});return{price:e?.id,quantity:Math.max(e?.ad_hoc?1:f.quantity,1),...e?.ad_hoc?{ad_hoc_amount:e?.is_zero_decimal?t:100*t}:{},note:o&&n?`${o}: ${n}`:n||"",...f.selectedVariant?.id?{variant:f.selectedVariant?.id}:{},...Object.keys(r).length?{bundle_component_variants:r}:{}}},get disabled(){const{selectedPrice:t,product:e}=(0,a.getContext)();return t?.archived||e?.archived},get isQuantityDisabled(){const{selectedPrice:t}=(0,a.getContext)();return!!t?.ad_hoc},get isQuantityIncreaseDisabled(){return f.isQuantityDisabled},get isQuantityDecreaseDisabled(){return f.isQuantityDisabled||f.quantity<=1}},actions:{*addToCart(t){const e=Object.values(t.submitter.dataset).includes("context.busy");!e&&d.open();const n=(0,a.getContext)(),{mode:o,formId:i,product:r}=n;try{n.busy=!0;const{addCheckoutLineItem:t}=yield import("@surecart/checkout-service"),a=yield*t(f.lineItem);l.setCheckout(a,o,i),e&&d.open(),p.label=g(/* translators: %s: product name */
2 __("%s has been added to your cart.","surecart"),r?.name)}catch(t){console.error(t)}finally{n.busy=!1}}},callbacks:{*init(){(window?.dataLayer||window?.gtag)&&(yield import("@surecart/google-events")),window?.fbq&&!1!==window?.scData?.facebook_tracking_enabled&&(yield import("@surecart/facebook-events"));const{selectedPrice:t,product:e}=(0,a.getContext)();v(e,t,f.quantity)},handleSubmit:(0,a.withSyncEvent)((function*(t){if("keydown"===t.type&&"Enter"!==t.key)return!0;if(t.preventDefault(),t.stopPropagation(),!t.submitter){const{ref:e}=(0,a.getElement)();e&&(t.submitter=e)}return t?.submitter?.value?window.location.assign(t.submitter.value):yield b.addToCart(t)})),setOption:(0,a.withSyncEvent)((t=>{if(y(t))return!0;t.preventDefault();const e=(0,a.getContext)(),n=t?.target?.selectedOptions?.[0]?.dataset?.wpContext?JSON.parse(t.target.selectedOptions[0].dataset.wpContext):e,{option_value:o,option_name:i,option_value_slug:r,option_name_slug:s}=n,c=o||t?.target?.value,l=u(e);l.commit(e.optionNumber,c),o&&i&&window.history.replaceState({},"",m(window.location.href,{[l.urlKey(s)]:r}))})),setPrice:(0,a.withSyncEvent)((t=>{if(y(t))return!0;t?.preventDefault();const e=(0,a.getContext)(),{price:n,prices:o}=e,i=(o||[]).find((t=>t.id===n?.id));e.selectedPrice=i,e.adHocAmount=null})),setAdHocAmount:t=>{(0,a.getContext)().adHocAmount=parseFloat(t.target.value)},setLineItemNote:t=>{const e=(0,a.getContext)();e.note=t.target.value||"",e.noteLabel=e.label||""},expandLineItemNote:t=>{(0,a.getContext)().rows=3},redirectToCheckout:(0,a.withSyncEvent)((t=>{t?.preventDefault();const e=t?.target?.closest("form");e&&!e.checkValidity()?e.reportValidity():window.location.assign(f.checkoutUrl)})),onQuantityChange:function*(t){const e=(0,a.getContext)();e.quantity=Math.max(parseInt(t.target.value),1);const{speak:n}=yield import("@wordpress/a11y");n(`Quantity set to ${e.quantity}`,"polite")},onQuantityDecrease:(0,a.withSyncEvent)((function*(t){if(y(t))return!0;t?.preventDefault();const e=(0,a.getContext)();if(f.isQuantityDisabled)return;e.quantity=Math.max(1,f.quantity-1);const{speak:n}=yield import("@wordpress/a11y");n(`Quantity set to ${e.quantity}`,"polite")})),onQuantityIncrease:(0,a.withSyncEvent)((function*(t){if(y(t))return!0;t?.preventDefault();const e=(0,a.getContext)();e.quantity=f.quantity+1;const{speak:n}=yield import("@wordpress/a11y");n(`Quantity set to ${e.quantity}`,"polite")}))}})}();var a=i.O,r=i.M;export{a as getVariantFromValues,r as isProductVariantOptionSoldOut};