Automatically clear shopping Cart

Michael Nash2
Mega Expert

Hi Guys,

 

Is there a way to automatically clear the shopping cart after a certain period of time?

 

Thanks in advance,

1 ACCEPTED SOLUTION

Michael Nash2
Mega Expert

Thanks Guys, 

 

You pointed me in the right direction.

 

I was able to resolve this myself by creating a scheduled job with the below script.

 

expiredCartItem();
function expiredCartItem() {
var cartItem = new GlideRecord('sc_cart_item');
cartItem.addEncodedQuery('sys_created_onRELATIVELE@dayofweek@ago@3'); //delete item from cart if created more than 3 days ago
cartItem.query();
while(cartItem.next()) {
cartItem.deleteRecord();
gs.log(cartItem.cat_item.getDisplayValue() + " expired and removed from users cart: " + cartItem.cart.user.getDisplayValue());
}
}

 

 

View solution in original post

5 REPLIES 5

Michael Nash2
Mega Expert

Thanks Guys, 

 

You pointed me in the right direction.

 

I was able to resolve this myself by creating a scheduled job with the below script.

 

expiredCartItem();
function expiredCartItem() {
var cartItem = new GlideRecord('sc_cart_item');
cartItem.addEncodedQuery('sys_created_onRELATIVELE@dayofweek@ago@3'); //delete item from cart if created more than 3 days ago
cartItem.query();
while(cartItem.next()) {
cartItem.deleteRecord();
gs.log(cartItem.cat_item.getDisplayValue() + " expired and removed from users cart: " + cartItem.cart.user.getDisplayValue());
}
}