Search in sources :

Example 1 with CartItemInfo

use of io.github.zutherb.appstash.shop.service.cart.model.CartItemInfo in project the-app by devops-dojo.

the class CartPanel method cartView.

private Component cartView() {
    cartView = new ListView<CartItemInfo>("cart", cartListModel()) {

        @Override
        protected void populateItem(ListItem<CartItemInfo> item) {
            WebMarkupContainer cartItem = new WebMarkupContainer("item");
            cartItem.add(new Label("name", new PropertyModel<String>(item.getModel(), "product.name")));
            cartItem.add(new IndicatingAjaxLink<Void>("delete") {

                @Override
                public void onClick(AjaxRequestTarget target) {
                    IModel<CartItemInfo> model = item.getModel();
                    send(CartPanel.this, Broadcast.BREADTH, new RemoveFromCartEvent(model.getObject(), target));
                }
            });
            cartItem.add(new Label("price", new PriceModel(new PropertyModel<>(item.getModel(), "totalSum"))));
            item.add(cartItem);
        }
    };
    cartView.setReuseItems(false);
    cartView.setOutputMarkupId(true);
    return cartView;
}
Also used : CartItemInfo(io.github.zutherb.appstash.shop.service.cart.model.CartItemInfo) RemoveFromCartEvent(io.github.zutherb.appstash.shop.ui.event.cart.RemoveFromCartEvent) Label(org.apache.wicket.markup.html.basic.Label) PropertyModel(org.apache.wicket.model.PropertyModel) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) IndicatingAjaxLink(org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxLink) PriceModel(io.github.zutherb.appstash.shop.ui.model.PriceModel)

Example 2 with CartItemInfo

use of io.github.zutherb.appstash.shop.service.cart.model.CartItemInfo in project the-app by devops-dojo.

the class InMemoryCartFulfillmentProviderImpl method addItem.

@Override
public CartItemInfo addItem(ProductInfo productInfo) {
    CartItemInfo cartItemInfo = new CartItemInfo(productInfo);
    getAllItems().add(cartItemInfo);
    return cartItemInfo;
}
Also used : CartItemInfo(io.github.zutherb.appstash.shop.service.cart.model.CartItemInfo)

Example 3 with CartItemInfo

use of io.github.zutherb.appstash.shop.service.cart.model.CartItemInfo in project the-app by devops-dojo.

the class RedisMicroserviceCartFulfillmentProviderImpl method addItem.

@Override
public CartItemInfo addItem(ProductInfo productInfo) {
    synchronized (lock) {
        CartItemInfo cartItemInfo = createCartItemInfo(productInfo);
        CartItem map = mapToCartItem(cartItemInfo);
        if (StringUtils.isEmpty(cartId)) {
            cartId = strip(cartRepository.create(map), "\"");
        } else {
            cartRepository.add(cartId, map);
        }
        return cartItemInfo;
    }
}
Also used : CartItemInfo(io.github.zutherb.appstash.shop.service.cart.model.CartItemInfo) CartItem(io.github.zutherb.appstash.shop.repository.cart.model.CartItem)

Example 4 with CartItemInfo

use of io.github.zutherb.appstash.shop.service.cart.model.CartItemInfo in project the-app by devops-dojo.

the class AbstractFulfillmentProvider method getTotalSum.

public BigDecimal getTotalSum() {
    BigDecimal sum = BigDecimal.ZERO;
    for (CartItemInfo cartItemInfo : getAllItems()) {
        sum = sum.add(cartItemInfo.getTotalSum());
    }
    double globalDiscount = Double.parseDouble(Config.getProperty("GLOBAL_DISCOUNT"));
    double factor = globalDiscount / 100.0;
    double result = sum.doubleValue() - (sum.doubleValue() * factor);
    return new BigDecimal(result);
}
Also used : CartItemInfo(io.github.zutherb.appstash.shop.service.cart.model.CartItemInfo) BigDecimal(java.math.BigDecimal)

Example 5 with CartItemInfo

use of io.github.zutherb.appstash.shop.service.cart.model.CartItemInfo in project the-app by devops-dojo.

the class AbstractFulfillmentProvider method getDiscountSum.

public BigDecimal getDiscountSum() {
    BigDecimal sum = BigDecimal.ZERO;
    for (CartItemInfo cartItemInfo : getAllItems()) {
        sum = sum.add(cartItemInfo.getTotalSum());
    }
    double globalDiscount = Double.parseDouble(Config.getProperty("GLOBAL_DISCOUNT"));
    double factor = globalDiscount / 100.0;
    double result = sum.doubleValue() * factor;
    return new BigDecimal(result);
}
Also used : CartItemInfo(io.github.zutherb.appstash.shop.service.cart.model.CartItemInfo) BigDecimal(java.math.BigDecimal)

Aggregations

CartItemInfo (io.github.zutherb.appstash.shop.service.cart.model.CartItemInfo)5 BigDecimal (java.math.BigDecimal)2 CartItem (io.github.zutherb.appstash.shop.repository.cart.model.CartItem)1 RemoveFromCartEvent (io.github.zutherb.appstash.shop.ui.event.cart.RemoveFromCartEvent)1 PriceModel (io.github.zutherb.appstash.shop.ui.model.PriceModel)1 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)1 IndicatingAjaxLink (org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxLink)1 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)1 Label (org.apache.wicket.markup.html.basic.Label)1 PropertyModel (org.apache.wicket.model.PropertyModel)1