Last active
December 20, 2015 21:19
-
-
Save ricardodantas/6196539 to your computer and use it in GitHub Desktop.
extbCarrinhoFlutuante.js
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 CarrinhoFlutuante = { | |
| getProductImage: function(product_id,element_to_insert){ | |
| $.ajax({ | |
| url: '/produto/sku/'+product_id, | |
| type: 'get', | |
| dataType: 'json', | |
| success: function(data, textStatus, xhr) { | |
| var image_path = data[0].Images[0][0].Path; | |
| $(element_to_insert).html('<img src="'+image_path+'" width="50" height="50" />'); | |
| } | |
| }); | |
| }, | |
| render: function(){ | |
| $.ajax({ | |
| url: '/orderformitemssummary', | |
| type: 'POST', | |
| dataType: 'json', | |
| data: {access: 'true'}, | |
| complete: function(xhr, textStatus) { | |
| console.log("[EXTB - Script] Requisição de informações finalizada."); | |
| }, | |
| success: function(data, textStatus, xhr) { | |
| var itens_total = data.length; | |
| var $cart_container = $('.extbCart'); | |
| var $cart_dropdown = $('<div class="extbCartDropDown" />').appendTo($cart_container); | |
| if($cart_dropdown.length > 0){ | |
| $cart_dropdown.append('<ul class="ulCartDropDown" />') | |
| for(var i = 0; i < itens_total ; i++){ | |
| var valor = data[i].Value.toString(); | |
| valor = valor.replace('.',','); | |
| $('.ulCartDropDown').append(' \ | |
| <li class="item count_'+i+'"> \ | |
| <div class="wrapItem"> \ | |
| <div class="img"><img src="/arquivos/ajaxLoading.gif"/></div> \ | |
| <div class="title"><span class="qty">('+data[i].Amount+'x)</span> '+data[i].ProductVariantName+'</div> \ | |
| <div class="price">R$ '+valor+'</div> \ | |
| </div> \ | |
| </li> \ | |
| '); | |
| CarrinhoFlutuante.getProductImage(data[i].ProductVariantId, '.ulCartDropDown li.item.count_'+i+' .wrapItem .img'); | |
| } | |
| } | |
| }, | |
| error: function(xhr, textStatus, errorThrown) { | |
| console.error("[EXTB - Script] Erro ao tentar requisitar as informações do carrinho de compras. \n"+textStatus); | |
| } | |
| }); | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment