PageSourceSearch

https://teslaweld.com/catalog/view/theme/fastor/js/sk_cart_oc.js?v=2.4.141

js teslaweld.com collected 2026-10-09 00:20:53 UTC 17,839 bytes, 569 lines download raw bytes

1/*
2* VER SK TT 01.01.2020
3* VER SK TT 21.09.2020 ++ добавлена function Cart_ListIdTextGet()
4* VER SK TT 21.05.2021 ++ добавлен PromoCode
5* VER SK TT 06.01.2022 ++ добавлен articul
6* VER SK TT 08.11.2022 ++ добавлен sk_criteo_product_to_cart
7* VER SK TT 28.01.2023 == update for GA4
8* VER SK TT 12.01.2024 !! кука большая более 4k - убраны из куки offer_cart.name, offer_cart.mes
9* VER SK TT 20.02.2024 ++ Order_ID Order_ID_Set() Order_ID_Get()
10* VER SK TT 03.07.2024 == оптимизация кода
11* VER SK TT 11.07.2024 == bag offer_cart=this.Offer_Get(id); -> let offer_cart
12* VER SK TT 13.09.2024 ++ fg_free_delivery, _set_stat={}
13* VER SK TT 23.10.2024 ++ super_sale
14* VER SK TT 04.12.2024 ++ super_sale in out price
15* VER SK TT 20.10.2025 == static PromoCodeValidation(_prome_code,_product_id)
16*/
17
18class Cart_OC
19{
20    constructor(cart_name='')
21    {
22        this.cart_name ='site_oc_cart_v2';
23        this.promo_name='site_oc_promo_code';
24        if (cart_name.length>0) this.cart_name=cart_name;
25        this.listOffers={};
26//        this.Lead_ID=''; // можно убрать
27        this.Order_ID='';
28        this.Cart_Read();
29        this.PromoCode_Init();
30    }
31    // old version
32    Lead_ID_Set(_lead_id)
33    {
34        this.Order_ID=_lead_id.toString();
35    }
36    // old version
37    Lead_ID_Get()
38    {
39        return this.Order_ID;
40    }
41    Order_ID_Set(_order_id)
42    {
43        this.Order_ID=_order_id.toString();
44    }
45    Order_ID_Get()
46    {
47        return this.Order_ID;
48    }
49
50    Cart_Save()
51    {
52        let ls={};
53        let offer_cart;
54        for (let id in this.listOffers)
55        {
56            offer_cart=this.listOffers[id];
57            let offer_s = {};
58            offer_s.count=offer_cart.count;
59            offer_s.super_sale=0;
60            if (offer_cart.hasOwnProperty('super_sale')) offer_s.super_sale=offer_cart.super_sale;
61  
62            ls[id] = offer_s;
63        }
64
65        var str=JSON.stringify(ls);
66        if (str=='{}' || str=='[]') str='';
67        $.cookie(this.cart_name, str);
68    }
69
70    Cart_Read()
71    {
72        this.listOffers={};
73        let str_cookie=$.cookie(this.cart_name);
74        if (str_cookie===null) return ;
75
76        let str=this.constructor.Cart_Init(str_cookie);
77
78        if (str===null || str=='' || str=='[]' || str=='{}')
79        {
80            return ;
81        }
82        if (str!='' && str!=null) str=str.replace(/\+/g, ' ');
83
84        this.listOffers=JSON.parse(str);
85/*
86        let list_id={};
87        list_id=JSON.parse(str);
88
89        this.listOffers={};
90        let offer_oc;
91        for (let id in list_id)
92        {
93         offer_oc=list_id[id];
94         offer_cart = this.Offer_OC_to_Offer_Cart(offer_oc);
95
96         this.listOffers[id] = offer_cart;
97        }
98*/
99    }
100
101    static Offer_Init(_product_id)
102    {
103     let offer = {};
104     if (typeof _product_id === 'undefined' || _product_id.length==0 || _product_id==0) return offer;
105     let url='index.php?route=module/block_cart/json_offer_cart';
106        jQuery.ajax({
107            type: "POST",
108//            url: url+'&product_id='+_product_id,
109            url: url,
110            data: { product_id: _product_id },
111            dataType:"text",
112            cache: false,
113            async:false,
114            success:function(text_json){
115                if (typeof text_json !== 'undefined' && text_json.length!=0) offer=JSON.parse(text_json);
116            },
117            error:function(xhr, ajaxOptions, thrownError){
118                alert(thrownError); alert("Ошибка выполнения скрипта: "+url);
119            }
120        });
121        return offer;
122    }
123
124    static Cart_Init(_cart_cookie)
125    {
126     let  cart_bd= '';
127     if (_cart_cookie==null || typeof _cart_cookie === 'undefined' || _cart_cookie.length==0) return cart_bd;
128     let url='index.php?route=module/block_cart/json_cart';
129        jQuery.ajax({
130            type: "POST",
131//            url: url+'&product_id='+_product_id,
132            url: url,
133            data: { cart_cookie: _cart_cookie },
134            dataType:"text",
135            cache: false,
136            async:false,
137            success:function(text_json){
138                if (typeof text_json !== 'undefined' && text_json.length!=0) cart_bd=text_json;
139            },
140            error:function(xhr, ajaxOptions, thrownError){
141                alert(thrownError); alert("Ошибка выполнения скрипта: "+url);
142            }
143        });
144        return cart_bd;
145    }
146
147    PromoCode_Init()
148    {
149        this.PromoCode_Read();
150
151        let promocode=this.constructor.PromoCodeValidation(this.PromeCode.code);
152        if (typeof promocode !== 'undefined')
153        {
154            this.PromeCode=promocode;
155            this.PromoCode_Save();
156        }
157        else
158        {
159            $.cookie(this.promo_name, '');
160        }
161    }
162
163    static PromoCodeValidation(_prome_code,_product_id=0)
164    {
165        let prome_code_info={code:'',fg:0,discount:0};
166        if (_prome_code.length==0) return prome_code_info;
167        jQuery.ajax({
168            type: "GET",
169            url: 'index.php?route=module/block_cart/promo_code_valid&promo_code='+_prome_code+'&product_id='+_product_id,
170            dataType:"text",
171            cache: false,
172            async:false,
173            success:function(text_json){
174                prome_code_info=JSON.parse(text_json);
175            },
176            error:function(xhr, ajaxOptions, thrownError){
177                alert(thrownError); alert("Ошибка выполнения скрипта: index.php?route=module/block_cart/promo_code_valid");
178            }
179        });
180        return prome_code_info;
181    }
182
183
184    PromoCode_Read()
185    {
186        this.PromeCode={code:'',fg:0,discount:0};
187
188        let str='';
189        str=$.cookie(this.promo_name);
190
191        if (str===null || str=='' || str=='[]' || str=='{}')
192        {
193            return ;
194        }
195        if (str!='' && str!=null) str=str.replace(/\+/g, ' ');
196        let l={};
197        l=JSON.parse(str);
198        this.PromeCode=l;
199    }
200
201    PromoCode_Save()
202    {
203        var str=JSON.stringify(this.PromeCode);
204        if (str=='{}' || str=='[]') str='';
205        $.cookie(this.promo_name, str);
206    }
207
208
209    Offer_GTM_Add(_offer_cart={})
210    {
211        if (typeof _offer_cart === 'undefined') return false;
212
213        if (_offer_cart.hasOwnProperty('id')==false) return false;
214        if (_offer_cart.id==0) return false;
215
216        let id=_offer_cart.id;
217        let super_sale=0;
218        if (_offer_cart.hasOwnProperty('super_sale')) super_sale=Number(_offer_cart.super_sale);
219
220        let keys=Object.keys(this.listOffers);
221        if (keys.length>10) return;
222
223        // если такой товар уже в корзине, то добавляем +1 к его количеству
224        if (this.listOffers.hasOwnProperty(id))
225        {
226            this.listOffers[id].count += 1;
227            if (super_sale>0) this.listOffers[id].super_sale = super_sale;
228        }
229        else
230        { // если товара в корзине еще нет, то добавляем в объект
231           let offer_oc=this.constructor.Offer_Init(id);
232           offer_oc.count=1;
233           offer_oc.super_sale=super_sale;
234/*         
235           let offer_cart = {};
236           offer_cart = this.Offer_OC_to_Offer_Cart(offer_oc);
237
238           this.listOffers[id] = offer_cart;
239*/
240           this.listOffers[id] = offer_oc;
241        }
242
243        this.Cart_Save();
244        
245        if (typeof sk_tracer_sender !== 'undefined')
246        {
247         let offer_cart=this.Offer_Get(id);
248         sk_tracer_sender.Event_Add_To_Cart(offer_cart);
249        }
250    }
251/*
252    Offer_OC_to_Offer_Cart(offer_oc)
253    {
254           let price_real= parseInt(offer_oc.price_real+''.replace(/\D+/g,""));
255           let price_old = parseInt(offer_oc.price_old+''.replace(/\D+/g,""));
256
257            if (price_real==0 && price_old>0)
258            {
259                price_real=price_old;
260                price_old=0;
261            }
262
263            let fg_visa=1;
264            fg_visa=Number(offer_oc.fg_visa);
265
266            if (price_real==0 && price_old==0) fg_visa=0;
267
268            let offer_cart={};
269            offer_cart.id=id;
270            offer_cart.price_real=price_real;
271            offer_cart.price_old=price_old;
272            offer_cart.count=1;
273            offer_cart.fg_visa=fg_visa;
274            offer_cart.articul=(offer_oc.hasOwnProperty('articul') != 'undefined')?offer_oc.articul:'';
275            offer_cart.vendor=(offer_oc.hasOwnProperty('vendor') != 'undefined')?offer_oc.vendor:'';
276            offer_cart.name_gtm=(offer_oc.hasOwnProperty('name_gtm') != 'undefined')?offer_oc.name_gtm:'';
277            offer_cart.category_id_gtm=(offer_oc.hasOwnProperty('category_id_gtm') != 'undefined')?offer_oc.category_id_gtm:'';
278            offer_cart.category_gtm=(offer_oc.hasOwnProperty('category_gtm') != 'undefined')?offer_oc.category_gtm:'';
279            return offer_cart;
280    }
281*/
282    Offer_Sub(_id)
283    {
284        if (_id.length==0 || _id==0) return;
285        if (this.listOffers.hasOwnProperty(_id)==false) return;
286        if (this.listOffers[_id].count<2) return;
287
288        this.listOffers[_id].count -= 1;
289        this.Cart_Save();
290        if (typeof sk_tracer_sender !== 'undefined')
291        {
292             let offer_cart=this.Offer_Get(_id);
293             sk_tracer_sender.Event_Remove_From_Cart(offer_cart);
294        }
295    }
296
297    Offer_Del(_id)
298    {
299        if (_id.length==0 || _id==0) return;
300        if (this.listOffers.hasOwnProperty(_id)==false) return;
301
302        let offer_cart=this.Offer_Get(_id);
303        delete this.listOffers[_id];
304        this.Cart_Save();
305        if (typeof sk_tracer_sender !== 'undefined')
306        {
307         sk_tracer_sender.Event_Remove_From_Cart(offer_cart,1);
308        }
309    }
310
311
312
313    Cart_Clear()
314    {
315        this.listOffers={};
316//   this.Cart_Save();
317        this.Storage_Delete();
318    }
319
320    Cart_isEmpty()
321    {
322     let keys=Object.keys(this.listOffers);
323     if (keys.length>0) return false;
324     return true;
325    }
326
327    
328    Cart_Stat(_set_stat={})
329    {
330        let price_fd_min=0,price_fd_max=0;
331        if (_set_stat.hasOwnProperty('price_fd_min')) price_fd_min=_set_stat.price_fd_min;
332        if (_set_stat.hasOwnProperty('price_fd_max')) price_fd_max=_set_stat.price_fd_max;
333
334        let stat={};
335
336        stat.poz=0;
337/*
338        stat.count_pay=0;
339        stat.sum_real_pay=0;
340        stat.sum_old_pay=0;
341        stat.desc_pay=0;
342*/
343        stat.count=0;
344        stat.sum_real=0;
345        stat.sum_old=0;
346        stat.sum_promo=0;
347        stat.desc=0;
348
349        stat.fg_pay=1;
350        stat.fg_promocode=0;
351        stat.fg_promocode_cart=0;
352        stat.id_main=0;
353        stat.id_cat=0;
354        stat.fg_free_delivery=0;
355
356        let ps=0;
357
358        let price_max=0;
359        for (let id in this.listOffers)
360        {
361            stat.poz++;
362
363            if (this.listOffers[id].fg_visa==0)
364                stat.fg_pay=0;
365
366            this.listOffers[id].coupon_code =	'';
367            this.listOffers[id].coupon_disc =	0;
368                   
369            if (this.listOffers[id].hasOwnProperty('ls_coupon')==true && this.listOffers[id].ls_coupon.length>0)
370            {
371                stat.fg_promocode=1;
372                // поиск промокода и определение скидки для товара
373                if (this.PromeCode.fg)
374                {
375                    // нашли
376                    let a=this.listOffers[id].ls_coupon;
377                    let discount=0,prome_code_info={};
378                    for (let index = 0; index < a.length; ++index)
379                    {
380                        let cc=a[index].code;
381                        if (cc==this.PromeCode.code)
382                        {
383                            stat.fg_promocode_cart=1;
384                            prome_code_info=this.constructor.PromoCodeValidation(this.PromeCode.code,id);
385                            this.listOffers[id].coupon_disc =	prome_code_info.discount;
386                            this.listOffers[id].coupon_code =	this.PromeCode.code;
387//                            stat.sum_promo+=this.listOffers[id].coupon_disc*this.listOffers[id].count;
388                            stat.sum_promo+=this.listOffers[id].coupon_disc*1; // 24.10.2024 
389                        }
390                    }
391
392                }
393            }
394
395            stat.count+=this.listOffers[id].count;
396            let super_sale=0;
397            if (this.listOffers[id].hasOwnProperty('super_sale')) super_sale=this.listOffers[id].super_sale;
398            stat.sum_real+=(this.listOffers[id].count*(this.listOffers[id].price_real-super_sale));
399            ps=this.listOffers[id].price_old;
400            if (ps==0) ps=this.listOffers[id].price_real;
401            stat.sum_old+=(this.listOffers[id].count*ps);
402            if (this.listOffers[id].price_real>price_max)
403            {
404             price_max=this.listOffers[id].price_real;
405             stat.id_main=id;
406             stat.id_cat=this.listOffers[id].category_id_gtm;
407            }
408
409            if (stat.fg_free_delivery==0 && (price_fd_min>0 && this.listOffers[id].price_real>=price_fd_min))
410            {
411             stat.fg_free_delivery=1;
412             if (price_fd_max>0 && this.listOffers[id].price_real>price_fd_max) stat.fg_free_delivery=0;
413            }
414
415        }
416
417//        if (stat.sum_old_pay>=stat.sum_real_pay)  stat.desc_pay=stat.sum_old_pay-stat.sum_real_pay;
418        if (stat.sum_old>=stat.sum_real)          stat.desc=stat.sum_old-stat.sum_real;
419
420//        stat.desc_pay+=stat.sum_promo;
421        stat.desc+=stat.sum_promo;
422        stat.sum_real-=stat.sum_promo;
423        this.stat=stat;
424
425        return stat;
426    }
427
428    Cart_Stat_Get()
429    {
430        return this.stat;
431    }
432
433    Cart_ToString()
434    {
435        this.Cart_Stat();
436
437        let str='';
438        let str_o='',str_p='';
439        let offer_cart;
440        let c=0;
441        if ((typeof this.PromeCode !== 'undefined') && this.PromeCode.fg==1)
442        {
443            str_p='ПромоКод ' + this.PromeCode.code + '#скидка '+ this.stat.sum_promo + ' грн';
444        }
445        str_p+=';';
446
447        for (let id in this.listOffers)
448        {
449            str_o='';
450            offer_cart=this.Offer_Get(id);
451            str_o=offer_cart.name_gtm + '#' + offer_cart.count + '#' +offer_cart.articul;
452            if (str!='') str+='~'; // если один товар то нет ^
453            str+=str_o;
454            c++;
455        }
456        if (c==1 && offer_cart.count>1) str+='^'; // если много позиций одного товара + ^
457        return str_p+str;
458    }
459
460    Cart_ListIdTextGet()
461    {
462        let str='';
463        for (let id in this.listOffers)
464        {
465            if (str!='') str+=',';
466            str+=id;
467        }
468        return str;
469    }
470
471
472    Cart_ListIdGet()
473    {
474        let list_id=[];
475        for (let id in this.listOffers)
476        {
477            list_id.push(id);
478        }
479        return list_id;
480    }
481
482
483
484    LinkListOffers_Get()
485    {
486        return this.listOffers;
487    }
488
489    Offer_Get(_id)
490    {
491        let offer_cart=null;
492        if (_id.length==0 || _id==0) return offer_cart;
493        if (this.listOffers.hasOwnProperty(_id))
494        {
495         offer_cart=this.listOffers[_id];
496        }
497        return offer_cart;
498    }
499
500    ListOffers_Get()
501    {
502        let ls=[];
503        let offer_cart;
504        for (let id in this.listOffers)
505        {
506            let offer_s = {};
507            offer_cart=this.listOffers[id];
508            offer_s.id=offer_cart.id.toString();
509            offer_s.price=offer_cart.price_real;
510            let super_sale=0;
511            if (this.listOffers[id].hasOwnProperty('super_sale')) super_sale=this.listOffers[id].super_sale;
512            offer_s.price=-super_sale;
513            offer_s.quantity=offer_cart.count;
514            ls.push(offer_s);
515        }
516        return ls;
517    }
518
519    ListOffersForLead_Get()
520    {
521        let ls=[];
522        let offer_cart;
523        for (let id in this.listOffers)
524        {
525            let offer_s = {};
526            offer_cart=this.listOffers[id];
527            offer_s.name=(offer_cart.hasOwnProperty('name_gtm')) ? offer_cart.name_gtm : '';
528            offer_s.price=offer_cart.price_real;
529            offer_s.discount=offer_cart.price_old-offer_cart.price_real;
530            let super_sale=0;
531            if (this.listOffers[id].hasOwnProperty('super_sale')) super_sale=this.listOffers[id].super_sale;
532            offer_s.discount=-super_sale;
533            if (offer_s.discount<0) offer_s.discount=0;
534            offer_s.quantity=offer_cart.count;
535            offer_s.articul=offer_cart.articul;
536            ls.push(offer_s);
537        }
538        return ls;
539    }
540
541    ListOffersFull_Get()
542    {
543        let ls=[];
544        let offer_cart;
545        for (let id in this.listOffers)
546        {
547            offer_cart=this.listOffers[id];
548            ls.push(offer_cart);
549        }
550        return ls;
551    }
552
553    Storage_Delete()
554    {
555        $.cookie(this.cart_name, '');
556        $.cookie(this.promo_name, '');
557    }
558
559    PromoCode_Delete()
560    {
561        this.PromeCode={code:'',fg:0,discount:0};
562        $.cookie(this.promo_name, '');
563    }
564
565
566}
567
568window.cart_site = new Cart_OC();
569window.text='';

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.