Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * #%L
   * BroadleafCommerce Framework
   * %%
   * Copyright (C) 2009 - 2013 Broadleaf Commerce
   * %%
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
  * 
  *       http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * #L%
  */
 package org.broadleafcommerce.core.pricing.service.module;
 
 
 import java.util.Map;

 
 public class BandedShippingModule implements ShippingModule {
     
     private static final Log LOG = LogFactory.getLog(BandedShippingModule.class);
 
     public static final String MODULENAME = "bandedShippingModule";
 
     protected String name = ;
     protected Boolean isDefaultModule = false;
 
     @Resource(name = "blShippingRateService")
 
     private Map<StringStringfeeTypeMapping;
     private Map<StringStringfeeSubTypeMapping;
 
     // this will need to calculate shipping on each fulfilmentGroup in an order
     @Override
         calculateShipping(fulfillmentGroup);
         return fulfillmentGroup;
     }
 
     private void calculateShipping(FulfillmentGroup fulfillmentGroup) {
         if (!isValidModuleForService(fulfillmentGroup.getService()) && !isDefaultModule()) {
             .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) {
             .warn("fulfillment group (" + fulfillmentGroup.getId() + ") does not contain any fulfillment group items. Unable to price banded shipping");
             fulfillmentGroup.setShippingPrice(BroadleafCurrencyUtils.getMoney(.fulfillmentGroup.getOrder().getCurrency()));
             fulfillmentGroup.setSaleShippingPrice(BroadleafCurrencyUtils.getMoney(.fulfillmentGroup.getOrder().getCurrency()));
             fulfillmentGroup.setRetailShippingPrice(BroadleafCurrencyUtils.getMoney(.fulfillmentGroup.getOrder().getCurrency()));
             return;
         }
         Address address = fulfillmentGroup.getAddress();
         String state = (address != null && address.getState() != null) ? address.getState().getAbbreviation() : null;
         BigDecimal retailTotal = new BigDecimal(0);
         String feeType = .get(fulfillmentGroup.getMethod());
         String feeSubType = ((.get(state) == null) ? .get("ALL") : .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 = .readShippingRateByFeeTypesUnityQty(feeTypefeeSubTyperetailTotal);
         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(shippingPricefulfillmentGroup.getOrder().getCurrency()));
        fulfillmentGroup.setSaleShippingPrice(fulfillmentGroup.getShippingPrice());
        fulfillmentGroup.setRetailShippingPrice(fulfillmentGroup.getSaleShippingPrice());
    }
    @Override
    public String getName() {
        return ;
    }
    @Override
    public void setName(String name) {
        this. = name;
    }
    public Map<StringStringgetFeeTypeMapping() {
        return ;
    }
    public void setFeeTypeMapping(Map<StringStringfeeTypeMapping) {
        this. = feeTypeMapping;
    }
    public Map<StringStringgetFeeSubTypeMapping() {
        return ;
    }
    public void setFeeSubTypeMapping(Map<StringStringfeeSubTypeMapping) {
        this. = feeSubTypeMapping;
    }
    @Override
    public String getServiceName() {
    }
    @Override
    public Boolean isValidModuleForService(String serviceName) {
        return getServiceName().equals(serviceName);
    }
    @Override
    public Boolean isDefaultModule() {
        return ;
    }
    @Override
    public void setDefaultModule(Boolean isDefaultModule) {
        this. = isDefaultModule;
    }
New to GrepCode? Check out our FAQ X