Extension Point: Shopping Cart Item Events
Basics
Parameter | Value |
---|---|
Extension Point Key | SHOPPING_CART_ITEM_EVENT |
Extension Point Name | Shopping Cart Item Event |
Extension Interface | ShoppingCartItemEvent |
Supports Multiple Extensions? | Yes |
Selector Type | None |
Available Since | 1.3.0 |
Use Cases
Extensions implementing this Extension Point are notified when shopping cart line item events occur.
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.
itemAdded
The itemAdded
method is invoked when a new shopping cart line item is added to a shopping cart in Cortex.
itemRemoved
The itemRemoved
method is invoked when a shopping cart line item is removed from a shopping cart in Cortex.
itemUpdated
The itemUpdated
method is invoked when the quantity or cart item modifier values are changed on a shopping cart line item in Cortex.
Extension Sample
@SuppressWarnings("checkstyle:magicnumber")
@Extension
@XPFAssignment(extensionPoint = XPFExtensionPointEnum.SHOPPING_CART_ITEM_EVENT, priority = 100)
public class SegmentCartItemEvents extends XPFExtensionPointImpl implements ShoppingCartItemEvent {
private static final String ATTRIBUTE_KEY_NAME = "name";
private static final String ATTRIBUTE_KEY_SKU_CODE = "sku-code";
private static final String ATTRIBUTE_KEY_QUANTITY = "quantity";
@Override
public XPFDeliveryPolicy getDeliveryPolicy() {
XPFDeliveryPolicy xpfDeliveryPolicy = new XPFDeliveryPolicy();
xpfDeliveryPolicy.setConsumerQueueName("segment");
xpfDeliveryPolicy.setMaximumRedeliveries(10);
xpfDeliveryPolicy.setRedeliveryDelay(10000); // 10 seconds
return xpfDeliveryPolicy;
}
@Override
public void itemAdded(final XPFCartItemShopperEventContext xpfCartItemShopperEventContext) {
Analytics analytics = (Analytics) XPFExternalPlugin.getInstance().getContext().getCustomData().get("analytics");
if (analytics != null) {
XPFShoppingItem shoppingItem = xpfCartItemShopperEventContext.getShoppingItem();
XPFShoppingCart shoppingCart = xpfCartItemShopperEventContext.getShoppingCart();
analytics.enqueue(TrackMessage.builder("Shopping cart item added")
.userId(shoppingCart.getShopper().getUser().getSharedId())
.properties(ImmutableMap.<String, Object>builder()
.put(ATTRIBUTE_KEY_NAME, shoppingCart.getModifierFields().get(ATTRIBUTE_KEY_NAME))
.put(ATTRIBUTE_KEY_SKU_CODE, shoppingItem.getProductSku().getCode())
.put(ATTRIBUTE_KEY_QUANTITY, shoppingItem.getQuantity())
.build()));
}
}
@Override
public void itemRemoved(final XPFCartItemShopperEventContext xpfCartItemShopperEventContext) {
Analytics analytics = (Analytics) XPFExternalPlugin.getInstance().getContext().getCustomData().get("analytics");
if (analytics != null) {
XPFShoppingItem shoppingItem = xpfCartItemShopperEventContext.getShoppingItem();
XPFShoppingCart shoppingCart = xpfCartItemShopperEventContext.getShoppingCart();
analytics.enqueue(TrackMessage.builder("Shopping cart item removed")
.userId(shoppingCart.getShopper().getUser().getSharedId())
.properties(ImmutableMap.<String, Object>builder()
.put(ATTRIBUTE_KEY_NAME, shoppingCart.getModifierFields().get(ATTRIBUTE_KEY_NAME))
.put(ATTRIBUTE_KEY_SKU_CODE, shoppingItem.getProductSku().getCode())
.put(ATTRIBUTE_KEY_QUANTITY, shoppingItem.getQuantity())
.build()));
}
}
@Override
public void itemUpdated(final XPFCartItemShopperEventContext xpfCartItemShopperEventContext) {
Analytics analytics = (Analytics) XPFExternalPlugin.getInstance().getContext().getCustomData().get("analytics");
if (analytics != null) {
XPFShoppingItem shoppingItem = xpfCartItemShopperEventContext.getShoppingItem();
XPFShoppingCart shoppingCart = xpfCartItemShopperEventContext.getShoppingCart();
analytics.enqueue(TrackMessage.builder("Shopping cart item updated")
.userId(shoppingCart.getShopper().getUser().getSharedId())
.properties(ImmutableMap.<String, Object>builder()
.put(ATTRIBUTE_KEY_NAME, shoppingCart.getModifierFields().get(ATTRIBUTE_KEY_NAME))
.put(ATTRIBUTE_KEY_SKU_CODE, shoppingItem.getProductSku().getCode())
.put(ATTRIBUTE_KEY_QUANTITY, shoppingItem.getQuantity())
.build()));
}
}
}