` ) }, 3000) }) } // OTP APIs function executeOtpAPI(preferredChannel) { if (!useTestAPI) { return getOtpAPI(preferredChannel); } else { return testGetOtpAPI(preferredChannel); } } function getOtpAPI(preferredChannel) { return new Promise(function(resolve, reject) { $.ajax({ url: `https://www.woolworths.com.au/api/v3/ui/authentication/otp?isInitial=true&Channel=${preferredChannel}`, type: 'GET', contentType: 'application/json', }).then(res => { if (res.Successful) { resolve(res); } else { reject(res); } }) }); } // send new code / send SMS/Email instead api function testGetOtpAPI(preferredChannel) { console.log('testGetOtpAPI preferredChannel', preferredChannel) if (preferredChannel == 1) { return new Promise((resolve, reject) => { setTimeout(() => { resolve({ "Successful": true, "Channel": 1, "MaskedContact": "p****h@g****.com" }) }, 3000) }) } else { return new Promise((resolve, reject) => { setTimeout(() => { resolve({ "Successful": true, "Channel": 0, "MaskedContact": "*******927" }) }, 3000) }) } } function executeVerifyOtp(otpInputValue) { if (!useTestAPI) { return verifyOtp(otpInputValue); } else { return testVerifyOtp(otpInputValue); } } // Verify the OPT provided by the user function verifyOtp(otpInputValue) { return new Promise(function(resolve, reject) { $.ajax({ url: `https://www.woolworths.com.au/api/v3/ui/authentication/otp`, type: 'POST', contentType: 'application/json', data: JSON.stringify({ OneTimePin: otpInputValue, UpdatePrimaryContact: false }) }).done((res) => { if (res.Successful) { resolve(res); } else { reject(res); } }).fail((res) => { reject(res); }) }); } function testVerifyOtp(otpInputValue) { if (otpInputValue == "123123") { return testOtpSuccess(); } else if (otpInputValue == "000000") { return testApiFailed(); } else { return testWrongOtpCode(); } } function testOtpSuccess() { return new Promise((resolve, reject) => { setTimeout(() => { resolve({ "Successful": true, "Error": null, "TokenValue": "d5794417cf1d4d5385c8347d8960ca07", "ErrorMessage": null }) }, 3000) }) } // wrong otp code function testWrongOtpCode() { console.log('testWrongOtpCode') return new Promise((resolve, reject) => { setTimeout(() => { reject({ "Successful": false, "Error": "InvalidOneTimePin", "TokenValue": "", "ErrorMessage": "Incorrect code. You have 4 attempt(s) left." }) }, 3000) }) } function fetchOrders(shopperId) { if (!useTestAPI) { return getOrdersAPI(shopperId); } else { return testGetOrdersAPI(); // return testNoOrdersAPI(); } } function getOrdersAPI(shopperId) { return new Promise(function(resolve, reject) { $.ajax({ url: `https://prod.mobile-api.woolworths.com.au/wow/v1/orders/api/orders?shopperId=${shopperId}&pageNumber=1&pageSize=6`, type: 'GET', contentType: 'application/json', headers: { "x-api-key": "s7iXf5Rixn4XxFrsYh4HKkriVp8hlnec" }, xhrFields: { withCredentials: true }, crossDomain: true }).done((res) => { resolve(res); }).fail((res) => { reject(res); }) }); } // orderstatus = // "Placed", "Received", "Preparing", // "Prepared", "OnItsWay", "Delivered", // "Shipped", "PartiallySent", "Cancelled" let testOrderStatus = "PartiallySent"; // DeliveryMethod = "Courier", "Express", "Pickup", "DriveUp" let testDeliveryMethod = "DriveUp"; function testGetOrdersAPI() { return new Promise((resolve, reject) => { setTimeout(() => { resolve({ "items": [{ "OrderId": 148153401, "CreatedDate": "2023-01-30T18:20:33.586949+11:00", "OriginalOrderCreatedDate": "2023-01-30T18:20:33.586949+11:00", "Total": 69.5, "CurrentStatus": `${testOrderStatus}`, "DeliveryMethod": `${testDeliveryMethod}`, "ProjectedDeliveryTime": { "Status": "OnTime", "OriginalStartTime": "2023-02-05T12:00:00", "OriginalEndTime": "2023-02-05T17:00:00", "StartTime": "2023-02-05T12:00:00", "EndTime": "2023-02-05T17:00:00", "BufferType": "None" }, "IsPfdOrder": false, "OrderType": "Standard", "MarketOrders": [], "IsMarketOnly": false, "IsPostPickPayOrder": false, "IsThirdPartyDelivery": false }, { "OrderId": 148153402, "CreatedDate": "2023-01-30T18:20:33.586949+11:00", "OriginalOrderCreatedDate": "2023-01-30T18:20:33.586949+11:00", "Total": 69.5, "CurrentStatus": `${testOrderStatus}`, "DeliveryMethod": `${testDeliveryMethod}`, "ProjectedDeliveryTime": { "Status": "OnTime", "OriginalStartTime": "2023-02-05T12:00:00", "OriginalEndTime": "2023-02-05T17:00:00", "StartTime": "2023-02-05T12:00:00", "EndTime": "2023-02-05T17:00:00", "BufferType": "None" }, "IsPfdOrder": false, "OrderType": "Standard", "MarketOrders": [], "IsMarketOnly": false, "IsPostPickPayOrder": false, "IsThirdPartyDelivery": false }, { "OrderId": 148153403, "CreatedDate": "2023-01-30T18:20:33.586949+11:00", "OriginalOrderCreatedDate": "2023-01-30T18:20:33.586949+11:00", "Total": 69.5, "CurrentStatus": `${testOrderStatus}`, "DeliveryMethod": `${testDeliveryMethod}`, "ProjectedDeliveryTime": { "Status": "OnTime", "OriginalStartTime": "2023-02-05T12:00:00", "OriginalEndTime": "2023-02-05T17:00:00", "StartTime": "2023-02-05T12:00:00", "EndTime": "2023-02-05T17:00:00", "BufferType": "None" }, "IsPfdOrder": false, "OrderType": "Standard", "MarketOrders": [], "IsMarketOnly": false, "IsPostPickPayOrder": false, "IsThirdPartyDelivery": false } ], "_links": { "self": "/api/Orders?shopperId=4282500&pageNumber=1&pageSize=6", "next": "/api/Orders?shopperId=4282500&pageNumber=2&pageSize=6", "previous": "/api/Orders?shopperId=4282500&pageNumber=1&pageSize=6" } }) }, 1500) }) } function testNoOrdersAPI() { return new Promise((resolve, reject) => { setTimeout(() => { resolve({ "items": [], "_links": { "self": "/api/Orders?shopperId=4282500&pageNumber=1&pageSize=6", "next": "/api/Orders?shopperId=4282500&pageNumber=2&pageSize=6", "previous": "/api/Orders?shopperId=4282500&pageNumber=1&pageSize=6" } }) }, 3000) }) } function fetchOrderDetails(orderId) { if (!useTestAPI) { return getOrderDetails(orderId); } else { return testGetOrderDetails(); } } function getOrderDetails(orderId) { return new Promise(function(resolve, reject) { $.ajax({ url: `https://prod.mobile-api.woolworths.com.au/wow/v1/orders/api/orders/${orderId}`, type: 'GET', contentType: 'application/json', headers: { "x-api-key": "s7iXf5Rixn4XxFrsYh4HKkriVp8hlnec" }, xhrFields: { withCredentials: true }, crossDomain: true }).done((res) => { resolve(res); }).fail((res) => { reject(res); }) }); } function testGetOrderDetails() { return new Promise((resolve, reject) => { setTimeout(() => { resolve({ "DeliveryWindowId": 628988, "DeliveryInstructions": "", "CanLeaveOrderUnattended": false, "ContainsFrozen": true, "ContainsRestrictedBySignature": false, "ContainsRestrictedBySignatureAndPhotoId": false, "DeliveryStreet1": "20 Bridge St", "DeliveryStreet2": "EPPING NSW", "DeliverySuburb": "Epping", "DeliveryPostCode": "2121", "OrderProducts": [{ "Ordered": { "StockCode": 175905, "Brand": "Woolworths", "Name": "Woolworths 12 Extra Large Free Range Eggs", "Quantity": 5, "Total": 26, "TotalExcludingGst": 0, "ListPrice": { "Measure": "Each", "Value": 5.2 }, "SalePrice": { "Measure": "Each", "Value": 5.2 }, "ComparativePrice": { "Measure": "100G", "Value": 0.74 }, "AllowSubstitution": true, "LineNumber": 1, "IsPurchasableWithRewardsCredits": false, "IsGiftable": false, "IsNotSelfServiceReturnable": false } }, { "Ordered": { "StockCode": 463666, "Brand": "Chobani", "Name": "Chobani Plain Whole Milk Greek Yogurt", "Quantity": 1, "Total": 7, "TotalExcludingGst": 0, "ListPrice": { "Measure": "Each", "Value": 7 }, "SalePrice": { "Measure": "Each", "Value": 7 }, "ComparativePrice": { "Measure": "100G", "Value": 0.77 }, "AllowSubstitution": true, "LineNumber": 2, "IsPurchasableWithRewardsCredits": false, "IsGiftable": false, "IsNotSelfServiceReturnable": false } }, { "Ordered": { "StockCode": 117381, "Brand": "Macro", "Name": "Macro Organic Carrots", "Quantity": 1, "Total": 4.5, "TotalExcludingGst": 0, "ListPrice": { "Measure": "Each", "Value": 4.5 }, "SalePrice": { "Measure": "Each", "Value": 4.5 }, "ComparativePrice": { "Measure": "1KG", "Value": 6 }, "AllowSubstitution": true, "LineNumber": 3, "IsPurchasableWithRewardsCredits": false, "IsGiftable": false, "IsNotSelfServiceReturnable": false } }, { "Ordered": { "StockCode": 785977, "Brand": "Nong Shim", "Name": "Nong Shim Shin Ramyun", "Quantity": 4, "Total": 18, "TotalExcludingGst": 0, "ListPrice": { "Measure": "Each", "Value": 7 }, "SalePrice": { "Measure": "Each", "Value": 4.5 }, "ComparativePrice": { "Measure": "100G", "Value": 0.75 }, "AllowSubstitution": true, "LineNumber": 4, "IsPurchasableWithRewardsCredits": false, "IsGiftable": false, "IsNotSelfServiceReturnable": false } } ], "OrderDiscountDetailsList": [], "PaymentDetails": { "MarketTotalByVendor": {}, "TotalBeforeSavings": 65.5, "Savings": 10, "Subtotal": 55.5, "OrderDiscount": 0, "DeliveryFeeBeforeDiscount": 13, "DeliveryFeeDiscount": 0, "DeliveryFee": 13, "MarketShippingFee": 0, "MarketShippingFeeBeforeDiscount": 0, "MarketShippingFeeDiscount": 0, "MarketSellerShippingFees": [], "Total": 69.5, "AdditionalDeductions": 0, "AmountToPay": 69.5, "PaidBy": [{ "Type": "CreditCard", "Amount": 69.5 }], "WowTotal": 69.5, "CompleteTotal": 69.5, "MarketplaceTotal": 0, "MarketplaceSubtotal": 0, "WowSubtotal": 55.5, "TeamDiscount": 0, "OrderDiscountWithoutTeamDiscount": 0, "PackagingFeeBeforeDiscount": 1, "PackagingFeeDiscount": 0, "PackagingFee": 1, "PackagingFeeLabel": "Reusable bags", "MarketDeliveryFee": 0 }, "RewardsPointsToCollect": 56, "RewardsCreditsToCollect": 0, "RewardsCreditsRedeemed": 0, "IsRewardsEarningsAvailable": true, "FulfilmentStore": { "Id": 8881, "Name": "Lidcombe CFC", "Timezone": "AUS Eastern Standard Time", "Url": "", "PhoneNumber": "", "Street1": "6 Hill Road", "Street2": "", "Area": "8881 Lidcombe CFC LOCAL", "PostCode": "2141", "Suburb": "Lidcombe Place Holder Suburb", "State": "" }, "RewardsCardNumber": "9355130014696", "IsRedelivery": false, "AmendmentCutOffStoreTime": "2023-02-05T00:45:00+11:00", "HasMarketOrderGiftingDetails": false, "DeliveryDelayed": false, "OrderId": 148153401, "CreatedDate": "2023-01-30T18:20:33.586949+11:00", "OriginalOrderCreatedDate": "2023-01-30T18:20:33.586949+11:00", "Total": 69.5, "CurrentStatus": `${testOrderStatus}`, "DeliveryMethod": `${testDeliveryMethod}`, "ProjectedDeliveryTime": { "Status": "OnTime", "OriginalStartTime": "2023-02-05T12:00:00", "OriginalEndTime": "2023-02-05T17:00:00", "StartTime": "2023-02-05T12:00:00", "EndTime": "2023-02-05T17:00:00", "BufferType": "None" }, "IsPfdOrder": false, "OrderType": "Standard", "MarketOrders": [], "IsMarketOnly": false, "GroceriesOrderId": 148153401, "IsPostPickPayOrder": false, "IsThirdPartyDelivery": false } ) }, 1500) }) } function fetchEdrCard() { if (!useTestAPI) { return getEdrCard(); } else { return testGetEdrCard(); // return testNoEdrCard(); } } function getEdrCard() { return new Promise(function(resolve, reject) { $.ajax({ url: `https://www.woolworths.com.au/apis/ui/EdrCard`, type: 'GET', contentType: 'application/json' }).done((res) => { resolve(res); }).fail((res) => { reject(res); }) }); } function testGetEdrCard() { return new Promise((resolve, reject) => { setTimeout(() => { resolve({ "NoValidEdrCardMessage": null, "HasValidAndRegisteredEdrCardMessage": "Your Woolworths Rewards cards has been accepted.", "HasValidAndUnRegisteredEdrCardMessage": null, "IsStaffMemberMessage": null, "CardValidationResult": "NotApplicable", "CardNumber": "9355130014696", "Isprimary": true, "Password": null, "Status": "Registered", "ShopperId": 4282500, "ValidatePassword": true, "Crn": "" }) }, 3000) }) } function testNoEdrCard() { return new Promise((resolve, reject) => { setTimeout(() => { resolve({}) }, 3000) }) } function fetchEdrCardBalance(cardNumber) { if (!useTestAPI) { return getEdrCardBalance(cardNumber); } else { return testEdrCardBalance(); } } function getEdrCardBalance(cardNumber) { return new Promise(function(resolve, reject) { $.ajax({ url: `https://www.woolworths.com.au/apis/ui/EdrCard/BalanceSummary?cardNumber=${cardNumber}`, type: 'GET', contentType: 'application/json' }).done((res) => { resolve(res); }).fail((res) => { reject(res); }) }); } let testEdrBalance = 1622; function testEdrCardBalance() { return new Promise((resolve, reject) => { setTimeout(() => { resolve({ "SaveForLaterPreference": { "Preference": "Automatic", "QffPoints": null, "PayOutDate": null, "RoundedCurrentVoucherBalance": 0, "IsLessThanMinimumBalance": false }, "Response": { "IsError": false, "Result": { "ReturnCode": "0", "ErrorMessage": "" }, "ReturnCode": "Success", "LifeTimeEarn": "1", "LifeTimeRedeem": "0", "CurrentPointBalance": `${testEdrBalance}`, "CurrentVoucherBalance": "0", "NextVoucherExpiry": "2023-02-01", "QffVoucherBalance": null, "LifeTimeCreditEarn": "3", "LifeTimeCreditRedeem": "0", "CurrentCreditBalance": "3", "ErrorMessage": null }, "LifeTimeEarn": 1, "LifeTimeRedeem": 0, "CurrentPointBalance": testEdrBalance, "CurrentVoucherBalance": 0, "NextVoucherExpiry": null, "LifeTimeCreditEarn": 3, "LifeTimeCreditRedeem": 0, "CurrentCreditBalance": 3, "IsError": false, "ErrorMessage": null, "DisplayErrorMessage": null }) }, 1000) }) } // show and hide password when clicking on the eye $(".password-with-eye").click(function() { if ($(this).parent(".password-textbox").find("input").attr("type") == "password") { $(this).parent(".password-textbox").find("input").attr("type", "text"); $(this).find("i").removeClass("iconAct-Visibility_Off").addClass("iconAct-Visibility"); } else { $(this).parent(".password-textbox").find("input").attr("type", "password"); $(this).find("i").removeClass("iconAct-Visibility").addClass("iconAct-Visibility_Off"); } });
# ${orderId}.
Order Status
${orderStatus}.
Fulfilment method
${fulfilmentMethod} .Order date
${orderDate} .Action 1 is
Track OrderAction 2 is
` ); if(orderStatus !== "Cancelled") { fetchOrderDetails(orderId).then(res => { let amendmentCutOffStoreTime = res.AmendmentCutOffStoreTime ? res.AmendmentCutOffStoreTime : ""; if(amendmentCutOffStoreTime) { amendOrderByDateTime = moment(amendmentCutOffStoreTime).format( 'LT [on] dddd, D MMM'); // logic if order pickup has expired let ammendHtml = ""; // check if the cutoff date is before current date if(moment(amendmentCutOffStoreTime).isBefore(moment())) { let projectedDeliveryStartTime = order.ProjectedDeliveryTime.StartTime ? moment(order.ProjectedDeliveryTime.StartTime).format('LT') : ""; let projectedDeliveryEndTime = order.ProjectedDeliveryTime.EndTime ? moment(order.ProjectedDeliveryTime.EndTime).format('LT') : ""; amendHtml = ` You may Delivery Window
`); } if(orderList.length == index) { isOrderCardSetupDone = true; } }); if(isMultiOrder && isOrderCardSetupDone) { // update orders section title to display no. of orders $('.lux-my-orders-title').html(`My orders (${orderList.length})`); } } else { // replace loading orders container with no orders container $('.my-orders.loading').replaceWith( `
` $(errorHTML).insertAfter("#page2 .find-delivery h4.tab-heading"); } }) } function deliveryAddressUpdateFulfilment(selectedAddressId) { $.ajax({ url: `${url}/ui/Fulfilment`, type: 'POST', data: { "addressId": selectedAddressId, "fulfilmentMethod": "Courier" } }).then(() => { getCustomerInfoAsync().then((res) => { totalData = res updateDeliveryTimeDisplay() updateDeliveryMethod() openDeliveryPickupSidePanel() }) }) } // open pick time for delivery side panel function openDeliveryPickupSidePanel() { $('.open-side.time-to').first().click() } // manual delivery address entry $('body').on('click', '.addressSelector-enterManually', function(e) { e.preventDefault() $('.delivery-warning').addClass('hide') showManualDeliveryAdressInput() }) function showManualDeliveryAdressInput() { $('.find-delivery').hide() $('#auto-delivery-buttons-container').hide() $('#manual-delivery-search').show() $('#manual-delivery-buttons-container').show() $('.previous-add').hide() $('#page2').addClass('manual') $('#page2').removeClass('auto') } function hideManualDeliveryAdressInput() { $('.find-delivery').show() $('#auto-delivery-buttons-container').show() $('#manual-delivery-search').hide() $('#manual-delivery-buttons-container').hide() $('#page2').removeClass('manual') $('#page2').addClass('auto') if (previousAddresses) { $('.find-delivery').hide() $('.previous-delivery, .add-address-button').show() $('.previous-add').hide() } } // button to return to auto delivery search from manual delivery search $('#manual-delivery-buttons-container .linkButton.fulfilment-button').click(function(e) { e.preventDefault() hideManualDeliveryAdressInput() }) // add class to input boxes on input so labels stay small if they hhave text $('#shared-text-input-11, #shared-text-input-12, input[name="Postcode"]').on('input', function() { let text = $(this).val() if (text.length) { $(this).addClass('input-with-value') } if (!text.length) { $(this).removeClass('input-with-value') } }) // retrieve the suburbs for the select when you input a postcode for manual delivery search $('input[name="Postcode"]').on('input', function() { let postcode = $(this).val() $('shared-dropdown[name="Suburb"] select').empty() if (postcode.length >= 4) { retrieveSuburbsFromPostCode(postcode).then((res) => { res.Response.forEach(option => { $('shared-dropdown[name="Suburb"] select').append( `` ) }) }) } else { $('shared-dropdown[name="Suburb"] select').append( `` ) } }) function retrieveSuburbsFromPostCode(postcode) { return $.ajax({ url: `${url}/ui/address/suburb/${postcode}`, type: 'GET' }) } // remove validation messages on input to input fields for manual delivery $('shared-textbox[name="Street1"]').on('input', function() { $(this).find('shared-validation-messages').hide() // if this has text then add class let text = $(this).find('input').val() if (text.length) { $(this).addClass('input-with-value') } else { $(this).removeClass('input-with-value') } }) $('shared-dropdown[name="Suburb"], shared-textbox[name="Postcode"]').on('input', function() { $('shared-dropdown[name="Suburb"]').find('shared-validation-messages').hide() $('shared-textbox[name="Postcode"]').find('shared-validation-messages').hide() }) // submit manual delivery search form function manual_delivery() { let form = $('#page2.manual') $(form).find('shared-validation-messages').hide() $(form).find('shared-dropdown[name="Suburb"]').removeClass('ng-invalid') $(form).find('shared-textbox[name="Postcode"]').removeClass('ng-invalid') $(form).find('shared-textbox[name="Street1"]').removeClass('ng-invalid') let street_address1 = $(form).find('input[name="Street1"]').val(); let street_address2 = $(form).find('input[name="Street2"]').val(); let postcode = $(form).find('input[name="Postcode"]').val(); let suburb = $(form).find('select#shared-dropdown-input-4').val(); let suburbObject = { Text: $('#shared-dropdown-input-4').find(':selected').text(), Id: $('#shared-dropdown-input-4').find(':selected').attr('data-id'), IsNonServiced: $('#shared-dropdown-input-4').find(':selected').attr('data-serviced') } let suburbId = $('#shared-dropdown-input-4').find(':selected').attr('data-id') let dataObject = { Postcode: postcode, Street1: street_address1, Street2: street_address2, Suburb: suburbObject, SuburbId: suburbId } if (!street_address1 || !postcode || !suburb) { if (!street_address1) { $(form).find('input[name="Street1"]').siblings('shared-validation-messages').show() $(form).find('shared-textbox[name="Street1"]').addClass('ng-invalid') } if (!postcode) { $(form).find('input[name="Postcode"]').siblings('shared-validation-messages').show() $(form).find('shared-textbox[name="Postcode"]').addClass('ng-invalid') } if (!suburb) { $(form).find('select#shared-dropdown-input-4').siblings('shared-validation-messages').show() $(form).find('shared-dropdown[name="Suburb"]').addClass('ng-invalid') } else { $('.addressSelectorManual-postcodeSuburbInput').removeClass('empty-drop') } } else { if (isUserLoggedIn) { manualDeliveryAddressCall(dataObject) } else { window.location.href = '/shop/securelogin' } } } $('body').on('click', '#page2.manual button[type="submit"].shopper-action', function(e) { e.preventDefault() manual_delivery() }) $('.fms-form shared-address-selector-manual input').on('keypress', function(e) { if (e.which == 13) { e.preventDefault() manual_delivery() } }) function manualDeliveryAddressCall(data) { $.ajax({ url: `${url}/ui/address/manual`, type: 'POST', contentType: 'application/json;', data: JSON.stringify(data) }).then(res => { let addressId = res.Address.AddressId deliveryAddressUpdateFulfilment(addressId) }) } // pickup and to boot // on-input pick-up address populate with list-items $('body').on('input', '#pickupAddressSelector, #pickupAddressSelectorBoot', function() { const pickup_or_boot = $(this).closest('.page-hide').attr('id') === 'page3' ? 'pickup' : 'boot' var searchVal = $(this).val() if (searchVal.length) { $(this).addClass('input-with-value') } if (!searchVal.length) { $(this).removeClass('input-with-value') } $.ajax({ url: `${url}/ui/StoreLocator/Suburbs`, type: 'GET', data: { "SearchTerm": searchVal } }).then((res) => { $('ul.list.ng-star-inserted').remove() if (pickup_or_boot === 'pickup') $('
').insertAfter( '#pickup-results') if (pickup_or_boot === 'boot') $('
').insertAfter( '#boot-results') if (!res.Suburbs.length) { $('ul.list.ng-star-inserted').append( `
` ) } if (res.Suburbs.length > 0) { if (pickup_or_boot === 'pickup') { res.Suburbs.forEach((suburb, index) => { $('ul.list.ng-star-inserted').append(`
${suburb.SuburbStateString}
`) }) } if (pickup_or_boot === 'boot') { res.Suburbs.forEach((suburb, index) => { $('ul.list.ng-star-inserted').append(`
${suburb.SuburbStateString}
`) }) } } }) }) // reset search when no results found $('body').on('click', '.drawer .reset-search', function(e) { $('#pickupAddressSelector').focus() e.preventDefault() $('#pickupAddressSelector').val('') $('#pickupAddressSelectorBoot').val('') inputIcons($(e.target)) $('ul.list.ng-star-inserted').remove() }) // selecting a suburb from list of suburbs for pickup and boot $('body').on('click', '.suburb-list-item', function() { const pickup_or_boot2 = $(this).closest('.page-hide').attr('id') === 'page3' ? 'pickup' : 'boot' const pickup_or_boot_api_value = $(this).closest('.page-hide').attr('id') === 'page3' ? 'Pickup' : 'DriveUp' const postCode = $(this).data('postcode') if (pickup_or_boot2 === 'pickup') { $('input#pickupAddressSelector').val(postCode) $('.pick-up-warning').addClass('hide') } if (pickup_or_boot2 === 'boot') { $('.direct-boot-warning').addClass('hide') $('input#pickupAddressSelectorBoot').val(postCode) } getListPickupStores({ postCode }) }) // get all stores that match a location and append them to the page function getListPickupStores(location) { return $.ajax({ url: `${url2}/v3/ui/fulfilment/stores`, type: 'GET', data: { ...location } }).then((res) => { //set first address as selected address id if (res && Array.isArray(res) && res.length > 0 && res[0].AddressId) { addressIdItem = res[0].AddressId } $('.stores.ng-star-inserted').remove() $('#page3 fieldset').append( '
') const pickUpContent = (pickupOrDriveUp) => { if (pickupOrDriveUp === 'Pickup') { return ` In-store pick up` } if (pickupOrDriveUp === 'DriveUp') { return ` Direct to boot` } } res.forEach((suburb, index) => { $('.stores.ng-star-inserted').append(` `) }) $('.list.ng-star-inserted').html('') }).then(() => { // hide all options after first 4 $('.suburb-list-item2:gt(4)').hide() // select the first option by default $('.suburb-list-item2:first input').prop("checked", true); // append the "view more button" when required let button = `` if ($('.suburb-list-item2').length > 5) { $(document).find('#page3 div.tab-content.ng-star-inserted .stores.ng-star-inserted').append( button) } // hide order options info $('#page3 .tab-content div.cvp.ng-star-inserted').hide() }) } // view more button for suburbs $(document).on('click', '.view-more-button', function() { const pickup_or_boot = $(this).closest('.page-hide').attr('id') === 'page3' ? 'pickup' : 'boot' if (pickup_or_boot === 'pickup') { $('.suburb-list-item2:hidden:lt(5)').show() if ($('.suburb-list-item2:hidden').length == 0) { $('.view-more-button').hide() $('.stores:last-child').css('border', 'none') } } if (pickup_or_boot === 'boot') { $('.suburb-list-item3:hidden:lt(5)').show() if ($('.suburb-list-item3:hidden').length == 0) { $('.view-more-button').hide() } } }) let addressIdItem; let fulfilmentMethod; // select a pickup or driveup location from the menu $('body').on('click', '.suburb-list-item2', function() { addressIdItem = $(this).data('id') fulfilmentMethod = $(this).data('fulfilmentMethod') // update input icons $('.suburb-list-item2 input').prop("checked", false); $(this).find('input').prop("checked", true); }) // pickup save button $('body').on('click', '.pickup-save', function(e) { e.preventDefault(e) if ($('#pickupAddressSelector').val() != '' || $('.suburb-list-item2').length) { $('.pick-up-warning').addClass('hide') $(this).find('.spinner-button').removeClass('hide') $(this).find('.button-text').addClass('hide') pickupMethodFulfilmentCall(fulfilmentMethod) let _this = $(this) setTimeout(function() { $(_this).find('.spinner-button').addClass('hide') $(_this).find('.button-text').removeClass('hide') }, 5000) } else { $('.pick-up-warning').removeClass('hide') } }) function pickupMethodFulfilmentCall(pickupMethod) { if (addressIdItem) { if (isUserLoggedIn) { $.ajax({ url: `${url}/ui/Fulfilment`, type: 'POST', data: { addressId: addressIdItem, fulfilmentMethod: pickupMethod } }).then(() => { getCustomerInfoAsync().then((res) => { totalData = res updateDeliveryTimeDisplay() updateDeliveryMethod() // open time select modal openDeliveryPickupSidePanel() }) }).then(() => { }) } else { window.location.href = '/shop/securelogin' } } } // update delivery / pickup method display function updateDeliveryMethod() { if (totalData.GetDeliveryInfoRequest && totalData.GetDeliveryInfoRequest.DeliveryMethod) { $('.linkButton.fulfilment-button.ng-star-inserted.back-button').hide() } if (totalData.GetDeliveryInfoRequest && (totalData.GetDeliveryInfoRequest.DeliveryMethod == 'Courier' || totalData.GetDeliveryInfoRequest.DeliveryMethod == 'Null')) { } if (isUserLoggedIn) { if (totalData && totalData.GetDeliveryInfoRequest && totalData.GetDeliveryInfoRequest.DeliveryMethod) { let deliveryDisplayText = totalData.GetDeliveryInfoRequest?.Address?.Description ? totalData .GetDeliveryInfoRequest?.Address?.Description : totalData.GetDeliveryInfoRequest?.Address ?.AddressText ? totalData.GetDeliveryInfoRequest?.Address?.AddressText : "" $('#page1').remove() if (totalData.GetDeliveryInfoRequest.DeliveryMethod == 'Pickup') { $('.lux-fulfilment-method').html(`
Pick up `); $('#deliveryContent, #delivery_display_mobile').html(`
Pick up: ${ deliveryDisplayText} Pick up ${deliveryDisplayText}
`) $('.fulfilment-delivery-address').html(deliveryDisplayText); } else if (totalData.GetDeliveryInfoRequest.DeliveryMethod == 'DriveUp') { $('.lux-fulfilment-method').html(` Direct to boot `); $('#deliveryContent, #delivery_display_mobile').html(`
Direct to boot: ${deliveryDisplayText} Pick up Direct to boot ${deliveryDisplayText}
`) $('.fulfilment-delivery-address').html(deliveryDisplayText); } else { $('.lux-fulfilment-method').html(` Deliver to `); $('#deliveryContent, #delivery_display_mobile').html(`
Delivery to: ${deliveryDisplayText} Delivery to ${deliveryDisplayText}
`) } $('.fulfilment-delivery-address').html(deliveryDisplayText); $(".wx-fs-header__fulfilment-section-arrow .open-side.deliver-to").html('Change'); } } } // update delivery / pickup chosen time display function updateDeliveryTimeDisplay() { let delivery_pickup_text = 'When suits? ' const data = totalData.GetDeliveryInfoRequest let dateString; if (data.ReservedDate.Date) { let reservedDate = moment(data.ReservedDate.Date); let today = moment(); let tomorrow = moment().add(1, 'days'); let time_format_day; if (reservedDate.isSame(today, 'day')) { time_format_day = "Today"; } else if (reservedDate.isSame(tomorrow, 'day')) { time_format_day = "Tomorrow"; } else { time_format_day = reservedDate.format('ddd'); } delivery_pickup_text = 'Chosen time: ' dateString = `
` } else { dateString = `
`; } $('#select_a_time, #select_a_time_mobile').html('') $('#select_a_time, #select_a_time_mobile').append(dateString) if (data.ReservedDate.Date) { $(".wx-fs-header__fulfilment-section-arrow .open-side.time-to").html('Change'); } } // general // prevent forms submitting on enter $('.fms-form').submit(function(e) { e.preventDefault() }) // function to only allow number input function validate(evt) { var theEvent = evt || window.event; // Handle paste if (theEvent.type === 'paste') { key = event.clipboardData.getData('text/plain'); } else { // Handle key press var key = theEvent.keyCode || theEvent.which; key = String.fromCharCode(key); } var regex = /[0-9]|\./; if (!regex.test(key)) { theEvent.returnValue = false; if (theEvent.preventDefault) theEvent.preventDefault(); } } // close search options dropdown when cicking away from it $('body').on('blur', '#deliveryAddressSelector, #pickupAddressSelector, #pickupAddressSelectorBoot', function() { setTimeout( function() { $('ul.list.ng-star-inserted').hide() }, 500) }); // reopen search options when focus back $('body').on('focus', '#deliveryAddressSelector, #pickupAddressSelector, #pickupAddressSelectorBoot', function() { $('ul.list.ng-star-inserted').show() }); // search input $('#pickupAddressSelectorBoot, #pickupAddressSelector, #deliveryAddressSelector').on('input', function(e) { inputIcons($(this)) }) $('#pickupAddressSelectorBoot, #pickupAddressSelector, #deliveryAddressSelector').on('focus', function(e) { inputIcons($(this)) }) $('#pickupAddressSelectorBoot, #pickupAddressSelector, #deliveryAddressSelector').on('blur', function(e) { inputIcons($(this)) }) // switch between geolocation icon and the clear text icon function inputIcons(_this) { let _thisParent = _this.closest('shared-pickup-address-selector') let searchTerm = $(_thisParent).find('input').val() if (typeof searchTerm != 'undefined' && searchTerm.length > 0) { if (!$(_thisParent).find('.clear-text').is(':visible')) { $(_thisParent).find('shared-textbox').append( `
` ) } $('.geolocate-icon').hide() } if (typeof searchTerm != 'undefined' && !searchTerm.length) { $(_thisParent).find('.clear-text').remove() $('.geolocate-icon').show() } } $('body').on('click', 'shared-pickup-address-selector .clear-text', function() { $(this).siblings('input').val('') inputIcons($(this).siblings('input')) }) // geolocation let pickupType; // get user location if possible function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(getMatchingLocations); // getMatchingLocations() } else { alert("Geolocation is not supported by this browser."); } } function getMatchingLocations(position) { getListPickupStores(pickupType, { latitude: position.coords.latitude, longitude: position.coords.longitude }) } let pickup_text = 'Search for Pick up location'; let direct_boot_text = 'Search for a Direct to boot location'; let user_location_text = 'Using your location'; $(document).on('keypress ', 'input[name="pickupAddressSelector"]', function() { if ($('#pickupAddressSelector', this)) { $(this).siblings('label.ng-star-inserted').text(pickup_text) } else if ('#pickupAddressSelectorBoot') { $(this).siblings('label.ng-star-inserted').text(direct_boot_text) } }) $(document).on('click', function(e) { if (!$(e.target).is('#geolocationiconDriveUp') && !$(e.target).is('#geolocationiconPickup')) return pickupType = $(e.target).is('#geolocationiconDriveUp') ? 'DriveUp' : 'Pickup' if (pickupType == 'DriveUp') { $('#geolocationiconDriveUp').siblings('shared-typeahead').find('label.ng-star-inserted').text( user_location_text) } else { $('#geolocationiconPickup').siblings('shared-typeahead').find('label.ng-star-inserted').text( user_location_text) } e.preventDefault(e) getLocation() }) $(document).on("click", ".add-address-button", function(e) { e.preventDefault(); $('.previous-delivery, .add-address-button').hide() $('.find-delivery, .previous-add').show() $('#manual-delivery-search').hide() $('#manual-delivery-buttons-container').hide() $('#page2').removeClass('manual') }); $(document).on("click", ".previous-add", function(e) { e.preventDefault(); $('.previous-delivery, .add-address-button').show() $('.find-delivery, .previous-add').hide() $('#manual-delivery-search').hide() $('#manual-delivery-buttons-container').hide() $('#page2').removeClass('manual') });
` ) $(this).find('.product-tile-v2--image img').addClass('is-unavailable'); } else { $(this).find('.cartControls-addButton').show() $(this).find(`.cartControls-inTrolleyWrapper`).remove() $(this).find(`.cart-item-unavailable`).remove() } }); } // update cart with additional populate cart data function updateCart() { const data = cartData $('.item-count-amount').html(data.TotalTrolleyItemQuantity) // add items to cart const items = data.AvailableItems const unavailableItems = data.UnavailableItems populateRHSCart(items, unavailableItems) // update total const total = data.Totals.SubTotal; const totalSavings = data.Totals.TotalSavings.toFixed(2); const numberItems = data.TotalTrolleyItemQuantity; const everydayMarketTotal = data.Totals.MarketTotal; const woolworthstTotal = data.Totals.WoolworthsTotal; updateCartTotal(total, totalSavings, numberItems, everydayMarketTotal, woolworthstTotal) } // populate the RHS cart with the product items // show differently if items are unavailable or available function populateRHSCart(availableItems, unavailableItems) { $('wow-cart-products .auto_products-in-cart').html('') $('#unavailable-items-container').remove() if (unavailableItems.length > 0) { $('wow-cart-products').prepend( ` These items are currently unavailable Unavailable ${item.Discount ? ' SAVE $' + item.Discount.toFixed(2) + ' ' : ''} ${ item.QuantityInTrolley >= item.ProductLimit ? ` ${item.ProductLimit} item limit ` : item.QuantityInTrolley >= item.SupplyLimit ? ` ${item.SupplyLimit} item(s) left ` : '' } $${priceLrg} .${priceSml} ${item.SalePrice.toFixed(2) != (item.ListPrice * item.Quantity).toFixed(2) ? ' Was $' + (item.ListPrice * item.Quantity).toFixed(2) + ' ' : ''} Continue shopping to browse and search for items. ${numberItems} Earn points on this shop Collect points on this shop Link Everyday Rewards Card Everyday Rewards, off next shop off next shop Everyday Rewards, You'll Earn You'll collect Everyday Rewards, You'll Earn You'll collect Saved ${message} Save cart as a list ${item.Name} ${item.PackageSize}
${item.Name} ${item.PackageSize}
Your cart is empty
$${rewardData.WowRewardsToSpend}
${currentBalance} pts
${currentBalance} pts
Are you sure you would like to remove all products from the cart?