Last active
July 12, 2021 08:30
-
-
Save saifulapm/647611cca9f11c2540c715011f33e384 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var dataProducts = []; | |
| var totalProducts = 0; | |
| var dataLoaded = false; | |
| var totalPage = 0; | |
| var maxLimit = 13000; | |
| function getCategory(type, total = 0) { | |
| var brand = $("#brand option:selected").val(); | |
| var year = $("#years option:selected").val(); | |
| var make = $("#make option:selected").val(); | |
| var model = $("#model option:selected").val(); | |
| var subModel = $("#subModel option:selected").val(); | |
| var engine = $("#engine option:selected").val(); | |
| var categoryId = $("#category option:selected").val(); | |
| var partId = $("#parts option:selected").val(); | |
| if (type == 'next') { | |
| if (total != 0) { | |
| var No = total; | |
| } else { | |
| var No = dataProducts['0']['Properties']['endingRecord']; | |
| } | |
| } else { | |
| var No = ""; | |
| } | |
| var recordsPerPage = $('#optionTopPartsPerPage').val(); | |
| var skuName = $('#textSearch').val().trim(); | |
| var skuName = encodeURIComponent(skuName.toUpperCase()); | |
| var value = $('#value').val(); | |
| var now = new Date(); | |
| var n = now.getTime(); | |
| $.ajax({ | |
| type: 'post', | |
| url: 'api/makeEndecaCall/ts=' + n + '', | |
| async: true, | |
| cache: false, | |
| headers: { | |
| 'Cache-Control': 'no-cache, no-store, must-revalidate', | |
| 'Pragma': 'no-cache', | |
| 'Expires': '0' | |
| }, | |
| data: { | |
| recordsPerPage: 50, | |
| year: year, | |
| make: make, | |
| model: model, | |
| subModel: subModel, | |
| engine: engine, | |
| brand: brand, | |
| No: No, | |
| skuName: skuName, | |
| categoryId: categoryId, | |
| partId: partId, | |
| type: "category" | |
| }, | |
| statusCode: { | |
| 500: function() { | |
| alert("Something Went Wrong"); | |
| } | |
| }, | |
| success: function(data) { | |
| totalProducts = data['0']['Properties']['totalNumberOfRecords']; | |
| dataProducts = data; | |
| if (total != 0) { | |
| config.count = 0; | |
| } | |
| dataLoaded = true; | |
| }, | |
| }); | |
| } | |
| var config = { | |
| count: 0 | |
| }; | |
| var cart_id = $("#current_cart_id").val(); | |
| function emptyCart() { | |
| $.ajax({ | |
| type: 'POST', | |
| url: 'api/emptyCart', | |
| data: { | |
| cart_id: cart_id | |
| }, | |
| success: function(data) { | |
| console.log('Current Runing:' + dataProducts['0']['Properties']['endingRecord']); | |
| }, | |
| error: function() { | |
| console.log('Error on Clear Cart'); | |
| } | |
| }); | |
| } | |
| function syncStore(callback) { | |
| if (dataProducts[config.count] !== undefined && dataLoaded && dataProducts['0']['Properties']['endingRecord'] <= maxLimit) { | |
| var item = dataProducts[config.count]; | |
| emptyCart(); | |
| if (!item['Properties']['id']) { | |
| item['Properties']['id'] = item['id']; | |
| } | |
| if (!item['Properties']['titleSku']) { | |
| item['Properties']['titleSku'] = item['Properties']['title']; | |
| } | |
| if (!item['Properties']['P_brand']) { | |
| item['Properties']['P_brand'] = item['brand']; | |
| } | |
| if (item['Properties']['parts']) { | |
| item['Properties']['parts'] = ""; | |
| } | |
| $.ajax({ | |
| type: 'POST', | |
| url: 'addItemToCart', | |
| data: { | |
| properties: item['Properties'], | |
| _token: csrf_token, | |
| recordSpec: item['Record Spec'], | |
| qty: 1, | |
| description: item['description'], | |
| cart_id: cart_id | |
| }, | |
| success: function(cart_data) { | |
| $.ajax({ | |
| type: 'POST', | |
| url: 'checkout', | |
| timeout: 120000, | |
| data: { | |
| cart_id: cart_id, | |
| page: 1, | |
| record_per_page: 10, | |
| _token: csrf_token, | |
| }, | |
| success: function(data) { | |
| if (data['items'][0] != undefined) { | |
| var total = parseFloat(data['total']) + parseFloat(data['total'] * 0.30); | |
| var local_data = { | |
| 'action': 'syncNow', | |
| 'brand': item['brand'], | |
| 'title': item['sku_title'], | |
| 'price': item['Properties']['b2b_price1'], | |
| 'barcode': item['Properties']['oem_Number'], | |
| 'quantity': data['items'][0]['max_available_all'], | |
| 'mainprice': total.toFixed(2), | |
| 'url': url, | |
| 'sku': item['sku'] | |
| }; | |
| $.ajax({ | |
| type: 'POST', | |
| url: "https://portal.rancynautoparts.com/import", | |
| dataType: 'json', | |
| data: local_data, | |
| success: function(data) { | |
| config.count = config.count + 1; | |
| setTimeout(callback, 500); | |
| }, | |
| error: function() { | |
| var local_data = { | |
| 'action': 'addError', | |
| 'sku': item['sku'] | |
| }; | |
| $.ajax({ | |
| type: 'POST', | |
| url: "https://portal.rancynautoparts.com/errors", | |
| dataType: 'json', | |
| data: local_data | |
| }).done(function(json) { | |
| config.count = config.count + 1; | |
| setTimeout(callback, 500); | |
| }); | |
| } | |
| }); | |
| } else { | |
| setTimeout(callback, 500); | |
| } | |
| }, | |
| error: function() { | |
| var local_data = { | |
| 'action': 'addError', | |
| 'sku': item['sku'] | |
| }; | |
| $.ajax({ | |
| type: 'POST', | |
| url: "https://portal.rancynautoparts.com/errors", | |
| dataType: 'json', | |
| data: local_data | |
| }).done(function(json) { | |
| config.count = config.count + 1; | |
| setTimeout(callback, 500); | |
| }); | |
| } | |
| }); | |
| }, | |
| error: function( data ) { | |
| var local_data = { | |
| 'action': 'syncNow', | |
| 'brand': item['brand'], | |
| 'title': item['sku_title'], | |
| 'price': item['Properties']['b2b_price1'], | |
| 'barcode': item['Properties']['oem_Number'], | |
| 'quantity': 0, | |
| 'url': url, | |
| 'mainprice': 0, | |
| 'sku': item['sku'] | |
| }; | |
| $.ajax({ | |
| type: 'POST', | |
| url: "https://portal.rancynautoparts.com/import", | |
| dataType: 'json', | |
| data: local_data, | |
| success: function(data) { | |
| config.count = config.count + 1; | |
| setTimeout(callback, 500); | |
| }, | |
| error: function() { | |
| var local_data = { | |
| 'action': 'addError', | |
| 'sku': item['sku'] | |
| }; | |
| $.ajax({ | |
| type: 'POST', | |
| url: "https://portal.rancynautoparts.com/errors", | |
| dataType: 'json', | |
| data: local_data | |
| }).done(function(json) { | |
| config.count = config.count + 1; | |
| setTimeout(callback, 500); | |
| }); | |
| } | |
| }); | |
| } | |
| }); | |
| } else if(dataLoaded) { | |
| if(totalProducts > dataProducts['0']['Properties']['endingRecord'] && dataProducts['0']['Properties']['endingRecord'] <= maxLimit) { | |
| dataLoaded = false; | |
| totalPage = totalPage + 1; | |
| getCategory('next'); | |
| config.count = 0; | |
| setTimeout(callback, 500); | |
| } else { | |
| console.log("Completed " + maxLimit); | |
| } | |
| } else { | |
| setTimeout(callback, 500); | |
| } | |
| } | |
| // Change Brand Here | |
| $('#brand').val('Replacement').trigger('change'); | |
| (function syncNow() { | |
| syncStore(syncNow); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment