src/bg/background.js
// A function to use as callback
A function to use as callback
A function to use as callback
function sendData(productData) {
  var partFits = productData.product.partFits;
  delete productData.product.partFits;
  var settings = {
    "url": "https://cors-anywhere.dmvmotorsport.workers.dev/?https://dmv-motorsport.myshopify.com/admin/api/2021-04/products.json",
    "method": "POST",
    "timeout": 0,
    "headers": {
      "Authorization": "Basic ZjI2OGEzZTIwNzk1Njc1ZWQ5Mzg3YjI2ZGQ5YWQ3YWM6c2hwcGFfZGU2YTIxOGJkZGY2MzM5ZjE3ZTEwYzhjZGRiNGNlMTg=",
      "Content-Type": "application/json",
    },
    "data": JSON.stringify(productData)
  };
  $.ajax(settings).done(function (response) {
    console.log(response);
    alert('Sucessfully inserted the product ' + productData.product.title + ' into the shopify database ')
    if (partFits) {
      partFits.forEach(async row => {
        console.log(row);
        var make = row.make;
        var model = row.model;
        var engine = row.engine;
        associateProductToCollection(response.product.id, getShopifyCollectionID(make, model, engine, productData.product.product_type, productData.product.tags[0]));
      });
    }
  });
  return true;
}
function sendData ( productData ) { var partFits = productData . product . partFits ; delete productData . product . partFits ; var settings = { "url" : "https://cors-anywhere.dmvmotorsport.workers.dev/?https://dmv-motorsport.myshopify.com/admin/api/2021-04/products.json" , "method" : "POST" , "timeout" : 0 , "headers" : { "Authorization" : "Basic ZjI2OGEzZTIwNzk1Njc1ZWQ5Mzg3YjI2ZGQ5YWQ3YWM6c2hwcGFfZGU2YTIxOGJkZGY2MzM5ZjE3ZTEwYzhjZGRiNGNlMTg=" , "Content-Type" : "application/json" , } , "data" : JSON . stringify ( productData ) } ; $ . ajax ( settings ) . done ( function ( response ) { console . log ( response ) ; alert ( 'Sucessfully inserted the product ' + productData . product . title + ' into the shopify database ' ) if ( partFits ) { partFits . forEach ( async row => { console . log ( row ) ; var make = row . make ; var model = row . model ; var engine = row . engine ; associateProductToCollection ( response . product . id , getShopifyCollectionID ( make , model , engine , productData . product . product_type , productData . product . tags [ 0 ] ) ) ; } ) ; } } ) ; return true ; }
A function to use as callback
A function to use as callback
//console.log(productData); //"Cookie": "_s=c80372d5-cb20-4c55-a5b1-882b90944746; _shopify_fs=2021-04-15T18%3A22%3A01Z; _shopify_s=c80372d5-cb20-4c55-a5b1-882b90944746; _shopify_y=5c6badc7-20ea-4103-a8a6-7e25b5e15562; _y=5c6badc7-20ea-4103-a8a6-7e25b5e15562"