Search in sources :

Example 1 with ShippingRate

use of org.broadleafcommerce.core.pricing.domain.ShippingRate in project BroadleafCommerce by BroadleafCommerce.

the class BandedShippingModule method calculateShipping.

private void calculateShipping(FulfillmentGroup fulfillmentGroup) {
    if (!isValidModuleForService(fulfillmentGroup.getService()) && !isDefaultModule()) {
        LOG.info("fulfillment group (" + fulfillmentGroup.getId() + ") with a service type of (" + fulfillmentGroup.getService() + ") is not valid for this module service type (" + getServiceName() + ")");
        return;
    }
    if (fulfillmentGroup.getFulfillmentGroupItems().size() == 0) {
        LOG.warn("fulfillment group (" + fulfillmentGroup.getId() + ") does not contain any fulfillment group items. Unable to price banded shipping");
        fulfillmentGroup.setShippingPrice(BroadleafCurrencyUtils.getMoney(BigDecimal.ZERO, fulfillmentGroup.getOrder().getCurrency()));
        fulfillmentGroup.setSaleShippingPrice(BroadleafCurrencyUtils.getMoney(BigDecimal.ZERO, fulfillmentGroup.getOrder().getCurrency()));
        fulfillmentGroup.setRetailShippingPrice(BroadleafCurrencyUtils.getMoney(BigDecimal.ZERO, fulfillmentGroup.getOrder().getCurrency()));
        return;
    }
    Address address = fulfillmentGroup.getAddress();
    String state = null;
    if (StringUtils.isNotBlank(address.getStateProvinceRegion())) {
        state = address.getStateProvinceRegion();
    } else if (address.getState() != null) {
        state = address.getState().getAbbreviation();
    }
    BigDecimal retailTotal = new BigDecimal(0);
    String feeType = feeTypeMapping.get(fulfillmentGroup.getMethod());
    String feeSubType = ((feeSubTypeMapping.get(state) == null) ? feeSubTypeMapping.get("ALL") : feeSubTypeMapping.get(state));
    for (FulfillmentGroupItem fulfillmentGroupItem : fulfillmentGroup.getFulfillmentGroupItems()) {
        BigDecimal price = (fulfillmentGroupItem.getRetailPrice() != null) ? fulfillmentGroupItem.getRetailPrice().getAmount().multiply(BigDecimal.valueOf(fulfillmentGroupItem.getQuantity())) : null;
        if (price == null) {
            price = fulfillmentGroupItem.getOrderItem().getRetailPrice().getAmount().multiply(BigDecimal.valueOf(fulfillmentGroupItem.getQuantity()));
        }
        retailTotal = retailTotal.add(price);
    }
    ShippingRate sr = shippingRateService.readShippingRateByFeeTypesUnityQty(feeType, feeSubType, retailTotal);
    if (sr == null) {
        throw new NotImplementedException("Shipping rate " + fulfillmentGroup.getMethod() + " not supported");
    }
    BigDecimal shippingPrice = new BigDecimal(0);
    if (sr.getBandResultPercent().compareTo(0) > 0) {
        BigDecimal percent = new BigDecimal(sr.getBandResultPercent() / 100);
        shippingPrice = retailTotal.multiply(percent);
    } else {
        shippingPrice = sr.getBandResultQuantity();
    }
    fulfillmentGroup.setShippingPrice(BroadleafCurrencyUtils.getMoney(shippingPrice, fulfillmentGroup.getOrder().getCurrency()));
    fulfillmentGroup.setSaleShippingPrice(fulfillmentGroup.getShippingPrice());
    fulfillmentGroup.setRetailShippingPrice(fulfillmentGroup.getSaleShippingPrice());
}
Also used : Address(org.broadleafcommerce.profile.core.domain.Address) ShippingRate(org.broadleafcommerce.core.pricing.domain.ShippingRate) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) NotImplementedException(org.apache.commons.lang.NotImplementedException) BigDecimal(java.math.BigDecimal)

Example 2 with ShippingRate

use of org.broadleafcommerce.core.pricing.domain.ShippingRate in project BroadleafCommerce by BroadleafCommerce.

the class ShippingRateDaoImpl method readShippingRateByFeeTypesUnityQty.

@Override
@SuppressWarnings("unchecked")
public ShippingRate readShippingRateByFeeTypesUnityQty(String feeType, String feeSubType, BigDecimal unitQuantity) {
    Query query = em.createNamedQuery("BC_READ_FIRST_SHIPPING_RATE_BY_FEE_TYPES");
    query.setParameter("feeType", feeType);
    query.setParameter("feeSubType", feeSubType);
    query.setParameter("bandUnitQuantity", unitQuantity);
    List<ShippingRate> returnedRates = query.getResultList();
    if (returnedRates.size() > 0) {
        return returnedRates.get(0);
    } else {
        return null;
    }
}
Also used : Query(javax.persistence.Query) ShippingRate(org.broadleafcommerce.core.pricing.domain.ShippingRate)

Example 3 with ShippingRate

use of org.broadleafcommerce.core.pricing.domain.ShippingRate in project BroadleafCommerce by BroadleafCommerce.

the class CommonSetupBaseTest method createShippingRates.

public void createShippingRates() {
    ShippingRate sr = new ShippingRateImpl();
    sr.setFeeType("SHIPPING");
    sr.setFeeSubType("ALL");
    sr.setFeeBand(1);
    sr.setBandUnitQuantity(BigDecimal.valueOf(29.99));
    sr.setBandResultQuantity(BigDecimal.valueOf(8.5));
    sr.setBandResultPercent(0);
    ShippingRate sr2 = new ShippingRateImpl();
    sr2.setFeeType("SHIPPING");
    sr2.setFeeSubType("ALL");
    sr2.setFeeBand(2);
    sr2.setBandUnitQuantity(BigDecimal.valueOf(999999.99));
    sr2.setBandResultQuantity(BigDecimal.valueOf(8.5));
    sr2.setBandResultPercent(0);
    shippingRateService.save(sr);
    shippingRateService.save(sr2);
}
Also used : ShippingRate(org.broadleafcommerce.core.pricing.domain.ShippingRate) ShippingRateImpl(org.broadleafcommerce.core.pricing.domain.ShippingRateImpl)

Aggregations

ShippingRate (org.broadleafcommerce.core.pricing.domain.ShippingRate)3 BigDecimal (java.math.BigDecimal)1 Query (javax.persistence.Query)1 NotImplementedException (org.apache.commons.lang.NotImplementedException)1 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)1 ShippingRateImpl (org.broadleafcommerce.core.pricing.domain.ShippingRateImpl)1 Address (org.broadleafcommerce.profile.core.domain.Address)1