FileMaster
Search
Toggle Dark Mode
Home
/
.
/
wp-content
/
plugins
/
surecart
/
dist
/
components
/
components
Edit File: sc-checkout-stock-alert2.js
import{proxyCustomElement,HTMLElement,createEvent,h,Host}from"@stencil/core/internal/client";import{s as state}from"./mutations2.js";import{c as updateCheckout}from"./index4.js";import{c as currentFormState}from"./getters3.js";import{d as defineCustomElement$c}from"./sc-alert2.js";import{d as defineCustomElement$b}from"./sc-block-ui2.js";import{d as defineCustomElement$a}from"./sc-button2.js";import{d as defineCustomElement$9}from"./sc-card2.js";import{d as defineCustomElement$8}from"./sc-dashboard-module2.js";import{d as defineCustomElement$7}from"./sc-dialog2.js";import{d as defineCustomElement$6}from"./sc-flex2.js";import{d as defineCustomElement$5}from"./sc-icon2.js";import{d as defineCustomElement$4}from"./sc-spinner2.js";import{d as defineCustomElement$3}from"./sc-table2.js";import{d as defineCustomElement$2}from"./sc-table-cell2.js";import{d as defineCustomElement$1}from"./sc-table-row2.js";const scCheckoutStockAlertCss=":host{display:block}sc-table{height:auto}h4{display:block;margin:0;font-weight:var(--sc-font-weight-bold);font-size:var(--sc-font-size-medium)}.stock-alert{--body-spacing:var(--sc-spacing-x-large);--width:500px}.stock-alert__image{width:50px;height:50px;object-fit:cover;margin-right:10px;display:block}.stock-alert__product-info{display:flex;flex-direction:column;gap:var(--sc-spacing-xx-small)}.stock-alert__variant{color:var(--sc-color-gray-500);font-size:var(--sc-font-size-small)}.stock-alert__quantity{color:var(--sc-color-gray-500);font-weight:var(--sc-font-weight-bold);display:flex;align-items:center;justify-content:flex-end;gap:var(--sc-spacing-xx-small)}",ScCheckoutStockAlertStyle0=scCheckoutStockAlertCss,ScCheckoutStockAlert=proxyCustomElement(class extends HTMLElement{constructor(){super(),this.__registerHost(),this.__attachShadow(),this.scUpdateLineItem=createEvent(this,"scUpdateLineItem",7),this.stockErrors=[],this.busy=void 0,this.error=void 0}getOutOfStockLineItems(){var t,e;return((null===(e=null===(t=state.checkout)||void 0===t?void 0:t.line_items)||void 0===e?void 0:e.data)||[]).filter((t=>{var e,s,o;const a=null===(e=t.price)||void 0===e?void 0:e.product;return"out_of_stock"===(null==t?void 0:t.purchasable_status)&&((null===(s=null==t?void 0:t.variant)||void 0===s?void 0:s.id)?(null===(o=null==t?void 0:t.variant)||void 0===o?void 0:o.available_stock)<t.quantity:(null==a?void 0:a.available_stock)<t.quantity)}))}getStockAdjustedLineItems(){var t,e;const s=new Map;return this.getOutOfStockLineItems().forEach((t=>{var e,o,a;const l=null===(e=t.price)||void 0===e?void 0:e.product,i=(null===(o=null==t?void 0:t.variant)||void 0===o?void 0:o.id)?Math.max((null===(a=null==t?void 0:t.variant)||void 0===a?void 0:a.available_stock)||0,0):Math.max((null==l?void 0:l.available_stock)||0,0);s.set(t.id,i)})),((null===(e=null===(t=state.checkout)||void 0===t?void 0:t.line_items)||void 0===e?void 0:e.data)||[]).map((t=>{var e,o;const a=s.get(t.id);return{id:t.id,price_id:null===(e=t.price)||void 0===e?void 0:e.id,quantity:void 0!==a?a:t.quantity,...(null===(o=null==t?void 0:t.variant)||void 0===o?void 0:o.id)?{variant:t.variant.id}:{}}}))}async onSubmit(){try{this.busy=!0,state.checkout=await updateCheckout({id:state.checkout.id,data:{line_items:this.getStockAdjustedLineItems().filter((t=>!!t.quantity))}})}catch(t){const e=((null==t?void 0:t.additional_errors)||[]).map((t=>null==t?void 0:t.message)).filter((t=>t));this.error=`${(null==t?void 0:t.message)||wp.i18n.__("Something went wrong.","surecart")} ${(null==e?void 0:e.length)&&` ${e.join(". ")}`}`}finally{this.busy=!1}}render(){const t=(this.getOutOfStockLineItems()||[]).map((t=>{var e,s,o;const a=null===(e=t.price)||void 0===e?void 0:e.product,l=(null===(s=null==t?void 0:t.variant)||void 0===s?void 0:s.id)?null===(o=null==t?void 0:t.variant)||void 0===o?void 0:o.available_stock:null==a?void 0:a.available_stock;return{name:null==a?void 0:a.name,variant:null==t?void 0:t.variant_display_options,image:null==t?void 0:t.image,quantity:t.quantity,available_stock:l}})),e=null==t?void 0:t.some((t=>(null==t?void 0:t.available_stock)<1));return h(Host,null,h("sc-dialog",{open:!!t.length&&"draft"===currentFormState(),noHeader:!0,onScRequestClose:t=>t.preventDefault(),class:"stock-alert"},h("sc-dashboard-module",{class:"subscription-cancel",error:this.error,style:{"--sc-dashboard-module-spacing":"1em"}},h("sc-flex",{slot:"heading","align-items":"center","justify-content":"flex-start"},h("sc-icon",{name:"alert-circle",style:{color:"var(--sc-color-primary-500"}}),e?wp.i18n.__("Out of Stock","surecart"):wp.i18n.__("Quantity Update","surecart")),h("span",{slot:"description"},e?wp.i18n.__("Some items are no longer available. Your cart will be updated.","surecart"):wp.i18n.__("Available quantities for these items have changed. Your cart will be updated.","surecart")),h("sc-card",{"no-padding":!0},h("sc-table",null,h("sc-table-cell",{slot:"head"},wp.i18n.__("Description","surecart")),h("sc-table-cell",{slot:"head",style:{width:"100px",textAlign:"right"}},wp.i18n.__("Quantity","surecart")),t.map(((e,s)=>{const o=s===t.length-1;return h("sc-table-row",{style:{"--columns":"2",...o?{border:"none"}:{}}},h("sc-table-cell",null,h("sc-flex",{justifyContent:"flex-start",alignItems:"center"},(null==e?void 0:e.image)&&h("img",{...e.image,class:"stock-alert__image"}),h("div",{class:"stock-alert__product-info"},h("h4",null,e.name),(null==e?void 0:e.variant)&&h("span",{class:"stock-alert__variant"},e.variant)))),h("sc-table-cell",{style:{width:"100px",textAlign:"right"}},h("span",{class:"stock-alert__quantity"},h("span",null,null==e?void 0:e.quantity)," ",h("sc-icon",{name:"arrow-right"})," ",h("span",null,Math.max(null==e?void 0:e.available_stock,0)))))}))))),h("sc-button",{slot:"footer",type:"primary",loading:this.busy,onClick:()=>this.onSubmit()},wp.i18n.__("Continue","surecart"),h("sc-icon",{name:"arrow-right",slot:"suffix"})),this.busy&&h("sc-block-ui",{spinner:!0})))}static get style(){return ScCheckoutStockAlertStyle0}},[1,"sc-checkout-stock-alert",{stockErrors:[32],busy:[32],error:[32]}]);function defineCustomElement(){"undefined"!=typeof customElements&&["sc-checkout-stock-alert","sc-alert","sc-block-ui","sc-button","sc-card","sc-dashboard-module","sc-dialog","sc-flex","sc-icon","sc-spinner","sc-table","sc-table-cell","sc-table-row"].forEach((t=>{switch(t){case"sc-checkout-stock-alert":customElements.get(t)||customElements.define(t,ScCheckoutStockAlert);break;case"sc-alert":customElements.get(t)||defineCustomElement$c();break;case"sc-block-ui":customElements.get(t)||defineCustomElement$b();break;case"sc-button":customElements.get(t)||defineCustomElement$a();break;case"sc-card":customElements.get(t)||defineCustomElement$9();break;case"sc-dashboard-module":customElements.get(t)||defineCustomElement$8();break;case"sc-dialog":customElements.get(t)||defineCustomElement$7();break;case"sc-flex":customElements.get(t)||defineCustomElement$6();break;case"sc-icon":customElements.get(t)||defineCustomElement$5();break;case"sc-spinner":customElements.get(t)||defineCustomElement$4();break;case"sc-table":customElements.get(t)||defineCustomElement$3();break;case"sc-table-cell":customElements.get(t)||defineCustomElement$2();break;case"sc-table-row":customElements.get(t)||defineCustomElement$1()}}))}export{ScCheckoutStockAlert as S,defineCustomElement as d};
Save
Back