PageSourceSearch

https://glassupply.com/wp-content/plugins/cut-configurator_plug/public/js/cut-configurator-public.js

js glassupply.com collected 2026-10-06 13:17:54 UTC 8,788 bytes, 298 lines download raw bytes

1/**
2
3
4 *
5
6
7 * @param props {{ widgetRequestBaseMapping, cartCounterId }}
8
9
10 * @returns {{updateCartCount(): Promise<unknown>, addToCart(*=): Promise<unknown>}|Promise<unknown>}
11
12
13 */
14
15const toBoolean = (value) => {
16  return value != null ? value === 'true' || value === true || value === 1 || value === '1' : null;
17};
18
19const configuratorService = function (props) {
20  const widget = props?.widget;
21
22  const requestBaseMapping =
23    props != null && props.widgetRequestBaseMapping != null ? props.widgetRequestBaseMapping : '/wp-json/ca';
24
25  const cartCounterSelector =
26    props != null && props.cartCounterId != null ? props.cartCounterId : '.et-cart-info > span';
27
28  const xtFlCartWcActive =
29    props.plugin != null && props.plugin.xtFloatingCartWooCActive != null
30      ? toBoolean(props.plugin.xtFloatingCartWooCActive)
31      : false;
32
33  const useAjaxUpdateWPFragments =
34    props.plugin != null && props.plugin.useAjaxUpdateFragments != null
35      ? toBoolean(props.plugin.useAjaxUpdateFragments)
36      : false;
37
38  const setOrderLoadingIdle = (state) => {
39    if (widget != null) {
40      widget.setOrderLoadingState(state);
41    }
42  };
43
44  const setOrderSuccess = (state) => {
45    if (widget != null) {
46      widget.setOrderSuccessState(state);
47    }
48  };
49
50  const thpPlugin_XT_FlcartWooCom = () => {
51    if (xtFlCartWcActive === true) {
52      xt_woofc_refresh_cart();
53    }
54  };
55
56  const stdWooComRefreshFragments = () => {
57    if (!useAjaxUpdateWPFragments) return;
58    const url = wc_cart_fragments_params.wc_ajax_url.toString().replace('%%endpoint%%', 'get_refreshed_fragments');
59    return new Promise((resolve, reject) => {
60      jQuery
61        .ajax({
62          type: 'POST',
63          url: url,
64          // contentType: "application/json; charset=utf-8",
65          contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
66          dataType: 'json',
67        })
68        .then((response) => {
69          if (response && response.fragments != null) {
70            for (let fragmentsKey in response.fragments) {
71              if (xtFlCartWcActive === true && fragmentsKey.indexOf('xt_woofc') !== -1) {
72                continue;
73              }
74              const el = document.querySelectorAll(fragmentsKey);
75              if (el != null && el.length > 0) {
76                for (let elElement of el) {
77                  elElement.innerHTML = response.fragments[fragmentsKey];
78                }
79              }
80            }
81          }
82          resolve(response);
83        })
84        .catch((e) => {
85          console.error('Update cart count error! ', e);
86          reject(e);
87        });
88    });
89  };
90
91  return {
92    addToCart(data) {
93      return new Promise((resolve, reject) => {
94        const customHeaders = {};
95
96        if (window?.uid != null) {
97          customHeaders['x-request-uid'] = window.uid;
98        }
99        if (window?.blogId != null) {
100          customHeaders['x-request-blog-id'] = window.blogId;
101        }
102
103        if (window.CutConfiguratorWidget && typeof window.CutConfiguratorWidget.updateCanvasScaleZoom === 'function') {
104          window.CutConfiguratorWidget.updateCanvasScaleZoom();
105        }
106
107        setOrderLoadingIdle(true);
108
109        jQuery
110          .ajax({
111            type: 'POST',
112            url: `${requestBaseMapping}/crt`,
113            data: JSON.stringify(data),
114            contentType: 'application/json; charset=utf-8',
115            headers: customHeaders,
116            dataType: 'json',
117          })
118          .then((d) => {
119            setOrderSuccess(true);
120            setOrderLoadingIdle(false);
121            // this.updateCartCount().then();
122            this.updateCart();
123            resolve(d);
124          })
125          .catch((e) => {
126            reject(e);
127            console.error('Add to cart error! ', e);
128            setOrderLoadingIdle(false);
129          });
130      });
131    },
132
133    updateCart() {
134      thpPlugin_XT_FlcartWooCom();
135      stdWooComRefreshFragments();
136      this.updateCartCount();
137    },
138
139    updateCartCount() {
140      return new Promise((resolve, reject) => {
141        jQuery(document.body).trigger('wc_fragment_refresh');
142
143        // jQuery.ajax({
144        //     type: "GET",
145        //     url: `${requestBaseMapping}/count`,
146        //     contentType: "application/json; charset=utf-8",
147        //     dataType: "json",
148        // }).then(response => {
149        //     //TODO: prop must be set from plugin settings
150        //     var el = document.querySelector(cartCounterSelector);
151        //     if (el != null) {
152        //         el.innerHTML = `${response} Item`;
153        //     } else {
154        //         console.error("Cart header element not found!");
155        //     }
156        //     resolve(response);
157        // }).catch(e => {
158        //     console.error("Update cart count error! ", e);
159        //     reject(e);
160        // })
161      });
162    },
163  };
164};
165
166function onConfiguratorLoaded() {
167  let rmo = [];
168  if (cplugin.isa === null || Number(cplugin.isa) === 0) {
169    rmo = ['SEAMED_EDGES'];
170  }
171  const widget = window.CutConfiguratorWidget.configure({
172    initialProductId: typeof product !== 'undefined' ? product : null,
173    cartUrl: cplugin.cartUrl,
174    canvasHeight: cplugin.canvasHeight != null ? cplugin.canvasHeight : null,
175    removeOperationsByCode: rmo,
176  });
177  const configService = new configuratorService({ widget: widget, plugin: cplugin });
178  widget.events.addEventListener('appMounted', () => {
179    jQuery(document).on('click', '.cut-configurator-modal .cfg-tab', function () {
180      window.CutConfiguratorWidget.updateCanvasScaleZoom();
181    });
182  });
183  // widget.events.addEventListener("selectMaterial", (d) => {
184  //     console.log("Material selected ", d);
185  // });
186  // widget.events.addEventListener("onSendCalc", (d) => {
187  //     console.log("Widget send calc price request", d);
188  // })
189  widget.events.addEventListener('orderDataReady', (d) => {
190    configService.addToCart(d).then();
191  });
192  widget.events.addEventListener('orderCreated', (d) => {
193    console.log('Order created:: ', d);
194    var weight = 0,
195      weightUnit = null;
196    var weightProp = d.priceData?.physicalProperties?.find(
197      (f) => f.type === 'WEIGHT' && f.propertyType === 'CALCULATE',
198    );
199    if (weightProp) {
200      weight = weightProp.value;
201      weightUnit = weightProp.unit.symbol;
202    }
203
204    jQuery(document).ready(function ($) {
205      var data = {
206        action: 'my_action',
207        number: d.number,
208        quantity: d.qty,
209        color: d.color,
210        form: d.form,
211        material: d.material,
212        length: d.length,
213        processing: d.processing,
214        thickness: d.thickness,
215        width: d.width,
216        cutouts: d.cutouts,
217        holes: d.holes,
218        productName: d.productName,
219        price: d.pricePerItem?.price,
220        media: d.media,
221        sides: d.sides,
222        // orderData: d.orderData,
223        weight: weight,
224        weightUnit: weightUnit,
225        corners: d.corners,
226        inputs: d.orderData.inputs,
227        objectProperties: d.orderData.objectProperties,
228      };
229      // 'ajaxurl' не определена во фронте, поэтому мы добавили её аналог с помощью wp_localize_script()
230      //--/wp-admin/admin-ajax.php
231      jQuery.post(
232        cplugin.url,
233        data,
234        function (response) {
235          //alert('Получено с сервера: ' + response);
236          //window.location.href = "https://test-shop.krava-dev.website/cut-configurator/";
237        },
238        'json',
239      );
240    });
241    //window.location.replace("https://test-shop.krava-dev.website/cut-configurator/");
242    setTimeout(function () {
243      // location.reload();
244      jQuery('.et-cart-info').load(location.href + ' .et-cart-info>*', '');
245    }, 2000);
246    setTimeout(function () {
247      // location.reload();
248      jQuery('.et-cart-info').load(location.href + ' .et-cart-info>*', '');
249    }, 5000);
250  });
251  widget.init();
252}
253
254// var $fragment_refresh = {
255
256//     url: wc_cart_fragments_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'get_refreshed_fragments' ),
257
258//     type: 'POST',
259
260//     success: function( data ) {
261
262//         if ( data && data.fragments ) {
263
264//
265
266//             $.each( data.fragments, function( key, value ) {
267
268//                 $( key ).replaceWith( value );
269
270//             });
271
272//
273
274//             if ( $supports_html5_storage ) {
275
276//                 sessionStorage.setItem( wc_cart_fragments_params.fragment_name, JSON.stringify( data.fragments ) );
277
278//                 set_cart_hash( data.cart_hash );
279
280//
281
282//                 if ( data.cart_hash ) {
283
284//                     set_cart_creation_timestamp();
285
286//                 }
287
288//             }
289
290//
291
292//             $( document.body ).trigger( 'wc_fragments_refreshed' );
293
294//         }
295
296//     }
297
298// };

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.