Skip to content

Instantly share code, notes, and snippets.

View rgoytacaz's full-sized avatar

Rodrigo Dellacqua rgoytacaz

View GitHub Profile
@rgoytacaz
rgoytacaz / redIf.js
Last active April 22, 2019 15:36
CS list of product refId
function() {
var productIds;
function productsCSV(){
$.ajax({
method: 'GET',
url:'/api/checkout/pub/orders/order-group/'+{{ORDER ID}},
async: false
}).then(function(resp){
productIds = resp[0].items.map(function(product){ return product.refId }).join(',');
@rgoytacaz
rgoytacaz / productIdsCsv.js
Created April 16, 2019 04:35
function that returns a string of productIds separated by commas from dataLayer on orderPlaced page.
//function that returns a string of productIds separated by commas
for (var idx in dataLayer) {
if (dataLayer[idx].hasOwnProperty('ecommerce')){
return dataLayer[idx].ecommerce.purchase.products.map(function(product){ return product.id }).join(','));
}
}
@rgoytacaz
rgoytacaz / forcePricetableUpdate.js
Last active February 22, 2019 14:18
Workaround to update prices at checkout (currently not working)
(function(){
var currentPostalCode = "";
$(window).on('orderFormUpdated.vtex', function(ev, orderForm) {
if(orderForm && orderForm.shippingData && orderForm.shippingData.address && currentPostalCode != orderForm.shippingData.address.postalCode){
currentPostalCode = orderForm.shippingData.address.postalCode;
var params = ({'postalCode':{'value':currentPostalCode}});
//Depends on JQUERY
//Depends on CL Entity's rclastcart field to be public to read
(function(accountName,identityExpiration) {
function setOrRenewUserEmailToSession(email) {
if(email && email != "") {
if(localStorage) { localStorage.setItem("vtex-user-email", email) };
if(vtex && vtex.NavigationCapture) {
//Saves user cart, for abbandoned cart.
@rgoytacaz
rgoytacaz / waiting-example.js
Last active April 16, 2019 04:39
Waiting data to be available dynamically
(function(){
//AVOIDS AN INFINITE LOOP
var tries=0;
var maxTries=5;
var callFunctionOrSetTimeout = function(){
tries++;
if(window.vtexjs&&window.vtexjs.checkout&&window.vtexjs.checkout.orderForm){
console.log('Data available');
// Example input
var item = { id: 35, quantity: 3, seller: 1 }
var attachments = [
{
name: "Ingredientes Hamburguesa con Queso",
values: [
{
"Sin Carne 50gr": "true",
"Sin Cebolla": "false",
"Sin Mostaza": "false",
@rgoytacaz
rgoytacaz / example-logout.js
Last active July 31, 2019 22:01
Example Logout
//dependencies jquery e jquery cookie
//https://plugins.jquery.com/cookie/
function logout(){
$.removeCookie('VTEXSC', {domain:'.'+window.document.domain});
$.removeCookie('checkout.vtex.com', {domain:'.'+window.document.domain});
$.get(vtexjs.checkout.getLogoutURL());
$.get('/no-cache/user/logout');
setTimeout(function(){window.location = "",500);
}
(function(){
var categories = [];
var brands = [];
function slugify(text)
{
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\s-]/g, '-') // remove non-word [a-z0-9_], non-whitespace, non-hyphen characters
@rgoytacaz
rgoytacaz / cashOnDelivery.js
Last active January 25, 2018 10:52
Disables Cash on Delivery payment types, for carriers that do not accept cash on delivery.
(function(){
//Carriers that accepts Cash on Delivery
var carriesCashOnDelivery = [
'Delivery' //Carrier name
];
var paymentGroupCashOnDelivery = '#payment-group-custom201PaymentGroupPaymentGroup'; //Cash On Delivery Payment Group
var defaultPaymentGroup = '#payment-group-creditCardPaymentGroup'; //Default Payment Group
@rgoytacaz
rgoytacaz / vtexCheckoutEvents.js
Last active July 25, 2019 19:48
Examples of events in VTEX Checkout
(function(){
$('#shipping-data').on('enable.vtex', function(){
console.log('Shipping Data just opened.');
});
$(window).on('orderFormUpdated.vtex', function(ev, orderForm) {
console.log('Order Form updated.');
});