PageSourceSearch

https://www.kleurenmix.nl/website/JavaScript/Vertoshop.js

js kleurenmix.nl collected 2026-09-26 17:47:28 UTC 20,811 bytes, 614 lines download raw bytes

1/**
2 * This object is designed as a struct. It will contain data concerning the visit of the current user and data on the current page.
3 */
4const Vertoshop = new function () {
5    const order    = new Order(ORDER_JSON);
6    const category = new Category(CATEGORY_JSON);
7    const user     = new User(USER_JSON);
8    const webshop  = new Webshop(WEBSHOP_JSON);
9
10    /**
11     * Returns an Order object. Only works if the customer has an active order.
12     * @returns {Order}
13     */
14    this.getOrder = function getOrder () {
15        return order;
16    };
17
18    /**
19     * Returns a Product object. Only works if on a Product page.
20     * @returns {Product}
21     */
22    this.getProduct = function getProduct () {
23        return new Product(PRODUCT_JSON);
24    };
25
26    /**
27     * Returns a Category object. Only works if on a Category page.
28     * @returns {Category}
29     */
30    this.getCategory = function getCategory () {
31        return category;
32    };
33
34    /**
35     * Returns a User object. Returns null if the user isn't logged in.
36     * @returns {User}
37     */
38    this.getUser = function getUser () {
39        return user;
40    };
41
42    /**
43     * Returns a Webshop object. This object is available on all pages.
44     * @returns {Webshop}
45     */
46    this.getWebshop = function getWebshop () {
47        return webshop;
48    };
49
50
51    function Order (json) {
52        const orderData = JSON.parse(json);
53
54        /**
55         * Returns Id of this object or null if not available. Id corresponds with the Resource Id in the API, ie:
56         * https://apiroot/:version/orders/:id
57         *
58         * @returns {int|null}
59         */
60        this.getId = function getId () {
61            return (orderData === null) ? null : orderData.id;
62        };
63
64        /**
65         * Returns an array with a collection or orderRows. If not order is available this will be an empty collection.
66         * @returns {OrderRow[]}
67         */
68        this.getOrderRows = function getOrderRows () {
69            const orderRowCollection = [];
70            let i                  = 0;
71            let orderRow           = null;
72            for (i in orderData.order_rows) {
73                if (orderData.order_rows.hasOwnProperty(i)) {
74                    orderRow = orderData.order_rows[i];
75                    orderRowCollection.push(new OrderRow(orderRow));
76                }
77
78            }
79
80            return (orderData === null) ? [] : orderRowCollection;
81        };
82    }
83
84    function OrderRow (data) {
85        const orderRowData = data;
86        /**
87         * Returns Id of this object or null if not available. Id corresponds with the Resource Id in the API, ie:
88         * https://apiroot/:version/orderrows/:id
89         * @returns {int|null}
90         */
91        this.getId = function getId () {
92            return (orderRowData === null) ? null : orderRowData.id;
93        };
94        /**
95         * Returns the poduct_id of this orderrow or null if not available. Id corresponds with the Resource Id in the API, ie:
96         * https://apiroot/:version/products/:id
97         *
98         * @returns {int|null}
99         */
100        this.getProductId = function getProductId () {
101            return (orderRowData === null) ? null : orderRowData.product_id;
102        };
103        /**
104         * Returns the quantity of the product in the orderrow or null if not available.
105         *
106         * @returns {int|null}
107         */
108        this.getCount = function getCount () {
109            return (orderRowData === null) ? null : orderRowData.count;
110        };
111        /**
112         * Returns the product name corresponding with this orderrow or null if not available.
113         * @returns {string|null}
114         */
115        this.getProductName = function getProductName () {
116            return (orderRowData === null) ? null : orderRowData.product_name;
117        };
118        /**
119         * Returns the product number corresponding with this orderrow or null if not available.
120         * @returns {string|null}
121         */
122        this.getProductNumber = function getProductNumber () {
123            return (orderRowData === null) ? null : orderRowData.product_number;
124        };
125        /**
126         * Returns the product base price corresponding with this orderrow or null if not available.
127         * @returns {float|null}
128         */
129        this.getPrice = function getPrice () {
130            return (orderRowData === null) ? null : orderRowData.price;
131        };
132        /**
133         * Returns the product discount corresponding with this orderrow or null if not available.
134         * @returns {float|null}
135         */
136        this.getDiscount = function getDiscount () {
137            return (orderRowData === null) ? null : orderRowData.discount;
138        };
139        /**
140         * Returns the tax percentage corresponding with this orderrow or null if not available.
141         * @returns {float|null}
142         */
143        this.getTax = function getTax () {
144            return (orderRowData === null) ? null : orderRowData.tax;
145        };
146    }
147
148    function Product (json) {
149        const product = JSON.parse(json);
150
151        /**
152         * Returns Id of this object. Id corresponds with the Resource Id in the API, ie:
153         * https://apiroot/:version/products/:id
154         *
155         * @returns {int|null}
156         */
157        this.getId = function getId () {
158            return (product === null) ? null : product.id;
159        };
160
161        /**
162         * Returns Name of this object in the current language of the webshop.
163         *
164         * @returns {string|null}
165         */
166        this.getName = function getName () {
167            return (product === null) ? null : product.name;
168        };
169
170        /**
171         * Returns Product Number of this object.
172         *
173         * @returns {string|null}
174         */
175        this.getProductNumber = function getProductNumber () {
176            return (product === null) ? null : product.productnumber;
177        };
178
179        /**
180         * Returns Product EAN of this object.
181         *
182         * @returns {string|null}
183         */
184        this.getEAN = function getEAN () {
185            return (product === null) ? null : product.ean;
186        };
187
188        /**
189         * Returns Product Amount of this object.
190         *
191         * @returns {string|null}
192         */
193        this.getAmount = function getAmount () {
194            return (product === null) ? null : product.amount;
195        };
196
197        /**
198         * Returns the currently selected Attribute Combination. If the customer changes his choices, these values
199         * will change accordingly.
200         *
201         * @returns {AttributeCombination}
202         */
203        this.getSelectedAttributeCombination = function getSelectedAttributeCombination () {
204            return new AttributeCombination(ATTRIBUTE_COMBINATION_JSON);
205        };
206
207        /**
208         * Returns the Attributes of this object. If the customer changes his attribute choices, the selected values
209         * will change accordingly.
210         *
211         * @returns {Attributes}
212         */
213        this.getAttributes = function getAttributes () {
214            return new Attributes(ATTRIBUTES_JSON)
215        };
216
217    }
218
219    function AttributeCombination (json) {
220        const attribute_combination = JSON.parse(json);
221
222        /**
223         * Returns the Id of this object. Id corresponds with the Resource Id in the API, ie:
224         * https://apiroot/:version/attributecombinations/:id
225         *
226         * @returns {int|null}
227         */
228        this.getId = function getId () {
229            return (attribute_combination === null) ? null : attribute_combination.id;
230        };
231        /**
232         * Returns Note (or short description) of this object.
233         *
234         * @returns {string|null}
235         */
236        this.getNote = function getNote () {
237            return (attribute_combination === null) ? null : attribute_combination.note;
238        };
239        /**
240         * Returns Product Number of this object.
241         *
242         * @returns {string|null}
243         */
244        this.getProductNumber = function getProductNumber () {
245            return (attribute_combination === null) ? null : attribute_combination.product_number;
246        };
247        /**
248         * Returns Attribute Combination EAN of this object.
249         *
250         * @returns {string|null}
251         */
252        this.getEAN = function getEAN () {
253            return (attribute_combination === null) ? null : attribute_combination.ean_number;
254        };
255        /**
256         * Returns Attribute Combination SKU of this object.
257         *
258         * @returns {string|null}
259         */
260        this.getSKU = function getSKU () {
261            return (attribute_combination === null) ? null : attribute_combination.sku_number;
262        };
263
264    }
265
266    function Attributes (json) {
267        const AttributesCollection = JSON.parse(json);
268
269        /**
270         * Returns an array with a collection or Attributes. If not available this will be an empty collection.
271         * @returns {Attributes[]}
272         */
273        this.getAttribute = function getAttribute () {
274            const Attributes         = [];
275            let a                  = 0;
276            let Attribute          = null;
277            for (a in AttributesCollection.Attributes) {
278                if (AttributesCollection.Attributes.hasOwnProperty(a)) {
279                    Attribute = AttributesCollection.Attributes[a];
280                    Attributes.push(new GetAttributeValues(Attribute));
281                }
282            }
283            return (Attributes === null) ? [] : Attributes;
284        };
285
286        /**
287         * Returns an array with a collection or selected attribute values. If not available this will be an empty collection.
288         * @returns {SelectedAttributes[]}
289         */
290        this.getSelectedValues = function getSelectedValues () {
291            const SelectedAttributes = [];
292            let sav                  = 0;
293            let SelectedAttribute  = null;
294            for (sav in AttributesCollection.Selected_attribute_value) {
295                if (AttributesCollection.Selected_attribute_value.hasOwnProperty(sav)) {
296                    SelectedAttribute = AttributesCollection.Selected_attribute_value[sav];
297                    SelectedAttributes.push(new GetSelectedAttribute(SelectedAttribute));
298                }
299            }
300            return (SelectedAttributes === null) ? [] : SelectedAttributes;
301        };
302
303        /**
304         * Returns Selected Attribute Combination Id of this object.
305         *
306         * @returns {string|null}
307         */
308        this.getSelectedAttributeCombinationId = function getSelectedAttributeCombinationId () {
309            return (AttributesCollection === null) ? null : AttributesCollection.Selected_attribute_combinationId;
310        };
311    }
312
313   function GetAttributeValues(Attribute) {
314       /**
315        * Returns the Id of this object. Id corresponds with the Resource Id in the API, ie:
316        * https://apiroot/:version/attributevalues/:id/
317        *
318        * @returns {int|null}
319        */
320       this.getId = function getId () {
321           return (Attribute === null) ? null : Attribute.Id;
322       };
323       /**
324        * Returns Name of this object.
325        *
326        * @returns {string|null}
327        */
328       this.getName = function getName () {
329           return (Attribute === null) ? null : Attribute.Name;
330       };
331
332       /**
333        * corresponds with the Resource in the API, ie:
334        * https://apiroot/:version/attributevalues/
335        *
336        * @returns {[]|null}
337        */
338       this.getValues = function getValues() {
339           const AttributesValues   = [];
340           let q                  = 0;
341           let AttributeValue     = null;
342           for (q in Attribute.Attribute_values) {
343               if (Attribute.Attribute_values.hasOwnProperty(q)) {
344                   AttributeValue = Attribute.Attribute_values[q];
345                   AttributesValues.push(new GetAttributeValue(AttributeValue));
346               }
347           }
348           return (AttributesValues === null) ? [] : AttributesValues;
349       }
350    }
351
352    function GetSelectedAttribute (SelectedAttribute) {
353        /**
354         * Returns the Id of this object. Id corresponds with the Resource Id in the API, ie:
355         * https://apiroot/:version/attributevalues/:id/
356         *
357         * @returns {int|null}
358         */
359        this.getId = function getId () {
360            return (SelectedAttribute === null) ? null : SelectedAttribute.Id;
361        };
362        /**
363         * Returns Value of this object.
364         *
365         * @returns {string|null}
366         */
367        this.getValue = function getValue () {
368            return (SelectedAttribute === null) ? null : SelectedAttribute.Value;
369        };
370
371        /**
372         * Returns Name of this object.
373         *
374         * @returns {string|null}
375         */
376        this.getName = function getName () {
377            return (SelectedAttribute === null) ? null : SelectedAttribute.Name;
378        };
379
380    }
381
382    function GetAttributeValue(AttributeValue) {
383        /**
384         * Returns the Id of this object.
385         *
386         * @returns {int|null}
387         */
388        this.getId = function getId () {
389            return (AttributeValue === null) ? null : AttributeValue.Id;
390        };
391        /**
392         * Returns Name of this object.
393         *
394         * @returns {string|null}
395         */
396        this.getName = function getNote () {
397            return (AttributeValue === null) ? null : AttributeValue.Name;
398        };
399    }
400
401
402    function Category (json) {
403        const category = JSON.parse(json);
404        /**
405         * Returns Id of this object. Id corresponds with the Resource Id in the API, ie:
406         * https://apiroot/:version/categories/:id
407         *
408         * @returns {int|null}
409         */
410        this.getId = function getId () {
411            return (category === null) ? null : category.id;
412        };
413
414        /**
415         * Returns Name of this object in the current language of the webshop.
416         *
417         * @returns {string|null}
418         */
419        this.getName = function getName () {
420            return (category === null) ? null : category.name;
421        };
422    }
423
424    function User (json) {
425        const user = JSON.parse(json);
426        /**
427         * Returns Id of this object. Id corresponds with the Resource Id in the API, ie:
428         * https://apiroot/:version/users/:id
429         *
430         * @returns {int|null}
431         */
432        this.getId = function getId () {
433            return (user === null) ? null : user.id;
434        };
435        /**
436         * Returns the Id of the group to whom this user belongs or null if not available. Id corresponds with the Resource Id in the API, ie:
437         * https://apiroot/:version/usergroups/:id
438         * @returns {null}
439         */
440        this.getGroupId = function getGroupId () {
441            return (user === null) ? null : user.group_id;
442        };
443    }
444
445
446
447
448    function Webshop (json) {
449        const webshop = JSON.parse(json);
450
451        const cookieBar       = (webshop.cookieBar === null) ? null : new CookieBar(webshop.cookieBar);
452        const creditPoints    = (webshop.creditPoints === null) ? null : new CreditPoints(webshop.creditPoints);
453        const discountCoupons = (webshop.discountCoupons === null) ? null : new DiscountCoupons(webshop.discountCoupons);
454        const currentTheme = (webshop.currentTheme === null) ? null : new CurrentTheme(webshop.currentTheme);
455        /**
456         * Returns a CookieBar object
457         * @returns {CookieBar}
458         */
459        this.getCookieBar = function getCookieBar () {
460            return cookieBar;
461        };
462        /**
463         * Returns a CreditPoints object.
464         * @returns {CreditPoints}
465         */
466        this.getCreditPoints = function getCreditPoints () {
467            return creditPoints;
468        };
469        /**
470         * Retuns a DiscountCoupons object.
471         * @returns {DiscountCoupons}
472         */
473        this.getDiscountCoupons = function getDiscountCoupons () {
474            return discountCoupons;
475        };
476        /**
477         * Retuns a CurrentTheme object.
478         * @returns {CurrentTheme}
479         */
480        this.getCurrentTheme = function getCurrentTheme () {
481            return currentTheme;
482        };
483        /**
484         * Returns the API root url of the webshop.
485         * @returns {string}
486         */
487        this.getApiRoot = function getApiRoot () {
488            return (webshop === null) ? null : webshop.api_root;
489        };
490        /**
491         * Indicates if prices include VAT.
492         * @returns {bool}
493         */
494        this.doPricesIncludeVat = function doPricesIncludeVat () {
495            return (webshop === null) ? null : webshop.prices_include_vat;
496        };
497
498        /**
499         * Indicates if shipping costs include VAT.
500         * @returns {bool}
501         */
502        this.doShippingCostsIncludeVat = function doShippingCostsIncludeVat () {
503            return (webshop === null) ? null : webshop.shippingcosts_include_vat;
504        };
505
506        /**
507         * Returns the current currency of the webshop in ISO 4217 Currency Codes.
508         * @returns {string}
509         */
510        this.getCurrency = function getCurrency () {
511            return (webshop === null) ? null : webshop.currency;
512        };
513        /**
514         * Returns the collection of available display languages of the webshop in ISO 639-1 Language Codes.
515         * @returns {array}
516         */
517        this.getLanguages = function getLanguages () {
518            return (webshop === null) ? null : webshop.languages;
519        };
520        /**
521         * Returns the current display language of the webshop in ISO 639-1 Language Codes.
522         * @returns {string}
523         */
524        this.getCurrentLanguage = function getCurrentLanguage () {
525            return (webshop === null) ? null : webshop.current_language;
526        };
527    }
528
529    function CookieBar (data) {
530        const cookieBarData = data;
531        /**
532         * Indicates if the webshop has a cookie bar.
533         * @returns {bool}
534         */
535        this.isEnabled = function isEnabled () {
536            return (cookieBarData === null) ? null : cookieBarData.is_enabled;
537        };
538        /**
539         * Indicates if the user accepted the placement of tracking cookies.
540         * @returns {bool}
541         */
542        this.isAccepted = function isAccepted () {
543            return (cookieBarData === null) ? null : cookieBarData.is_accepted;
544        };
545
546        this.getPreferences =function getPreferences () {
547            return (cookieBarData === null) ? [] : cookieBarData.preferences;
548        };
549
550        this.getCookies =function getCookies () {
551            return (cookieBarData === null) ? [] : cookieBarData.cookies;
552        };
553
554        this.isAllowed = function isAllowed(type) {
555            return this.getPreferences().includes(type);
556        }
557    }
558
559    function CreditPoints (data) {
560        const creditPointData = data;
561        /**
562         * Indicates if the checkout accepts creditpoints.
563         * @returns {bool}
564         */
565        this.isEnabled = function isEnabled () {
566            return (creditPointData === null) ? null : creditPointData.is_enabled;
567        };
568        /**
569         * Returns the value of 1 credit point in the current currency.
570         * @returns {float}
571         */
572        this.getValue = function getValue () {
573            return (creditPointData === null) ? null : creditPointData.value;
574        };
575        /**
576         * Returns the display name for the creditpoints. The merchant can choose how these should be named.
577         * @returns {string}
578         */
579        this.getName = function getName () {
580            return (creditPointData === null) ? null : creditPointData.name;
581        };
582    }
583
584    function DiscountCoupons (data) {
585        const discountCouponData = data;
586        /**
587         * Indicates if the checkout accepts discount coupons.
588         * @returns {bool}
589         */
590        this.isEnabled = function isEnabled () {
591            return (discountCouponData === null) ? null : discountCouponData.is_enabled;
592        };
593        /**
594         * Indicates if a discount coupon is used in the current order.
595         * @returns {bool}
596         */
597        this.isFilledIn = function isFilledIn () {
598            return (discountCouponData === null) ? null : discountCouponData.is_filled_in;
599        };
600
601    }
602
603    function CurrentTheme (data) {
604        const currentThemeData = data;
605        /**
606         * Returns the display name for the creditpoints. The merchant can choose how these should be named.
607         * @returns {string}
608         */
609        this.getName = function getName () {
610            return (currentThemeData === null) ? null : currentThemeData.name;
611        };
612
613    }
614};

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.