PageSourceSearch

https://www.perfectdraft.com/static/version0.0.0.1228/frontend/Bee…/js/products_rendering_hook_nodefer.js

js perfectdraft.com collected 2026-10-09 22:39:06 UTC 2,025 bytes, 56 lines download raw bytes

1require([], function () {
2    window.algolia && window.algolia.registerHook('beforeWidgetInitialization', function (allWidgetConfiguration) {
3
4        let customerSegments = [];
5        let cacheStorage = JSON.parse(localStorage.getItem('mage-cache-storage'));
6
7        if (typeof cacheStorage === 'object' && cacheStorage.customersegments && Array.isArray(cacheStorage.customersegments.customer_segments)) {
8            customerSegments = cacheStorage.customersegments.customer_segments
9        }
10
11        const parentTransformItems = allWidgetConfiguration.infiniteHits.transformItems;
12
13        allWidgetConfiguration.infiniteHits.transformItems = function (items) {
14            const transformedItems = parentTransformItems(items);
15
16            return transformedItems.map(item => {
17                if (!item.show_only_for_segments) {
18                    return { ...item, isAvailableForCurrentCustomer: true }
19                }
20
21                let productSegments = [];
22
23                if (Array.isArray(item.show_only_for_segments) && item.show_only_for_segments.length) {
24                    productSegments = item.show_only_for_segments;
25                }
26
27                if (typeof(item.show_only_for_segments) == 'string') {
28                    productSegments = item.show_only_for_segments.split(',');
29                }
30
31                let canAddToCart = false;
32
33                if (productSegments.length > 0) {
34
35                    productSegments.forEach(productSegment => {
36
37                        const contains = !!customerSegments
38                            .find(customerSegs => customerSegs.name === productSegment);
39
40                        if (contains) {
41                            canAddToCart = true;
42                        }
43                    })
44
45                } else {
46                    canAddToCart = true;
47                }
48
49                return { ...item, isAvailableForCurrentCustomer: canAddToCart }
50            });
51        }
52
53        return allWidgetConfiguration;
54    });
55
56})

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.