Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. $(".prateleira > ul > li").each(function(){
  2. var id = $(this).find(".produtoContent").attr("id");
  3. if(id === undefined) return;
  4. var $this = $(this);
  5.  
  6. var settings = {
  7. "async": true,
  8. "crossDomain": true,
  9. "url": "//mustique.vtexcommercestable.com.br/api/catalog_system/pub/products/variations/"+id,
  10. "method": "GET",
  11. "headers": {
  12. "Content-Type": "application/json",
  13. "X-VTEX-API-AppKey": "vtexappkey-baliexpress-QUJKUX",
  14. "X-VTEX-API-AppToken": "PURMFGUAXNLKMTHWROGFLKHBCYJJCSNWTNNHZPPJHNCFSDSQHVWFJESENQJGWLYFZORYFAXCYWYYIBJZGTCGWHNOVITJGINWPXFDMTKGYTHNFTWLHKACJRISACDWGNVQ"
  15. }
  16. }
  17.  
  18. $this.find('.selectTamanho select').html("");
  19.  
  20. $.ajax(settings).done(function (response) {
  21. $.map(response.dimensionsMap.tamanho, function(item, index){
  22. $this.find('.selectTamanho select').append('<option sku="'+item+'"">'+item+'</option>');
  23. });
  24. });
  25. });
  26.  
  27. $(document).on("change", ".produtoContent .selectVaricao .selectTamanho", function () {
  28. var idProduto = $(this).closest(".produtoContent").attr("id");
  29. var selectedSku = $("option:selected", this).text();
  30. var $this = $(this);
  31. var $selectCor = $(this).closest(".produtoContent .selectVariacao .selectCor");
  32. console.log($selectCor.html());
  33.  
  34. var settings = {
  35. "async": true,
  36. "crossDomain": true,
  37. "url": "//mustique.vtexcommercestable.com.br/api/catalog_system/pub/products/variations/"+idProduto,
  38. "method": "GET",
  39. "headers": {
  40. "Content-Type": "application/json",
  41. "X-VTEX-API-AppKey": "vtexappkey-baliexpress-QUJKUX",
  42. "X-VTEX-API-AppToken": "PURMFGUAXNLKMTHWROGFLKHBCYJJCSNWTNNHZPPJHNCFSDSQHVWFJESENQJGWLYFZORYFAXCYWYYIBJZGTCGWHNOVITJGINWPXFDMTKGYTHNFTWLHKACJRISACDWGNVQ"
  43. }
  44. }
  45.  
  46. $.ajax(settings).done(function (response) {
  47.  
  48. var skuJson = $.map(response.skus, function(item, index){
  49. if(item.dimensions.tamanho == selectedSku)
  50. return item;
  51. });
  52.  
  53. if(skuJson.length > 0){
  54. $selectCor.html("");
  55.  
  56. $.map(skuJson, function(item, index){
  57. var option = '<option value="'+item.dimensions.cor+'">'+ item.dimensions.cor +'</option>';
  58. $selectCor.append(option);
  59. console.log(option);
  60. });
  61. }
  62.  
  63. console.log($selectCor.html());
  64.  
  65. });
  66.  
  67. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement