use of org.broadleafcommerce.core.order.domain.NullOrderImpl in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafCartController method addWithPriceOverride.
/**
* Takes in an item request, adds the item to the customer's current cart, and returns.
*
* Calls the addWithOverrides method on the orderService which will honor the override
* prices on the OrderItemRequestDTO request object.
*
* Implementors must secure this method to avoid accidentally exposing the ability for
* malicious clients to override prices by hacking the post parameters.
*
* @param request
* @param response
* @param model
* @param itemRequest
* @throws IOException
* @throws AddToCartException
* @throws PricingException
*/
public String addWithPriceOverride(HttpServletRequest request, HttpServletResponse response, Model model, OrderItemRequestDTO itemRequest) throws IOException, AddToCartException, PricingException {
Order cart = CartState.getCart();
// and provision a fresh cart for the current customer upon the first cart add
if (cart == null || cart instanceof NullOrderImpl) {
cart = orderService.createNewCartForCustomer(CustomerState.getCustomer(request));
}
updateCartService.validateAddToCartRequest(itemRequest, cart);
cart = orderService.addItemWithPriceOverrides(cart.getId(), itemRequest, false);
cart = orderService.save(cart, true);
return isAjaxRequest(request) ? getCartView() : getCartPageRedirect();
}
use of org.broadleafcommerce.core.order.domain.NullOrderImpl in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafCartController method add.
/**
* Takes in an item request, adds the item to the customer's current cart, and returns.
*
* If the method was invoked via an AJAX call, it will render the "ajax/cart" template.
* Otherwise, it will perform a 302 redirect to "/cart"
*
* @param request
* @param response
* @param model
* @param itemRequest
* @throws IOException
* @throws AddToCartException
* @throws PricingException
* @throws RemoveFromCartException
* @throws NumberFormatException
*/
public String add(HttpServletRequest request, HttpServletResponse response, Model model, OrderItemRequestDTO itemRequest) throws IOException, AddToCartException, PricingException, NumberFormatException, RemoveFromCartException, IllegalArgumentException {
Order cart = CartState.getCart();
// and provision a fresh cart for the current customer upon the first cart add
if (cart == null || cart instanceof NullOrderImpl) {
cart = orderService.createNewCartForCustomer(CustomerState.getCustomer(request));
}
// Validate the add to cart
updateCartService.validateAddToCartRequest(itemRequest, cart);
// if this is an update to an existing order item, remove the old before proceeding
if (isUpdateRequest(request)) {
String originalOrderItem = request.getParameter("originalOrderItem");
if (StringUtils.isNotEmpty(originalOrderItem)) {
Long originalOrderItemId = Long.parseLong(originalOrderItem);
updateAddRequestQuantities(itemRequest, originalOrderItemId);
cart = orderService.removeItem(cart.getId(), originalOrderItemId, false);
cart = orderService.save(cart, true);
}
}
cart = orderService.addItem(cart.getId(), itemRequest, false);
cart = orderService.save(cart, true);
return isAjaxRequest(request) ? getCartView() : getCartPageRedirect();
}
use of org.broadleafcommerce.core.order.domain.NullOrderImpl in project BroadleafCommerce by BroadleafCommerce.
the class NamedOrderProcessor method populateModelVariables.
@Override
public Map<String, Object> populateModelVariables(String tagName, Map<String, String> tagAttributes, BroadleafTemplateContext context) {
Customer customer = CustomerState.getCustomer();
String orderVar = tagAttributes.get("orderVar");
String orderName = tagAttributes.get("orderName");
Order order = orderService.findNamedOrderForCustomer(orderName, customer);
Map<String, Object> newModelVars = new HashMap<>();
if (order != null) {
newModelVars.put(orderVar, order);
} else {
newModelVars.put(orderVar, new NullOrderImpl());
}
return newModelVars;
}
use of org.broadleafcommerce.core.order.domain.NullOrderImpl in project BroadleafCommerce by BroadleafCommerce.
the class OnePageCheckoutProcessor method populateModelVariables.
@Override
public Map<String, Object> populateModelVariables(String tagName, Map<String, String> tagAttributes, BroadleafTemplateContext context) {
// Pre-populate the command objects
OrderInfoForm orderInfoForm = context.parseExpression(tagAttributes.get("orderInfoForm"));
ShippingInfoForm shippingInfoForm = context.parseExpression(tagAttributes.get("shippingInfoForm"));
BillingInfoForm billingInfoForm = context.parseExpression(tagAttributes.get("billingInfoForm"));
String orderInfoHelpMessage = context.parseExpression(tagAttributes.get("orderInfoHelpMessage"));
String billingInfoHelpMessage = context.parseExpression(tagAttributes.get("billingInfoHelpMessage"));
String shippingInfoHelpMessage = context.parseExpression(tagAttributes.get("shippingInfoHelpMessage"));
prepopulateCheckoutForms(CartState.getCart(), orderInfoForm, shippingInfoForm, billingInfoForm);
// Add PaymentRequestDTO to the model in the case of errors or other cases
Map<String, Object> newModelVars = new HashMap<>();
Order cart = CartState.getCart();
if (cart != null && !(cart instanceof NullOrderImpl)) {
newModelVars.put("paymentRequestDTO", orderToPaymentRequestDTOService.translateOrder(cart));
}
// Initialize Fulfillment Group Vars
int numShippableFulfillmentGroups = calculateNumShippableFulfillmentGroups();
newModelVars.put("numShippableFulfillmentGroups", numShippableFulfillmentGroups);
populateFulfillmentOptionsAndEstimationOnModel(newModelVars);
// Initialize View States
newModelVars.put("orderInfoHelpMessage", orderInfoHelpMessage);
newModelVars.put("billingInfoHelpMessage", billingInfoHelpMessage);
newModelVars.put("shippingInfoHelpMessage", shippingInfoHelpMessage);
populateSectionViewStates(newModelVars);
// Helpful lists to populate dropdowns on a checkout page
newModelVars.put("states", stateService.findStates());
newModelVars.put("countries", countryService.findCountries());
newModelVars.put("expirationMonths", populateExpirationMonths());
newModelVars.put("expirationYears", populateExpirationYears());
// Populate any Payment Processing Errors
populateProcessingError(newModelVars);
return newModelVars;
}
use of org.broadleafcommerce.core.order.domain.NullOrderImpl in project BroadleafCommerce by BroadleafCommerce.
the class CartStateRefresher method onApplicationEvent.
/**
* <p>Resets {@link CartState} with the newly persisted Order. If {@link CartState} was empty, this will only update it if
* the {@link Order} that has been persisted is the {@link OrderStatus#IN_PROCESS} {@link Order} for the active
* {@link Customer} (as determined by {@link CustomerState#getCustomer()}. If {@link CartState} was <b>not</b> empty,
* then it will be replaced only if this newly persisted {@link Order} has the same id.</p>
*
* <p>This ensures that whatever is returned from {@link CartState#getCart()} will always be the most up-to-date
* database version (meaning, safe to write to the DB).</p>
*/
@Override
public void onApplicationEvent(final OrderPersistedEvent event) {
WebRequest request = BroadleafRequestContext.getBroadleafRequestContext().getWebRequest();
if (request != null) {
Order dbOrder = event.getOrder();
// Update the cart state ONLY IF the IDs of the newly persisted order and whatever is already in CartState match
boolean emptyCartState = CartState.getCart() == null || CartState.getCart() instanceof NullOrderImpl;
if (emptyCartState) {
// If cart state is empty, set it to this newly persisted order if it's the active Customer's cart
if (CustomerState.getCustomer() != null && CustomerState.getCustomer().getId().equals(dbOrder.getCustomer().getId()) && OrderStatus.IN_PROCESS.equals(dbOrder.getStatus())) {
CartState.setCart(dbOrder);
}
} else if (CartState.getCart().getId().equals(dbOrder.getId())) {
CartState.setCart(dbOrder);
}
}
}
Aggregations