Search in sources :

Example 21 with BroadleafRequestContext

use of org.broadleafcommerce.common.web.BroadleafRequestContext in project BroadleafCommerce by BroadleafCommerce.

the class MultiTenantCopyContext method setupContext.

protected BroadleafRequestContext setupContext() {
    BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
    context.setCurrentCatalog(getToCatalog());
    context.setCurrentProfile(getToSite());
    context.setSite(getToSite());
    return context;
}
Also used : BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext)

Example 22 with BroadleafRequestContext

use of org.broadleafcommerce.common.web.BroadleafRequestContext in project BroadleafCommerce by BroadleafCommerce.

the class TranslatableException method getLocalizedMessage.

/**
 * <p>Return the message to show to the user. The framework will first look in the localized property bundles
 * for any messages that match the supplied error code and exception type. If not found, the regular message
 * submitted to the constructor will be returned.</p>
 *
 * <p>Message bundle properties have the following format:</p>
 *
 * <p>
 * [simple class name of exception]_[integer error code]=[localized message for this exception and code]
 * </p>
 *
 * @return The error message to display to the user
 */
@Override
public String getLocalizedMessage() {
    String response = getMessage();
    try {
        String exCode = getMessageKey();
        BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
        if (context != null && context.getMessageSource() != null) {
            response = context.getMessageSource().getMessage(exCode, this.messageParams, getMessage(), context.getJavaLocale());
            if (response.equals(exCode)) {
                response = getMessage();
            }
        }
    } catch (NoSuchMessageException e) {
        response = getMessage();
    }
    return response;
}
Also used : NoSuchMessageException(org.springframework.context.NoSuchMessageException) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext)

Example 23 with BroadleafRequestContext

use of org.broadleafcommerce.common.web.BroadleafRequestContext in project BroadleafCommerce by BroadleafCommerce.

the class MvelHelper method buildMvelParameters.

/**
 * Builds parameters using time, request, customer, and cart.
 *
 * Should be called from within a valid web request.
 *
 * @param request
 * @return
 */
public static Map<String, Object> buildMvelParameters() {
    Map<String, Object> mvelParameters = new HashMap<String, Object>();
    BroadleafRequestContext brc = BroadleafRequestContext.getBroadleafRequestContext();
    if (brc != null && brc.getRequest() != null) {
        TimeDTO timeDto = new TimeDTO(SystemTime.asCalendar());
        HttpServletRequest request = brc.getRequest();
        RequestDTO requestDto = brc.getRequestDTO();
        mvelParameters.put("time", timeDto);
        mvelParameters.put("request", requestDto);
        Map<String, Object> blcRuleMap = (Map<String, Object>) request.getAttribute(BLC_RULE_MAP_PARAM);
        if (blcRuleMap != null) {
            for (String mapKey : blcRuleMap.keySet()) {
                mvelParameters.put(mapKey, blcRuleMap.get(mapKey));
            }
        }
    }
    return mvelParameters;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HashMap(java.util.HashMap) TimeDTO(org.broadleafcommerce.common.TimeDTO) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) RequestDTO(org.broadleafcommerce.common.RequestDTO) HashMap(java.util.HashMap) EfficientLRUMap(org.broadleafcommerce.common.util.EfficientLRUMap) Map(java.util.Map)

Example 24 with BroadleafRequestContext

use of org.broadleafcommerce.common.web.BroadleafRequestContext in project BroadleafCommerce by BroadleafCommerce.

the class OnePageCheckoutProcessor method populateSectionViewStates.

/**
 * This method is responsible of populating the variables necessary to draw the checkout page.
 * This logic is highly dependent on your layout. If your layout does not follow the same flow
 * as the HeatClinic demo, you will need to override with your own custom layout implementation
 *
 * @param localVars
 */
protected void populateSectionViewStates(Map<String, Object> localVars) {
    boolean orderInfoPopulated = hasPopulatedOrderInfo(CartState.getCart());
    boolean billingPopulated = hasPopulatedBillingAddress(CartState.getCart());
    boolean shippingPopulated = hasPopulatedShippingAddress(CartState.getCart());
    localVars.put("orderInfoPopulated", orderInfoPopulated);
    localVars.put("billingPopulated", billingPopulated);
    localVars.put("shippingPopulated", shippingPopulated);
    // Logic to show/hide sections based on state of the order
    // show all sections including header unless specifically hidden
    // (e.g. hide shipping if no shippable items in order or hide billing section if the order payment doesn't need
    // an address i.e. PayPal Express)
    boolean showBillingInfoSection = true;
    boolean showShippingInfoSection = true;
    boolean showAllPaymentMethods = true;
    boolean showPaymentMethodSection = true;
    int numShippableFulfillmentGroups = calculateNumShippableFulfillmentGroups();
    if (numShippableFulfillmentGroups == 0) {
        showShippingInfoSection = false;
    }
    boolean orderContainsThirdPartyPayment = false;
    boolean orderContainsUnconfirmedCreditCard = false;
    OrderPayment unconfirmedCC = null;
    if (CartState.getCart().getPayments() != null) {
        for (OrderPayment payment : CartState.getCart().getPayments()) {
            if (payment.isActive() && PaymentType.THIRD_PARTY_ACCOUNT.equals(payment.getType())) {
                orderContainsThirdPartyPayment = true;
            }
            if (payment.isActive() && (PaymentType.CREDIT_CARD.equals(payment.getType()) && !PaymentGatewayType.TEMPORARY.equals(payment.getGatewayType()))) {
                orderContainsUnconfirmedCreditCard = true;
                unconfirmedCC = payment;
            }
        }
    }
    // Toggle the Payment Info Section based on what payments were applied to the order
    // (e.g. Third Party Account (i.e. PayPal Express) or Gift Cards/Customer Credit)
    Money orderTotalAfterAppliedPayments = CartState.getCart().getTotalAfterAppliedPayments();
    if (orderContainsThirdPartyPayment || orderContainsUnconfirmedCreditCard) {
        showBillingInfoSection = false;
        showAllPaymentMethods = false;
    } else if (orderTotalAfterAppliedPayments != null && orderTotalAfterAppliedPayments.isZero()) {
        // If all the applied payments (e.g. gift cards) cover the entire amount
        // we don't need to show all payment method options.
        showAllPaymentMethods = false;
    }
    localVars.put("showBillingInfoSection", showBillingInfoSection);
    localVars.put("showAllPaymentMethods", showAllPaymentMethods);
    localVars.put("showPaymentMethodSection", showPaymentMethodSection);
    localVars.put("orderContainsThirdPartyPayment", orderContainsThirdPartyPayment);
    localVars.put("orderContainsUnconfirmedCreditCard", orderContainsUnconfirmedCreditCard);
    localVars.put("unconfirmedCC", unconfirmedCC);
    // The Sections are all initialized to INACTIVE view
    List<CheckoutSectionDTO> drawnSections = new LinkedList<>();
    CheckoutSectionDTO orderInfoSection = new CheckoutSectionDTO(CheckoutSectionViewType.ORDER_INFO, orderInfoPopulated);
    CheckoutSectionDTO billingInfoSection = new CheckoutSectionDTO(CheckoutSectionViewType.BILLING_INFO, billingPopulated);
    CheckoutSectionDTO shippingInfoSection = new CheckoutSectionDTO(CheckoutSectionViewType.SHIPPING_INFO, shippingPopulated);
    CheckoutSectionDTO paymentInfoSection = new CheckoutSectionDTO(CheckoutSectionViewType.PAYMENT_INFO, false);
    String orderInfoHelpMessage = (String) localVars.get("orderInfoHelpMessage");
    String billingInfoHelpMessage = (String) localVars.get("billingInfoHelpMessage");
    String shippingInfoHelpMessage = (String) localVars.get("shippingInfoHelpMessage");
    // Add the Order Info Section
    drawnSections.add(orderInfoSection);
    // Add the Billing Section
    if (showBillingInfoSection) {
        billingInfoSection.setHelpMessage(orderInfoHelpMessage);
        drawnSections.add(billingInfoSection);
    }
    // Add the Shipping Section
    if (showShippingInfoSection) {
        if (showBillingInfoSection) {
            shippingInfoSection.setHelpMessage(billingInfoHelpMessage);
        } else {
            shippingInfoSection.setHelpMessage(orderInfoHelpMessage);
        }
        drawnSections.add(shippingInfoSection);
    }
    // Add the Payment Section
    if (showShippingInfoSection) {
        paymentInfoSection.setHelpMessage(shippingInfoHelpMessage);
    } else if (showBillingInfoSection) {
        paymentInfoSection.setHelpMessage(billingInfoHelpMessage);
    } else {
        paymentInfoSection.setHelpMessage(orderInfoHelpMessage);
    }
    drawnSections.add(paymentInfoSection);
    // Logic to toggle state between form view, saved view, and inactive view
    // This is dependent on the layout of your checkout form. Override this if layout is different.
    // initialize first view to always be a FORM view
    CheckoutSectionDTO firstSection = drawnSections.get(0);
    firstSection.setState(CheckoutSectionStateType.FORM);
    for (ListIterator<CheckoutSectionDTO> itr = drawnSections.listIterator(); itr.hasNext(); ) {
        CheckoutSectionDTO previousSection = null;
        if (itr.hasPrevious()) {
            previousSection = drawnSections.get(itr.previousIndex());
        }
        CheckoutSectionDTO section = itr.next();
        // if the previous section is populated, set this section to a Form View
        if (previousSection != null && previousSection.isPopulated()) {
            section.setState(CheckoutSectionStateType.FORM);
        }
        // If this sections is populated then set this section to the Saved View
        if (section.isPopulated()) {
            section.setState(CheckoutSectionStateType.SAVED);
        }
        // {@see DefaultPaymentGatewayCheckoutService where payments are invalidated on an unsuccessful transaction}
        if (CheckoutSectionViewType.PAYMENT_INFO.equals(section.getView())) {
            if (showBillingInfoSection && !billingPopulated) {
                section.setState(CheckoutSectionStateType.INACTIVE);
                section.setHelpMessage(billingInfoHelpMessage);
            }
        }
        // Finally, if the edit button is explicitly clicked, set the section to Form View
        BroadleafRequestContext blcContext = BroadleafRequestContext.getBroadleafRequestContext();
        HttpServletRequest request = blcContext.getRequest();
        boolean editOrderInfo = BooleanUtils.toBoolean(request.getParameter("edit-order-info"));
        boolean editBillingInfo = BooleanUtils.toBoolean(request.getParameter("edit-billing"));
        boolean editShippingInfo = BooleanUtils.toBoolean(request.getParameter("edit-shipping"));
        if (CheckoutSectionViewType.ORDER_INFO.equals(section.getView()) && editOrderInfo) {
            section.setState(CheckoutSectionStateType.FORM);
        } else if (CheckoutSectionViewType.BILLING_INFO.equals(section.getView()) && editBillingInfo) {
            section.setState(CheckoutSectionStateType.FORM);
        } else if (CheckoutSectionViewType.SHIPPING_INFO.equals(section.getView()) && editShippingInfo) {
            section.setState(CheckoutSectionStateType.FORM);
        }
    }
    localVars.put("checkoutSectionDTOs", drawnSections);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Money(org.broadleafcommerce.common.money.Money) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) OrderPayment(org.broadleafcommerce.core.payment.domain.OrderPayment) CheckoutSectionDTO(org.broadleafcommerce.core.web.checkout.section.CheckoutSectionDTO) LinkedList(java.util.LinkedList)

Example 25 with BroadleafRequestContext

use of org.broadleafcommerce.common.web.BroadleafRequestContext in project BroadleafCommerce by BroadleafCommerce.

the class PaginationPageLinkProcessor method getModifiedAttributes.

@Override
public BroadleafAttributeModifier getModifiedAttributes(String tagName, Map<String, String> tagAttributes, String attributeName, String attributeValue, BroadleafTemplateContext context) {
    BroadleafRequestContext blcContext = BroadleafRequestContext.getBroadleafRequestContext();
    HttpServletRequest request = blcContext.getRequest();
    String baseUrl = request.getRequestURL().toString();
    Map<String, String[]> params = new HashMap<>(request.getParameterMap());
    Integer page = (Integer) context.parseExpression(attributeValue);
    if (page != null && page > 1) {
        params.put(SearchCriteria.PAGE_NUMBER, new String[] { page.toString() });
    } else {
        params.remove(SearchCriteria.PAGE_NUMBER);
    }
    String url = ProcessorUtils.getUrl(baseUrl, params);
    Map<String, String> newAttributes = new HashMap<>();
    newAttributes.put("href", url);
    return new BroadleafAttributeModifier(newAttributes);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HashMap(java.util.HashMap) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) BroadleafAttributeModifier(org.broadleafcommerce.presentation.model.BroadleafAttributeModifier)

Aggregations

BroadleafRequestContext (org.broadleafcommerce.common.web.BroadleafRequestContext)78 Site (org.broadleafcommerce.common.site.domain.Site)16 HashMap (java.util.HashMap)12 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 ArrayList (java.util.ArrayList)9 Map (java.util.Map)9 Locale (org.broadleafcommerce.common.locale.domain.Locale)8 SandBox (org.broadleafcommerce.common.sandbox.domain.SandBox)5 StructuredContentDTO (org.broadleafcommerce.common.structure.dto.StructuredContentDTO)5 MessageSource (org.springframework.context.MessageSource)5 List (java.util.List)4 StructuredContent (org.broadleafcommerce.cms.structure.domain.StructuredContent)4 Field (java.lang.reflect.Field)3 HashSet (java.util.HashSet)3 Locale (java.util.Locale)3 Catalog (org.broadleafcommerce.common.site.domain.Catalog)3 BroadleafAttributeModifier (org.broadleafcommerce.presentation.model.BroadleafAttributeModifier)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 File (java.io.File)2 PrintWriter (java.io.PrintWriter)2