use of org.broadleafcommerce.core.order.domain.SkuAccessor in project BroadleafCommerce by BroadleafCommerce.
the class GoogleUniversalAnalyticsProcessor method getItemJs.
protected String getItemJs(Order order, String trackerPrefix) {
StringBuffer sb = new StringBuffer();
for (FulfillmentGroup fulfillmentGroup : order.getFulfillmentGroups()) {
for (FulfillmentGroupItem fulfillmentGroupItem : fulfillmentGroup.getFulfillmentGroupItems()) {
OrderItem orderItem = fulfillmentGroupItem.getOrderItem();
Sku sku = ((SkuAccessor) orderItem).getSku();
sb.append("ga('" + trackerPrefix + "ecommerce:addItem', {");
sb.append("'id': '" + order.getOrderNumber() + "'");
sb.append(",'name': '" + sku.getName() + "'");
sb.append(",'sku': '" + sku.getId() + "'");
sb.append(",'category': '" + getVariation(orderItem) + "'");
sb.append(",'price': '" + orderItem.getAveragePrice() + "'");
sb.append(",'quantity': '" + orderItem.getQuantity() + "'");
sb.append("});");
}
}
return sb.toString();
}
use of org.broadleafcommerce.core.order.domain.SkuAccessor in project BroadleafCommerce by BroadleafCommerce.
the class UncacheableDataProcessor method addCartData.
protected void addCartData(Map<String, Object> attrMap) {
Order cart = CartState.getCart();
int cartQty = 0;
List<Long> cartItemIdsWithOptions = new ArrayList<>();
List<Long> cartItemIdsWithoutOptions = new ArrayList<>();
if (cart != null && cart.getOrderItems() != null) {
cartQty = cart.getItemCount();
for (OrderItem item : cart.getOrderItems()) {
if (item instanceof SkuAccessor) {
Sku sku = ((SkuAccessor) item).getSku();
if (sku != null && sku.getProduct() != null && item.getParentOrderItem() == null) {
if (useSku) {
cartItemIdsWithoutOptions.add(sku.getId());
} else {
Product product = sku.getProduct();
List<ProductOptionXref> optionXrefs = product.getProductOptionXrefs();
if (optionXrefs == null || optionXrefs.isEmpty()) {
cartItemIdsWithoutOptions.add(product.getId());
} else {
cartItemIdsWithOptions.add(product.getId());
}
}
}
}
}
}
attrMap.put("cartItemCount", cartQty);
attrMap.put("cartItemIdsWithOptions", cartItemIdsWithOptions);
attrMap.put("cartItemIdsWithoutOptions", cartItemIdsWithoutOptions);
}
Aggregations