Search in sources :

Example 1 with SkuAccessor

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();
}
Also used : FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) Sku(org.broadleafcommerce.core.catalog.domain.Sku) SkuAccessor(org.broadleafcommerce.core.order.domain.SkuAccessor)

Example 2 with SkuAccessor

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);
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) ProductOptionXref(org.broadleafcommerce.core.catalog.domain.ProductOptionXref) ArrayList(java.util.ArrayList) Product(org.broadleafcommerce.core.catalog.domain.Product) Sku(org.broadleafcommerce.core.catalog.domain.Sku) SkuAccessor(org.broadleafcommerce.core.order.domain.SkuAccessor)

Aggregations

Sku (org.broadleafcommerce.core.catalog.domain.Sku)2 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)2 SkuAccessor (org.broadleafcommerce.core.order.domain.SkuAccessor)2 ArrayList (java.util.ArrayList)1 Product (org.broadleafcommerce.core.catalog.domain.Product)1 ProductOptionXref (org.broadleafcommerce.core.catalog.domain.ProductOptionXref)1 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)1 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)1 Order (org.broadleafcommerce.core.order.domain.Order)1