PageSourceSearch

https://pastelierdreams.pl/application/assets/storefront/chunk-product_shipping_prices_initializer.COkqj3-.js

js pastelierdreams.pl collected 2026-10-08 07:35:46 UTC 21,259 bytes, 80 lines download raw bytes

1import{bf as c,b as K,c as $,l as z,s as H,w as x,L as k,T as V,bg as y,bh as j,S as Q}from"./storefrontApp.DHj_rTVq.min.js";import{U as f,e as d,t as w,n as D,w as B,$ as I}from"./chunk-vendor-lit.NvY0u02.js";import{S as M}from"./chunk-storefront_base_lit_element.BDgKmPq.js";import{n as X}from"./chunk-vendor-lodash.CWHFt7Z.js";import{e as A,m}from"./chunk-vendor-rxjs.Dp7kflo.js";import{w as O,g as Y,s as R,c as L}from"./chunk-index.esm.nYUWi4A.js";import{P as Z}from"./chunk-product_stock_changed_handler.Cxrl8lM.js";import{S as q}from"./chunk-storefront_settings_constants.DIF02Gz.js";import{S as ii,P as ti,e as ei}from"./chunk-product_stock_mapper.CQEvmPB.js";import{t as F}from"./chunk-translations_directive.DFKTlKG.js";import{o as si}from"./chunk-observable_directive.eGckMWP.js";import"./chunk-vendor-di.Bh23gdA.js";import"./chunk-vendor-phoenix.cdKS79L.js";import"./chunk-product_events_constants.BHFu5GP.js";import"./chunk-price_mapper.C8-oiM4.js";import"./chunk-product_code_mapper.BkpvZKV.js";import"./chunk-loyalty_points_mapper.CnpZkby.js";class ni{constructor({host:i,productId:t,translationApi:s,productShippingPricesService:n}){this._calculateLowestShippingInfo=(r,p)=>{const o=r.filter(l=>{const a=p.find(u=>u.shippingId===l.shippingId);return a&&a.engine!=="personal"});return X(o,"cost.float")||r[0]},this._updateShippingPricesMethod=(r,p)=>{let o="";p&&(o=p.isPersonalCollect?"Pick up in person":"Shipping"),this._updateShippingPriceContent(r,this._translationApi.translate(o))},this._updateShippingPricesInfo=({$singleShippingPricesInfo:r,$multipleShippingPricesInfo:p,shippingDetails:o})=>{if(!o){this._hideShippingPricesInfo([r,p]);return}this._toggleMultipleShippingPricesInfo(o.hasMultipleShippings,r,p);const l=o.hasMultipleShippings?p:r;l&&this._updateShippingPriceContent(l,this._getShippingPricesInfo(o))},this.#i=i,this.productId=t,this._translationApi=s,this._productShippingPricesService=n,this.#i.addController(this)}#i;hostConnected(){this._productShippingPricesService.selectShippingOptions$().subscribe(i=>{i&&this._updateShippingPrices(i)})}_updateShippingPrices(i){const t=this._getShippingDetails(i);if(i.availableShippings.length!==0)f.show(this.#i);else{f.hide(this.#i);return}const{$shippingPricesMethod:n,$singleShippingPricesInfo:r,$multipleShippingPricesInfo:p,$shippingPricesDescription:o}=this._getShippingPricesElements();n&&this._updateShippingPricesMethod(n,t),(r||p)&&this._updateShippingPricesInfo({$singleShippingPricesInfo:r,$multipleShippingPricesInfo:p,shippingDetails:t}),o&&this._updateShippingPriceContent(o,t?.lowestShippingInfo?.description||"")}_getShippingDetails({availableCountries:i,availableShippings:t,shippingsInCountries:s}){const n=this._productShippingPricesService.getDefaultCountryIfAvailable(),r=this._productShippingPricesService.getCurrentCountry(),p=this._getShippingCountryName(n,i),o=this._getLowestShippingCosts({shippingsInCountries:s,defaultCountry:n,availableCountries:i,availableShippings:t}),l=this._getLowestShippingInfo(t,o),a=this._getIsPersonalCollect(l),u=this._getDoesShipToMultipleCountries(i),g=this._getHasMultipleShippings(i,s),N=this._getIsDefaultCountryACurrentCountry(n,r);return{shippingCountryName:p,lowestShippingCosts:o,lowestShippingInfo:l,isPersonalCollect:a,doesShipToMultipleCountries:u,hasMultipleShippings:g,isDefaultCountryACurrentCountry:N}}_getShippingCountryName(i,t){const s=t[0]?.countryName;return i?.name||s}_getLowestShippingCosts({availableCountries:i,defaultCountry:t,shippingsInCountries:s,availableShippings:n}){const r=i.find(g=>g.countryId===String(t?.id)),p=i[0],o=r||p;if(o.shippingWithLowestCost){const g=o.shippingWithLowestCost?.shippingId;return s.find(v=>v.countryId===o.countryId)?.shippingOptions.find(v=>v.shippingId===g)}const l=i[0]?.countryId,a=t?.id||l;if(!a)return;const u=s.find(({countryId:g})=>g===String(a));if(u)return this._calculateLowestShippingInfo(u.shippingOptions,n)}_getLowestShippingInfo(i,t){return i.find(({shippingId:s})=>s===t?.shippingId)}_getIsPersonalCollect(i){return i?.engine==="personal"}_getDoesShipToMultipleCountries(i){return i.length>1}_getHasMultipleShippings(i,t){const s=t.some(({shippingOptions:n})=>n.length>1);return this._getDoesShipToMultipleCountries(i)||s}_getIsDefaultCountryACurrentCountry(i,t){return!!i&&!!t&&i.id===t.id}_getShippingPricesElements(){const i=this.#i.querySelector(`.${c.shippingPricesContainer}`),t=this.#i.querySelector(`
2                .${c.shippingPricesContainer}
3                .${c.singleShippingInfo}
4            `),s=this.#i.querySelector(`
5                    .${c.shippingPricesContainer}
6                    .${c.multipleShippingInfo}
7                `),n=this.#i.querySelector(`
8                .${c.shippingPricesContainer}
9                .${c.shippingMethod}
10            `),r=this.#i.querySelector(`
11                .${c.shippingPricesContainer}
12                .${c.description}
13            `);return{$shippingPricesContainer:i,$singleShippingPricesInfo:t,$multipleShippingPricesInfo:s,$shippingPricesMethod:n,$shippingPricesDescription:r}}
13_hideShippingPricesInfo(i){i.forEach(t=>this._hideElement(t))}_toggleMultipleShippingPricesInfo(i,t,s){i?(this._hideElement(t),this._showElement(s)):(this._showElement(t),this._hideElement(s))}_hideElement(i){i&&f.hide(i)}_showElement(i){i&&f.show(i)}_getShippingPricesInfo(i){const{shippingCountryName:t,lowestShippingInfo:s,lowestShippingCosts:n,doesShipToMultipleCountries:r,hasMultipleShippings:p,isPersonalCollect:o,isDefaultCountryACurrentCountry:l}=i;let a="";return a+=`
14            <strong class="product-shipping-prices__shipping-info-price">
15                ${this._getShippingPricesInfoPrice({lowestShippingCosts:n,hasMultipleShippings:p,isPersonalCollect:o})}
16            </strong>
17        `,!o&&s&&(a+=` - ${s.name}`),(r||!r&&!l)&&(a+=` (${this._translationApi.translate(t)})`),a}_getShippingPricesInfoPrice({lowestShippingCosts:i,hasMultipleShippings:t,isPersonalCollect:s}){if(!i)return;if(t)return`${this._translationApi.translate("from")} ${i.cost.text}`;const n=i.cost.float===0;return n&&s?this._translationApi.translate("free <<shipping_prices personal collect>>"):n?this._translationApi.translate("free <<shipping_prices delivery>>"):`${this._translationApi.translate("from")} ${i.cost.text}`}_updateShippingPriceContent(i,t=""){i.innerHTML="",i.append(this._replaceHtmlStringWithTag(t))}_replaceHtmlStringWithTag(i){const t=document.createElement("span");return t.innerHTML=i,t.childNodes.length>1?t:i}}class ri extends K{constructor({availableCountriesRepository:i,availableShippingsRepository:t,shippingsInCountriesRepository:s,settingsApi:n}){super(),this._settingsApi=n,this._availableCountriesRepository=i,this._availableShippingsRepository=t,this._shippingsInCountriesRepository=s}getAvailableCountries(){return this._availableCountriesRepository.getAvailableCountries()}getDefaultCountry(){return this._availableCountriesRepository.getDefaultCountry()}getCurrentCountry(){return this._availableCountriesRepository.getCurrentCountry()}getDefaultCountryIfAvailable(){const i=this._availableCountriesRepository.getDefaultCountry(),t=this._availableCountriesRepository.getAvailableCountries();return i?this._findCountry(i,t):null}setAvailableCountries(i){this._availableCountriesRepository.setAvailableCountries(i)}setDefaultCountry(i){this._availableCountriesRepository.setDefaultCountry(i)}setCurrentCountry(i){if(!i){const t=this.getDefaultCountryIfAvailable();if(t){this._availableCountriesRepository.setCurrentCountry(t);return}const s=this.getAvailableCountries()[0]?.countryId,n=s?this._settingsApi.getCountryById(Number(s)):null;this._availableCountriesRepository.setCurrentCountry(n);return}this._availableCountriesRepository.setCurrentCountry(i)}setAvailableShippings(i){this._availableShippingsRepository.setAvailableShippings(i)}setShippingsInCountries(i){this._shippingsInCountriesRepository.setShippingsInCountries(i)}selectAvailableShippings$(){return this._availableShippingsRepository.selectAvailableShippings$()}selectShippingsInCountries$(){return this._shippingsInCountriesRepository.selectShippingsInCountries$()}selectAvailableCountries$(){return this._availableCountriesRepository.selectAvailableCountries$()}selectDefaultCountry$(){return this._availableCountriesRepository.selectDefaultCountry$()}selectCurrentCountry$(){return this._availableCountriesRepository.selectCurrentCountry$()}selectShippingOptions$(){return A([this.selectAvailableCountries$(),this.selectDefaultCountry$(),this.selectCurrentCountry$(),this.selectAvailableShippings$(),this.selectShippingsInCountries$()]).pipe(m(([i,t,s,n,r])=>({availableCountries:i,defaultCountry:t,currentCountry:s,availableShippings:n,shippingsInCountries:r})))}selectDefaultCountryIfAvailable$(){return A([this.selectDefaultCountry$(),this.selectAvailableCountries$()]).pipe(m(([i,t])=>i?this._findCountry(i,t):null))}_findCountry(i,t){const s=t.find(({countryId:n})=>n===String(i.id));return s?this._settingsApi.getCountryById(Number(s.countryId)):null}}const b="ProductShippingPrices",T={availableCountries:`${b}AvailableCountries`,availableShippings:`${b}AvailableShippings`,shippingsInCountries:`${b}ShippingsInCountries`},pi=()=>$({name:T.availableCountries},O({idKey:"countryId"}),z({defaultCountry:null,currentCountry:null})),oi=()=>$({name:T.availableShippings},O({idKey:"shippingId"})),ai=()=>$({name:T.shippingsInCountries},O({idKey:"countryId"}));class li{#i;constructor({availableCountriesStore:i}){this.#i=i}getDefaultCountry(){return this.#i.getValue().defaultCountry}getCurrentCountry(){return this.#i.getValue().currentCountry}getAvailableCountries(){return this.#i.query(Y())}selectAvailableCountries$(){return this.#i.pipe(R())}selectDefaultCountry$(){return this.#i.pipe(H(i=>i.defaultCountry))}selectCurrentCountry$(){return this.#i.pipe(H(i=>i.currentCountry))}setAvailableCountries(i){this.#i.update(L(i))}setDefaultCountry(i){this.#i.update(x(t=>t.defaultCountry=i))}setCurrentCountry(i){this.#i.update(x(t=>t.currentCountry=i))}}class ci{#i;constructor({availableShippingsStore:i}){this.#i=i}
17selectAvailableShippings$(){return this.#i.pipe(R())}setAvailableShippings(i){this.#i.update(L(i))}}class hi{#i;constructor({shippingsInCountriesStore:i}){this.#i=i}selectShippingsInCountries$(){return this.#i.pipe(R())}setShippingsInCountries(i){this.#i.update(L(i))}}var G;G=k;const ui=class W{constructor({country_id:i,shipping_options:t}){this[G]=!0;const s=new ii;this.countryId=i,this.shippingOptions=t.map(n=>s.toModel(n))}static create(i){return new W(i)}};let U=ui;class J{toModel(i){return U.create(i)}static parseShippingsInCountriesFromJson(i){return i?JSON.parse(i).map(n=>this._parsedShippingsInCountryToModel(n)):[]}static _parsedShippingsInCountryToModel({countryId:i,shippingCosts:t}){const s={country_id:String(i),shipping_options:t.map(({id:n,lowestCost:r,lowestCostFloat:p})=>({id:n,lowest_cost:r,lowest_cost_float:p}))};return U.create(s)}stockShippingsInCountriesToModel(i){return Object.entries(i).map(([s,n])=>({country_id:s,shipping_options:n.map(({shippingId:r,cost:p})=>({id:Number(r),lowest_cost:p.text,lowest_cost_float:p.float}))})).map(s=>this.toModel(s))}}var gi=Object.defineProperty,di=Object.getOwnPropertyDescriptor,C=(e,i,t,s)=>{for(var n=s>1?void 0:s?di(i,t):i,r=e.length-1,p;r>=0;r--)(p=e[r])&&(n=(s?p(i,t,n):p(n))||n);return s&&n&&gi(i,t,n),n};let h=class extends M{constructor(){super(),this.hasAnyVariantsChosen=!1,this._revertToDefaultShippingPrices=()=>{this.productShippingPricesService.setAvailableCountries(this.defaultCountries),this.productShippingPricesService.setAvailableShippings(this.defaultAvailableShippings),this.productShippingPricesService.setShippingsInCountries(this.defaultShippingsInCountries)},this._handleProductStockChanged=({body:e})=>{!e||e.productId!==this.productId||(this._setAvailableCountries(e.shippingOptions?.availableCountries),this.productShippingPricesService.setAvailableShippings(e.shippingOptions?.availableShippings||[]),this._setShippingsInCountries(e.shippingOptions?.shippingsInCountries),this.productShippingPricesService.setCurrentCountry(),this._setHasAnyVariantsChosen(e),this.hasAnyVariantsChosen||this._revertToDefaultShippingPrices())},this._setAvailableCountries=e=>{if(!e){this.productShippingPricesService.setAvailableCountries([]);return}const i=Object.entries(e).map(([t,s])=>({countryId:t,countryName:s}));this.productShippingPricesService.setAvailableCountries(i)},this._setShippingsInCountries=e=>{if(!e){this.productShippingPricesService.setShippingsInCountries([]);return}const t=new J().stockShippingsInCountriesToModel(e);this.productShippingPricesService.setShippingsInCountries(t)},this._productShippingPricesSetup()}async _productShippingPricesSetup(){this._settingsApi=this.getApiSync(q.api),this.productShippingPricesService=this._getProductShippingPricesService(),this._translationApi=await this.getApi(V.api),this._productShippingPricesController=new ni({host:this,productId:this.productId,translationApi:this._translationApi,productShippingPricesService:this.productShippingPricesService})}_getProductShippingPricesService(){const e=pi(),i=new li({availableCountriesStore:e}),t=oi(),s=new ci({availableShippingsStore:t}),n=ai(),r=new hi({shippingsInCountriesStore:n});return new ri({availableCountriesRepository:i,availableShippingsRepository:s,shippingsInCountriesRepository:r,settingsApi:this._settingsApi})}connectedCallback(){super.connectedCallback(),this.hasAnyVariantsChosen||this._revertToDefaultShippingPrices()}firstUpdated(e){super.firstUpdated(e),new Z(this._handleProductStockChanged)}_setHasAnyVariantsChosen(e){this.hasAnyVariantsChosen=!!e.optionValues&&e.optionValues.length>0}};h.moduleName=y.component;C([d({type:Number,attribute:"product-id"})],h.prototype,"productId",2);C([d({attribute:"default-countries",converter:e=>ti.parseAvailableCountriesFromJson(e)})],h.prototype,"defaultCountries",2);C([d({attribute:"default-available-shippings",converter:e=>ei.parseProductStockShippingsFromJson(e)})],h.prototype,"defaultAvailableShippings",2);C([d({attribute:"default-shippings-in-countries",converter:e=>J.parseShippingsInCountriesFromJson(e)})],h.prototype,"defaultShippingsInCountries",2);C([w()],h.prototype,"hasAnyVariantsChosen",2);h=C([D(y.component)],h);var Si=Object.defineProperty,Ci=Object.getOwnPropertyDescriptor,E=(e,i,t,s)=>{for(var n=s>1?void 0:s?Ci(i,t):i,r=e.length-1,p;r>=0;r--)(p=e[r])&&(n=(s?p(i,t,n):p(n))||n);return s&&n&&Si(i,t,n),n};let _=class extends M{constructor(){super(),this.defaultCountryLocale=null,this._countriesList$=null,this._getCountriesList$=()=>{const e=this._$productShippingPrices.productShippingPricesService.selectAvailableCountries$(),i=this._$productShippingPrices.productShippingPricesService.selectDefaultCountryIfAvailable$(),t=this._$productShippingPrices.productShippingPricesService.selectCurrentCountry$();return A([e,i,t]).pipe(m(([s,n,r])=>{const p=r||n;return s.map(({countryId:o,countryName:l},a)=>
17({value:o,content:l,selected:p?o===p?.id.toString():a===0}))}))},this._handleChange=e=>{const{selectedOptions:i}=e.target,t=i[0];if(!t)return;const s=this._settingsApi.getCountryById(Number(t.value));this._$productShippingPrices.productShippingPricesService.setCurrentCountry(s)},this._$productShippingPrices=this._getProductShippingPricesParent(),this._settingsApi=this.getApiSync(q.api),this._settingsApi.selectLocales$().subscribe(({locale:e})=>{this.defaultCountryLocale=new j(e)})}_getProductShippingPricesParent(){const e=this.closest(y.component);if(!e)throw Error("Missing product-shipping-prices parent");return e}firstUpdated(e){super.firstUpdated(e),this._countriesList$=this._getCountriesList$();const i=this._settingsApi.getCountryByCode(this.defaultCountryLocale?.getLocaleRegion()||"");this._$productShippingPrices.productShippingPricesService.setDefaultCountry(i),this._$productShippingPrices.productShippingPricesService.setCurrentCountry(),this._$productShippingPrices.productShippingPricesService.selectAvailableCountries$().subscribe(t=>{this.hidden=t.length===1})}render(){return this._countriesList$?I`
18            <div class="select-shipping-prices control">
19                <div class="control__label">
20                    <label
21                        class="label"
22                        id="select-shipping-prices_${this.instanceId}-label"
23                        >${F("Country of delivery")}</label
24                    >
25                </div>
26
27                <div class="control__content">
28                    <div class="control__element">
29                        <h-select
30                            class="select-shipping-prices__select select"
31                            .optionsList="${si(this._countriesList$)}"
32                            id="select-shipping-prices_${this.instanceId}"
33                            control-id="select-shipping-prices_${this.instanceId}"
34                            control-name="select-shipping-prices_${this.instanceId}"
35                            @change=${this._handleChange}
36                            no-deselect
37                            assistive-title-id="select-shipping-prices_${this.instanceId}-label"
38                        >
39                            <h-select-toggler
40                                class="select-toggler"
41                                aria-labelledby="select-shipping-prices_${this.instanceId}-label"
42                            >
43                                <span
44                                    class="select-toggler__placeholder"
45                                    slot="placeholder"
46                                    >${F("Select")}</span
47                                >
48                            </h-select-toggler>
49                        </h-select>
50                    </div>
51                </div>
52            </div>
53        `:B}};E([d({type:Number,attribute:"instance-id"})],_.prototype,"instanceId",2);E([d({type:String,attribute:"default-country-locale",converter:e=>e?new j(e):null})],_.prototype,"defaultCountryLocale",2);_=E([D("select-shipping-countries")],_);var _i=Object.defineProperty,yi=Object.getOwnPropertyDescriptor,P=(e,i,t,s)=>{for(var n=s>1?void 0:s?yi(i,t):i,r=e.length-1,p;r>=0;r--)(p=e[r])&&(n=(s?p(i,t,n):p(n))||n);return s&&n&&_i(i,t,n),n};let S=class extends M{constructor(){super(),this._shippingOptions=null,this._handleShippingOptionsChanged=e=>{e&&(this._shippingOptions=e,this.selectedCountryId=e.currentCountry?.id.toString(),this._shippingCosts=e.shippingsInCountries.find(({countryId:i})=>i===this.selectedCountryId)?.shippingOptions)},this._$productShippingPrices=this._getProductShippingPricesParent(),this.getApi(V.api).then(e=>{this._translationApi=e})}_getProductShippingPricesParent(){const e=this.closest(y.component);if(!e)throw Error("Missing product-shipping-prices parent");return e}connectedCallback(){super.connectedCallback(),this._selectShippingOptionsSubscription=this._$productShippingPrices.productShippingPricesService.selectShippingOptions$().subscribe(e=>{this._handleShippingOptionsChanged(e)})}disconnectedCallback(){super.disconnectedCallback(),this._selectShippingOptionsSubscription?.unsubscribe()}_getShippingInfoById(e){return this._shippingOptions?.availableShippings.find(i=>i.shippingId===e)}render(){return I`
54            <ul class="list__content">
55                ${this._shippingCosts?this._shippingCosts.map((e,i)=>{const t=this._getShippingInfoById(e.shippingId),s=e.cost.float===0;return I`
56                              <li
57                                  class="
58                                list__item
59                                product-shipping-prices-modal__shipping
60                                ${i%2===0?"product-shipping-prices-modal__shipping_secondary":""}
61                                mb-xs-2
62                            "
63                              >
64                                  <div class="product-shipping-prices-modal__shipping-details">
65                                      <span class="product-shipping-prices-modal__shipping-name"> ${t?.name} </span>
66                                      <span
67                                          class="
68                                    product-shipping-prices-modal__shipping-price
69                                    ${s?"product-shipping-prices-modal__shipping-price_secondary":""}
70                                    "
71                                      >
72                                          ${s?this._translationApi?.translate("Free"):e.cost.text}
73                                      </span>
74                                  </div>
75
76                                  <p class="product-shipping-prices-modal__shipping-description mt-xs-1">${t?.description}</p>
77                              </li>
78                          `}):B}
79            </ul>
80        `}};P([d({attribute:"selected-country-id",reflect:!0,type:String})],S.prototype,"selectedCountryId",2);P([w()],S.prototype,"_shippingOptions",2);P([w()],S.prototype,"_shippingCosts",2);S=P([D("shipping-prices-details")],S);class xi extends Q{static{this.featureName=y.feature}static{this._components={productShippingPrices:h,selectShippingCountries:_,shippingPricesDetails:S}}}export{xi as ProductShippingPricesInitializer};

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.