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.offer.service.discount.domain;
 
 
 
     
     private static final long serialVersionUID = 1L;
     
     protected PromotableOrder promotableOrder;
     protected Money adjustmentValue;
     protected Offer offer;
     
     protected boolean roundOfferValues = true;
     protected int roundingScale = 2;
 
     public PromotableOrderAdjustmentImpl(PromotableCandidateOrderOffer promotableCandidateOrderOfferPromotableOrder promotableOrder) {
         assert (promotableOrder != null);
         assert (promotableCandidateOrderOffer != null);
 
         this. = promotableCandidateOrderOffer;
         this. = promotableOrder;
         this. = promotableCandidateOrderOffer.getOffer();
         computeAdjustmentValue();
     }
     
     public PromotableOrderAdjustmentImpl(PromotableCandidateOrderOffer promotableCandidateOrderOffer,
             PromotableOrder promotableOrderMoney adjustmentValue) {
         this(promotableCandidateOrderOfferpromotableOrder);
         if (promotableOrder.isIncludeOrderAndItemAdjustments()) {
             this. = adjustmentValue;
         }
     }
 
     @Override
     public PromotableOrder getPromotableOrder() {
         return ;
     }
     
     @Override
     public Offer getOffer() {
         return ;
     }
     
     /*
      * Calculates the value of the adjustment by first getting the current value of the order and then
      * calculating the value of this adjustment.   
      * 
      * If this adjustment value is greater than the currentOrderValue (e.g. would make the order go negative
      * then the adjustment value is set to the value of the order).  
      */
     protected void computeAdjustmentValue() {
         Money currentOrderValue = .calculateSubtotalWithAdjustments();
 
         // Note: FIXED_PRICE not calculated as this is not a valid option for offers.
              = new Money(.getValue(), .getOrderCurrency());            
         } else if (.getDiscountType().equals(.)) {
             BigDecimal offerValue = currentOrderValue.getAmount().multiply(.getValue().divide(new BigDecimal("100"), 5, .));
             
             if (isRoundOfferValues()) {
                 offerValue = offerValue.setScale();
             }
              = new Money(offerValue.getOrderCurrency(), 5);
         }
 
         if (currentOrderValue.lessThan()) {
              = currentOrderValue;
         }
     }
     
     @Override
     public Money getAdjustmentValue() {
        return ;
    }

    
It is sometimes problematic to offer percentage-off offers with regards to rounding. For example, consider an item that costs 9.99 and has a 50% promotion. To be precise, the offer value is 4.995, but this may be a strange value to display to the user depending on the currency being used.
    public boolean isRoundOfferValues() {
        return ;
    }

    

Parameters:
roundingScale
See also:
isRoundOfferValues()
    public void setRoundingScale(int roundingScale) {
        this. = roundingScale;
    }
    public int getRoundingScale() {
        return ;
    }

    

Parameters:
roundingMode
See also:
isRoundOfferValues()
    public void setRoundingMode(RoundingMode roundingMode) {
        this. = roundingMode;
    }
    public RoundingMode getRoundingMode() {
        return ;
    }
    @Override
    public boolean isCombinable() {
        Boolean combinable = .isCombinableWithOtherOffers();
        return (combinable != null && combinable);
    }
    @Override
    public boolean isTotalitarian() {
        Boolean totalitarian = .isTotalitarianOffer();
        return (totalitarian != null && totalitarian.booleanValue());
    }
New to GrepCode? Check out our FAQ X