Class DefaultCommerceQuoteService

    • Field Detail

      • DATE_TIME_FORMAT

        protected static final java.lang.String DATE_TIME_FORMAT
        See Also:
        Constant Field Values
      • ABSTRACT_ORDER_NAME

        protected static final java.lang.String ABSTRACT_ORDER_NAME
        See Also:
        Constant Field Values
      • ABSTRACT_ORDER_DESCRIPTION

        protected static final java.lang.String ABSTRACT_ORDER_DESCRIPTION
        See Also:
        Constant Field Values
    • Constructor Detail

      • DefaultCommerceQuoteService

        public DefaultCommerceQuoteService()
    • Method Detail

      • createQuoteFromCart

        public QuoteModel createQuoteFromCart​(CartModel cartModel,
                                              UserModel userModel)
        Description copied from interface: CommerceQuoteService
        Creates a new quote based on given cart. Please note that it's the caller's responsibility to persist the new quote. The cart passed into this method is not affected by its business logic.
        Specified by:
        createQuoteFromCart in interface CommerceQuoteService
        Parameters:
        cartModel - the cart model
        userModel - the user performing the operation on the quote
        Returns:
        the new quote model
      • hasQuoteInSessionCart

        protected boolean hasQuoteInSessionCart()
      • loadQuoteAsSessionCart

        public CartModel loadQuoteAsSessionCart​(QuoteModel quoteModel,
                                                UserModel userModel)
        Description copied from interface: CommerceQuoteService
        Loads the given quote into a new session cart or returns the existing session cart if existing session cart already has the quote loaded. If the quote needs to be loaded into a new session cart, it first checks if the action can be performed for the quote. If the action cannot be performed, then a runtime exception is thrown. The method also updates the quote state and saves the existing session cart before replacing it with a new session cart, if needed.
        Specified by:
        loadQuoteAsSessionCart in interface CommerceQuoteService
        Parameters:
        quoteModel - the quote to process
        userModel - the user performing the operation on the quote
        Returns:
        the new session cart loaded with the given quote or the existing session cart if existing session cart already has the quote loaded
      • getCurrentDateTimeFormatted

        protected java.lang.String getCurrentDateTimeFormatted​(java.lang.String format)
      • getQuoteFromSessionCart

        protected java.util.Optional<QuoteModel> getQuoteFromSessionCart()
      • submitQuote

        public QuoteModel submitQuote​(QuoteModel quoteModel,
                                      UserModel userModel)
        Description copied from interface: CommerceQuoteService
        Submits a quote from buyer to seller representative or from seller representative to seller approver. A new version of the same quote will be created on the seller representative or seller approver side.
        Specified by:
        submitQuote in interface CommerceQuoteService
        Parameters:
        quoteModel - the quote to process
        userModel - the user performing the operation on the quote
        Returns:
        the updated quote
      • isRequestThresholdRequired

        protected boolean isRequestThresholdRequired​(QuoteModel quote,
                                                     UserModel user,
                                                     CartModel sessionCart)
        Checks if quote is in a state that requires checking the request threshold.
        Parameters:
        quote -
        user -
        sessionCart -
        Returns:
        true is request threshold is required.
      • getQuoteRequestThreshold

        public double getQuoteRequestThreshold​(QuoteModel quote,
                                               UserModel user,
                                               CartModel sessionCart)
        Description copied from interface: CommerceQuoteService
        Get quote request threshold defined in properties. It will return the property defined threshold amount for current site and currency. If the threshold is not defined for the site and currency, it will return global threshold. If none of these are defined, it will return 0. If quote threshold calculation is not required for the quote, will return an negative number.
        Specified by:
        getQuoteRequestThreshold in interface CommerceQuoteService
        Returns:
        quote request threshold
      • validateQuoteTotal

        protected void validateQuoteTotal​(QuoteModel quoteModel)
      • approveQuote

        public QuoteModel approveQuote​(QuoteModel quoteModel,
                                       UserModel userModel)
        Description copied from interface: CommerceQuoteService
        Approve a quote from seller representative. Send a quote on submit event.
        Specified by:
        approveQuote in interface CommerceQuoteService
        Parameters:
        quoteModel - the quote to process
        userModel - the user performing the operation on the quote
        Returns:
        the updated quote
      • rejectQuote

        public QuoteModel rejectQuote​(QuoteModel quoteModel,
                                      UserModel userModel)
        Description copied from interface: CommerceQuoteService
        Reject a quote from seller representative. Send a quote on submit event.
        Specified by:
        rejectQuote in interface CommerceQuoteService
        Parameters:
        quoteModel - the quote to process
        userModel - the user performing the operation on the quote
        Returns:
        the updated quote
      • updateQuoteFromCart

        public QuoteModel updateQuoteFromCart​(CartModel cartModel,
                                              UserModel userModel)
        Description copied from interface: CommerceQuoteService
        Updates quote with data from cart (and existing quote). Sets the cart as cartReference on to the new quote.
        Specified by:
        updateQuoteFromCart in interface CommerceQuoteService
        Parameters:
        cartModel - cart that has an association to a quote
        userModel - the user performing the operation on the quote
        Returns:
        the updated quote
      • getQuoteList

        public SearchPageData<QuoteModel> getQuoteList​(CustomerModel customerModel,
                                                       UserModel quoteUserModel,
                                                       BaseStoreModel store,
                                                       PageableData pageableData)
        Description copied from interface: CommerceQuoteService
        Retrieves the paged list of quotes according to the provided selection criteria.
        Specified by:
        getQuoteList in interface CommerceQuoteService
        Parameters:
        customerModel - the customer to be used for selecting the quotes
        quoteUserModel - the user asking for the list.
        store - the store to be used for selecting the quotes
        pageableData - paging information
        Returns:
        the paged search results
      • getQuoteByCodeAndCustomerAndStore

        public QuoteModel getQuoteByCodeAndCustomerAndStore​(CustomerModel customerModel,
                                                            UserModel quoteUserModel,
                                                            BaseStoreModel store,
                                                            java.lang.String quoteCode)
        Description copied from interface: CommerceQuoteService
        Finds a quote with highest version by code, customer and store.
        Specified by:
        getQuoteByCodeAndCustomerAndStore in interface CommerceQuoteService
        Parameters:
        customerModel - the customer to be used for selecting the quote
        quoteUserModel - the user asking for the list.
        store - the store to be used for selecting the quote
        quoteCode - the code of the quote
        Returns:
        the quote
      • validateListNotEmpty

        protected void validateListNotEmpty​(java.util.Collection paramToCheck,
                                            java.lang.String unknownIdException)
      • getAllowedActions

        public java.util.Set<QuoteAction> getAllowedActions​(QuoteModel quoteModel,
                                                            UserModel userModel)
        Description copied from interface: CommerceQuoteService
        Get currently allowed actions for a quote.
        Specified by:
        getAllowedActions in interface CommerceQuoteService
        Parameters:
        quoteModel - the quote to process
        userModel - the user for which the allowed actions will be determined
        Returns:
        the allowed action. Empty set will be returned if none of the actions is allowed.
      • applyQuoteDiscount

        public void applyQuoteDiscount​(AbstractOrderModel abstractOrderModel,
                                       UserModel userModel,
                                       java.lang.Double discountRate,
                                       DiscountType discountType)
        Description copied from interface: CommerceQuoteService
        Applies a quote specific discount to abstract order model given the discount rate and discount type.
        Specified by:
        applyQuoteDiscount in interface CommerceQuoteService
        Parameters:
        abstractOrderModel - the abstract order model to add a discount to. Must either be a QuoteModel or a CartModel associated with a quote.
        userModel - the user performing the operation on the quote
        discountRate - the discount rate to be applied
        discountType - the type of discount to be applied
      • validateDiscountRate

        protected void validateDiscountRate​(java.lang.Double discountRate,
                                            DiscountType discountType,
                                            AbstractOrderModel abstractOrderModel)
      • cancelQuote

        public void cancelQuote​(QuoteModel quoteModel,
                                UserModel userModel)
        Description copied from interface: CommerceQuoteService
        Cancels a quote. The version of the quote visible to the user will have the state set to canceled.
        Specified by:
        cancelQuote in interface CommerceQuoteService
        Parameters:
        quoteModel - the quote to cancel
        userModel - the user performing the operation on the quote
      • assignQuoteToUser

        public void assignQuoteToUser​(QuoteModel quote,
                                      UserModel assignee,
                                      UserModel assigner)
        Description copied from interface: CommerceQuoteService
        Assigns quote to an assignee
        Specified by:
        assignQuoteToUser in interface CommerceQuoteService
        Parameters:
        quote - the quote to be assigned
        assignee - the user to which the quote should be assigned
        assigner - the user assigning the quote to the assignee
      • shouldAutoApproveTheQuoteForSellerApproval

        public boolean shouldAutoApproveTheQuoteForSellerApproval​(QuoteModel quoteModel)
        Description copied from interface: CommerceQuoteService
        Checks whether a quote can be auto approved or requires seller approval based on the configured threshold.
        Specified by:
        shouldAutoApproveTheQuoteForSellerApproval in interface CommerceQuoteService
        Parameters:
        quoteModel - the quote to inspect for auto approval
        Returns:
        true if the quote should be auto approved, false otherwise
      • getQuotesCountForStoreAndUser

        public java.lang.Integer getQuotesCountForStoreAndUser​(CustomerModel customerModel,
                                                               UserModel quoteUserModel,
                                                               BaseStoreModel store)
        Description copied from interface: CommerceQuoteService
        Get the number of quotes for the specified user and store.
        Specified by:
        getQuotesCountForStoreAndUser in interface CommerceQuoteService
        Parameters:
        customerModel - the customer to be used for selecting the quotes
        quoteUserModel - the user asking for the number of quotes
        store - the store to be used for selecting the quotes
        Returns:
        the total number
      • isQuoteCartValidForCheckout

        public boolean isQuoteCartValidForCheckout​(CartModel cart)
        Description copied from interface: CommerceQuoteService
        Validates if the quote cart can be checked-out or not
        Specified by:
        isQuoteCartValidForCheckout in interface CommerceQuoteService
        Parameters:
        cart - the cart to validate
        Returns:
        true if quoteCart is valid for check out, false otherwise
      • updateQuoteFromCartInternal

        protected QuoteModel updateQuoteFromCartInternal​(CartModel cartModel)
      • executeQuoteAssignment

        protected void executeQuoteAssignment​(QuoteModel quote,
                                              UserModel assignee,
                                              java.lang.String errorMsg)
      • setAssigneeOnQuote

        protected void setAssigneeOnQuote​(QuoteModel quote,
                                          UserModel assignee)
      • createDiscountValue

        protected java.util.Optional<DiscountValue> createDiscountValue​(java.lang.Double discountRate,
                                                                        DiscountType discountType,
                                                                        java.lang.String currencyIsoCode)
      • isSessionQuoteSameAsRequestedQuote

        protected boolean isSessionQuoteSameAsRequestedQuote​(QuoteModel quoteModel)
      • validateQuoteCart

        protected void validateQuoteCart​(CartModel cartModel)
      • setCommerceQuoteDao

        public void setCommerceQuoteDao​(CommerceQuoteDao commerceQuoteDao)
      • getCartService

        protected CartService getCartService()
      • setCartService

        public void setCartService​(CartService cartService)
      • getModelService

        protected ModelService getModelService()
      • setModelService

        public void setModelService​(ModelService modelService)
      • setCommerceSaveCartService

        public void setCommerceSaveCartService​(CommerceSaveCartService commerceSaveCartService)
      • setSessionService

        public void setSessionService​(SessionService sessionService)
      • setCommerceCartService

        public void setCommerceCartService​(CommerceCartService commerceCartService)
      • setQuoteStateSelectionStrategy

        public void setQuoteStateSelectionStrategy​(QuoteStateSelectionStrategy quoteStateSelectionStrategy)
      • setQuoteActionValidationStrategy

        public void setQuoteActionValidationStrategy​(QuoteActionValidationStrategy quoteActionValidationStrategy)
      • setQuoteUpdateStateStrategy

        public void setQuoteUpdateStateStrategy​(QuoteUpdateStateStrategy quoteUpdateStateStrategy)
      • setCalculationService

        public void setCalculationService​(CalculationService calculationService)
      • getQuoteService

        protected QuoteService getQuoteService()
      • setQuoteService

        public void setQuoteService​(QuoteService quoteService)
      • setUpdateQuoteFromCartStrategy

        public void setUpdateQuoteFromCartStrategy​(UpdateQuoteFromCartStrategy updateQuoteFromCartStrategy)
      • getQuoteSnapshotStateTransitionMap

        protected java.util.Map<QuoteState,​QuoteState> getQuoteSnapshotStateTransitionMap()
      • setQuoteSnapshotStateTransitionMap

        public void setQuoteSnapshotStateTransitionMap​(java.util.Map<QuoteState,​QuoteState> quoteSnapshotStateTransitionMap)
      • getEventService

        protected EventService getEventService()
      • setEventService

        public void setEventService​(EventService eventService)
      • setQuoteCartValidationStrategy

        public void setQuoteCartValidationStrategy​(QuoteCartValidationStrategy quoteCartValidationStrategy)
      • getUserService

        protected UserService getUserService()
      • setUserService

        public void setUserService​(UserService userService)
      • setCommerceQuoteUtils

        public void setCommerceQuoteUtils​(CommerceQuoteUtils commerceQuoteUtils)
      • setRequoteStrategy

        public void setRequoteStrategy​(RequoteStrategy requoteStrategy)