Skip to main content
Version: 1.4.x

Extension Point: Shopping Cart Events

Basics​

ParameterValue
Extension Point KeySHOPPING_CART_EVENT
Extension Point NameShopping Cart Event
Extension InterfaceShoppingCartEvent
Supports Multiple Extensions?Yes
Selector TypeNone
Available Since1.3.0

Use Cases​

Extensions implementing this Extension Point are notified when shopping cart events occur. Note that adding, removing, or updating shopping cart line items will not cause these events to be called. In these cases, the Shopping Cart Item Events will be called.

Methods​

getDeliveryPolicy​

The getDeliveryPolicy method is invoked during Integration Server startup. It allows the extension to define how retries should be handled if the extension throws an exception. The extension needs to return the following values in the XPFDeliveryPolicy response object:

  • consumerQueueName: An identifier for the consumer message queue that will be used to track events and allow them to be processed asynchronously. This value should be unique for all extensions assigned to this extension point.
  • maximumRedeliveries: The maximum number of redelivery attempts before the message is sent to the dead letter queue.
  • redeliveryDelay: The delay between redelivery attempts, in milliseconds.

created​

The created method is invoked when a new shopping cart is created in Cortex. This can happen either due to the Cortex create cart resource being called, or when a customer accesses their default cart for the first time.

deleted​

The deleted method is invoked when a shopping cart is deleted in Cortex. This happens when a user manually deletes a custom shopping cart.

abandoned​

The abandoned method is invoked when the daily abandoned cart event Quartz job determines that a shopping cart has not been modified in COMMERCE/SYSTEM/ABANDONEDCARTEVENTS/maxHistory days.

updated​

The updated method is invoked when a shopping cart is modified in Cortex. This happens if the billing address, shipping address, selected shipping option, or cart modifier field values are changed. This method will not be invoked if shopping items are added or removed or if the selected payment instruments are changed.

Extension Sample​

@SuppressWarnings("checkstyle:magicnumber")
@Extension
@XPFAssignment(extensionPoint = XPFExtensionPointEnum.SHOPPING_CART_EVENT, priority = 100)
public class SegmentCartEvents extends XPFExtensionPointImpl implements ShoppingCartEvent {

private static final String ATTRIBUTE_KEY_NAME = "name";

@Override
public XPFDeliveryPolicy getDeliveryPolicy() {
XPFDeliveryPolicy xpfDeliveryPolicy = new XPFDeliveryPolicy();
xpfDeliveryPolicy.setConsumerQueueName("segment");
xpfDeliveryPolicy.setMaximumRedeliveries(10);
xpfDeliveryPolicy.setRedeliveryDelay(10000); // 10 seconds
return xpfDeliveryPolicy;
}

@Override
public void created(final XPFShoppingCartEventContext context) {
Analytics analytics = (Analytics) XPFExternalPlugin.getInstance().getContext().getCustomData().get("analytics");
if (analytics != null) {
XPFShoppingCart shoppingCart = context.getShoppingCart();
analytics.enqueue(TrackMessage.builder("Shopping cart created")
.userId(shoppingCart.getShopper().getUser().getSharedId())
.properties(ImmutableMap.<String, Object>builder()
.put(ATTRIBUTE_KEY_NAME, shoppingCart.getModifierFields().get(ATTRIBUTE_KEY_NAME))
.build()));
}
}

@Override
public void updated(final XPFShoppingCartEventContext context) {
Analytics analytics = (Analytics) XPFExternalPlugin.getInstance().getContext().getCustomData().get("analytics");
if (analytics != null) {
XPFShoppingCart shoppingCart = context.getShoppingCart();
analytics.enqueue(TrackMessage.builder("Shopping cart updated")
.userId(shoppingCart.getShopper().getUser().getSharedId())
.properties(ImmutableMap.<String, Object>builder()
.put(ATTRIBUTE_KEY_NAME, shoppingCart.getModifierFields().get(ATTRIBUTE_KEY_NAME))
.build()));
}
}

@Override
public void deleted(final XPFShoppingCartEventContext context) {
Analytics analytics = (Analytics) XPFExternalPlugin.getInstance().getContext().getCustomData().get("analytics");
if (analytics != null) {
XPFShoppingCart shoppingCart = context.getShoppingCart();
analytics.enqueue(TrackMessage.builder("Shopping cart deleted")
.userId(shoppingCart.getShopper().getUser().getSharedId())
.properties(ImmutableMap.<String, Object>builder()
.put(ATTRIBUTE_KEY_NAME, shoppingCart.getModifierFields().get(ATTRIBUTE_KEY_NAME))
.build()));
}
}

@Override
public void abandoned(final XPFShoppingCartEventContext context) {
Analytics analytics = (Analytics) XPFExternalPlugin.getInstance().getContext().getCustomData().get("analytics");
if (analytics != null) {
XPFShoppingCart shoppingCart = context.getShoppingCart();
analytics.enqueue(TrackMessage.builder("Shopping cart abandoned")
.userId(shoppingCart.getShopper().getUser().getSharedId())
.properties(ImmutableMap.<String, Object>builder()
.put(ATTRIBUTE_KEY_NAME, shoppingCart.getModifierFields().get(ATTRIBUTE_KEY_NAME))
.build()));
}
}
}