(Coming Soon)

Compare thousands of DIY and building products

Best Prices

City Electrical Factors

£4.45

Best Price
Visit Site In stock

The prices shown are available online and may not reflect in store. Confirm prices before visiting store.

Map View

Product Image
${product._source.title}
£ ${product._source.price ? product._source.price.toFixed(2) : 0}
`).join(''); searchBox.html(productCards); } else { searchBox.html('

No products found.

'); } } function renderSuggestions(suggestions) { let suggestionBox = $('.suggestion-links'); suggestionBox.empty(); if (suggestions?.length) { let suggestionLinks = suggestions.slice(0, 5).map(suggestion => ` ${suggestion} `).join(''); suggestionBox.html(suggestionLinks); } else { suggestionBox.html('

No suggestions found.

'); // suggestionBox.html(''); } } function productURL(product) { let slug = product._source.title.replace(/\//g, '-').toLowerCase().split(' ').join('-'); // Get base URL fr om a hidden Blade variable or directly hardcode if known let baseUrl = "https://test.comparethebuild.com/product"; return `${baseUrl}/${slug}/${product._id}`; } // Use event delegation to handle dynamically created links $(document).on('click', '.suggestion-link', function() { let productName = $(this).data('title'); $('#search-bar').val(productName); $('#search-child-form').submit(); $('.search-dropdown').hide(); // Hides the search box }); }); function searchFormSubmit() { $('#search-child-form').submit(); } --> ', container); // if (!map) { // showMap(); // map = new mapboxgl.Map({ // container: container, // style: 'mapbox://styles/mapbox/navigation-day-v1', // center: coordinates, // zoom: 10, // }); // } // Update user location marker // if (userMarker) { // userMarker.setLngLat(coordinates); // } else { // userMarker = new mapboxgl.Marker(createUserCustomMarker()) // .setLngLat(coordinates) // .setPopup(new mapboxgl.Popup().setHTML(` //
//
//
Postcode Location
// //
//
// `)) // .addTo(map); // } // Update map center and zoom // map.setCenter(coordinates); // map.setZoom(10); } else { // alert('Location not found. Please try again.'); } }) .catch(error => { console.error('Error:', error); // alert('Failed to fetch location. Please try again.'); }); } async function getLocationByPostalCode(location1, container = 'map', isNew = false) { const postcode = location1.trim(); console.log(postcode, 'postcode'); try { // Fetch geolocation from Mapbox const response = await fetch( `https://api.mapbox.com/geocoding/v5/mapbox.places/${encodeURIComponent(location1)}.json?access_token=pk.eyJ1IjoiY29tcGFyZXRoZWJ1aWxkIiwiYSI6ImNtNm00ZmhnMjBmdnkya3M1a2xzNzlhNTUifQ.zywKzFbxfqER2Tf-lTiCGg` ); const data = await response.json(); if (data.features.length === 0) { console.warn('Location not found. Please try again.'); return; } const coordinates = data.features[0].geometry.coordinates; console.log(coordinates, 'coordinates'); const radius = $('#radius-input').val(); // Wrap jQuery AJAX in a Promise so we can await it const storeData = await new Promise((resolve, reject) => { $.ajax({ url: 'https://test.comparethebuild.com/get-store-data/67e393c77775e6ce89a4a4fd' + `/${coordinates[0]}/${coordinates[1]}?radius=${radius}`, type: 'GET', headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]') .getAttribute('content') }, dataType: 'json', delay: 250, success: resolve, error: (xhr, status, error) => { console.error('Error occurred:', error); $(loadingSpinner).hide(); reject(error); } }); }); window.merchantMap = storeData.merchantData; console.log(window.merchantMap, 'merchantData'); // Track nearest merchant document.querySelectorAll(".merchant-row").forEach(row => { let merchantId = row.getAttribute("data-merchant-id"); let merchantInfo = window.merchantMap[merchantId]; if (merchantInfo) { if (!window.nearestMerchantId || merchantInfo.minimum_store_distance < window.merchantMap[window.nearestMerchantId] ?.minimum_store_distance) { window.nearestMerchantId = merchantId; } } }); const startLong = coordinates[0]; const startLat = coordinates[1]; updatedLong = startLong; updatedLat = startLat; if (!map) { showMap(); map = new mapboxgl.Map({ container: container, style: 'mapbox://styles/mapbox/streets-v12', center: [startLong, startLat], zoom: 10, }); } await showUserLocation(startLat, startLong, isNew, container); for (const merchantId of Object.keys(window.merchantMap)) { const merchant = window.merchantMap[merchantId]; const endLat = merchant?.nearest_store_lat; const endLong = merchant?.nearest_store_long; if (endLat && endLong) { try { const travelRes = await fetch( `https://api.mapbox.com/directions/v5/mapbox/driving/${startLong},${startLat};${endLong},${endLat}?access_token=pk.eyJ1IjoiY29tcGFyZXRoZWJ1aWxkIiwiYSI6ImNtNm00ZmhnMjBmdnkya3M1a2xzNzlhNTUifQ.zywKzFbxfqER2Tf-lTiCGg` ); const travelData = await travelRes.json(); if (travelData.routes.length > 0) { const travelTimeInMinutes = Math.round(travelData.routes[0].duration / 60); console.log( `Merchant ${merchantId} - Estimated travel time: ${travelTimeInMinutes} minutes` ); const el = document.querySelector( `.merchant-row[data-merchant-id="${merchantId}"] .merchant-distance`); if (el) { el.innerText = `Nearest Store: ${travelTimeInMinutes} min Drive`; } } } catch (error) { console.error(`Error fetching travel time for Merchant ${merchantId}:`, error); } } else { console.error(`Nearest store coordinates missing for Merchant ${merchantId}`); } } if (storeData.nearestStore) { getDirectionsToMultipleStores(startLat, startLong, storeData.nearestStore); } if (Array.isArray(storeData.merchantStores) && storeData.merchantStores.length > 0) { $('#map').show(); messageElement.style.display = "none"; $('#expandedMap').show(); expandedMessageElement.style.display = "none"; storeMarkers.forEach(marker => marker.remove()); storeMarkers = []; for (const store of storeData.merchantStores) { var customStoreMarker = createCustomMarker(store.img_url); const storeMarker = new mapboxgl.Marker(customStoreMarker) .setLngLat([store.long, store.lat]) .setPopup(new mapboxgl.Popup().setHTML(`
Logo
${store.store_name}
`)) .addTo(map); storeMarker.getElement().addEventListener("click", function() { getDirectionsToMultipleStores(startLat, startLong, store); }); storeMarkers.push(storeMarker); $(".range-updated-message").show(); setTimeout(() => { $(".range-updated-message").hide(); }, 5000); } } else { showMessage(`Stores are not within ${storeData.radius} miles.`); } } catch (error) { console.error('Error:', error); // alert('Failed to fetch location. Please try again.'); } } // document.getElementById('location-input').addEventListener('input', function() { // const location1 = document.getElementById('location-input').value; // getLocationByPostalCode(location1); // }); function submitPostalCode() { const location1 = document.getElementById('location-input').value.replace(/\s+/g, ''); getLocationByPostalCode(location1); } // Function to get directions from user's location to the store function getDirections(userLat, userLong, storeLat, storeLong) { const directionsUrl = `https://api.mapbox.com/directions/v5/mapbox/driving/${userLong},${userLat};${storeLong},${storeLat}?geometries=geojson&access_token=pk.eyJ1IjoiY29tcGFyZXRoZWJ1aWxkIiwiYSI6ImNtNm00ZmhnMjBmdnkya3M1a2xzNzlhNTUifQ.zywKzFbxfqER2Tf-lTiCGg`; fetch(directionsUrl) .then(response => response.json()) .then(data => { const route = data.routes[0].geometry.coordinates; const routeCoordinates = route.map(coord => [coord[0], coord[1]]); const userLocation = { latitude: userLat, longitude: userLong, } const storeLocations = [{ latitude: storeLat, longitude: storeLong, }]; // displayRoute(routeCoordinates, userLocation, storeLocations); displayRoute(routeCoordinates, false, storeLocations); displayRoute(routeCoordinates); }) .catch(error => { console.error('Error fetching directions:', error); alert('Could not fetch directions. Please try again later.'); }); } // Function to display the route on the map // function displayRoute(routeCoordinates) { // // If the map is already initialized // if (!map) { // console.error("Map not initialized."); // return; // } // // Add the route as a line to the map // map.on('load', () => { // map.addSource('route', { // 'type': 'geojson', // 'data': { // 'type': 'Feature', // 'properties': {}, // 'geometry': { // 'type': 'LineString', // 'coordinates': routeCoordinates // } // } // }); // map.addLayer({ // 'id': 'route', // 'type': 'line', // 'source': 'route', // 'paint': { // 'line-width': 5, // 'line-color': '#3887be', // 'line-opacity': 0.75 // } // }); // // Add markers for user and store // new mapboxgl.Marker() // .setLngLat([userLong, userLat]) // .addTo(map); // new mapboxgl.Marker() // .setLngLat([storeLong, storeLat]) // .addTo(map); // }); // } // Function to get directions from user's location to the store // function getDirections(userLat, userLong, storeLat, storeLong) { // const directionsUrl = `https://api.mapbox.com/directions/v5/mapbox/driving/${userLong},${userLat};${storeLong},${storeLat}?geometries=geojson&access_token=pk.eyJ1IjoiY29tcGFyZXRoZWJ1aWxkIiwiYSI6ImNtNm00ZmhnMjBmdnkya3M1a2xzNzlhNTUifQ.zywKzFbxfqER2Tf-lTiCGg`; // fetch(directionsUrl) // .then(response => response.json()) // .then(data => { // const route = data.routes[0].geometry.coordinates; // const routeCoordinates = route.map(coord => [coord[0], coord[1]]); // displayRoute(routeCoordinates); // }) // .catch(error => { // console.error('Error fetching directions:', error); // alert('Could not fetch directions. Please try again later.'); // }); // } function getDirectionsToMultipleStores(userLat, userLong, stores) { // const coordinates = [`${userLong},${userLat}`, ...stores.map(store => `${store.long},${store.lat}`)].join(';'); const coordinates = `${userLong},${userLat};${stores.long},${stores.lat}`; console.log('coordinates', coordinates); console.log('stores', stores); // Create the full URL with the user's location as the starting point const directionsUrl = `https://api.mapbox.com/directions/v5/mapbox/driving/${coordinates}?geometries=geojson&access_token=pk.eyJ1IjoiY29tcGFyZXRoZWJ1aWxkIiwiYSI6ImNtNm00ZmhnMjBmdnkya3M1a2xzNzlhNTUifQ.zywKzFbxfqER2Tf-lTiCGg`; fetch(directionsUrl) .then(response => response.json()) .then(data => { if (data.routes.length > 0) { const route = data.routes[0].geometry.coordinates; // Get the route coordinates const routeCoordinates = route.map(coord => [coord[0], coord[1]]); // const storeLocations = stores.map(store => { // latitude: store.lat, // longitude: store.long, // }) const storeLocations = [{ latitude: stores.lat, longitude: stores.long, }]; const userLocation = { latitude: userLat, longitude: userLong, } console.log('storeLocations', storeLocations); // Display the route that starts at the user's location and visits all stores // displayRoute(routeCoordinates, userLocation, storeLocations); displayRoute(routeCoordinates, false, storeLocations); // displayRoute(routeCoordinates); } else { console.warn('No routes found.'); } }) .catch(error => { console.error('Error fetching directions:', error); // alert('Could not fetch directions. Please try again later.'); }); } let routeLayer = null; // Variable to hold the route layer (geometry) // Function to display the route on the map function displayRoute(routeCoordinates, userLocation, storeLocations) { // Check if the map is initialized if (!map) { console.error("Map not initialized."); return; } // Remove the previous route if it exists if (routeLayer) { if (map.getLayer(routeLayer)) { map.removeLayer(routeLayer); // Remove the route layer } if (map.getSource(routeLayer)) { map.removeSource(routeLayer); // Remove the route source } } routeLayer = 'routeLayer'; // Unique identifier for the route layer // Add the route as a new source and layer to the map map.addSource(routeLayer, { type: 'geojson', data: { type: 'Feature', properties: {}, geometry: { type: 'LineString', coordinates: routeCoordinates // The route's coordinates } } }); map.addLayer({ id: routeLayer, type: 'line', source: routeLayer, layout: { 'line-join': 'round', 'line-cap': 'round' }, paint: { 'line-width': 5, 'line-color': '#3887be', 'line-opacity': 0.75 } }); // Remove existing markers if needed // (Optional, implement a separate storeMarkers array for store/user markers) // Add marker for the user's location console.log('userLocation-->', userLocation); console.log('storeLocations-->', storeLocations); // if (userLocation) { // new mapboxgl.Marker({ // color: '#1E90FF' // }) // Blue marker for the user // .setLngLat([userLocation.longitude, userLocation.latitude]) // .setPopup(new mapboxgl.Popup().setHTML(` //
//
//
Your Location
// //
//
// `)) // Add a popup // .addTo(map); // } // if (storeLocations) { // // Add markers for each store location // storeLocations.forEach(store => { // console.log('Store--', store); // var defaultStoreMarker = { // color: '#1E90FF' // }; // new mapboxgl.Marker(defaultStoreMarker) // Orange marker for stores // .setLngLat([store.longitude, store.latitude]) // // .setPopup(new mapboxgl.Popup().setHTML(` // //
// //
${store.name}
// //

${store.address}

// //
// // `)) // Add store details in the popup // .addTo(map); // }); // } } -->