I'm working with Hybris 6.3 we generated a module for a B2B implementation and I have the requirement of splitting the cart contents into different orders depending on the products in the cart, the billing address, payment, delivery, etc must share the same parameters.
From the requirements we've gathered from our client, we concluded applying consignments strategies aren't what we requiere here, since that handles one order and splits it for shipping and delivery purposes, instead our client's needs are that the different products in the cart to be grouped by a set of shared attributes and generate an order for each group of products.
So far I have identified the class in charge of placing the order in the storefront extension, DefaultCheckoutFacade, which contains the following method:
@Override
public OrderData placeOrder() throws InvalidCartException
{
final CartModel cartModel = getCart();
if (cartModel != null)
{
if (cartModel.getUser().equals(getCurrentUserForCheckout()) || getCheckoutCustomerStrategy().isAnonymousCheckout())
{
beforePlaceOrder(cartModel);
final OrderModel orderModel = placeOrder(cartModel);
afterPlaceOrder(cartModel, orderModel);
if (orderModel != null)
{
return getOrderConverter().convert(orderModel);
}
}
}
return null;
}
From what I understand, I should override this method to generate a different CartModel accordingly to the criteria set in my requirements and place an order for each CartModel. I revised the CartModel class, and it's superclass AbstractOrderModel, I'm guessing after the getCart() call in the method above, I just need to modify the entries in the CartModel and make a call to the method placeOrder() for each order I need to place, but is it allowed to modify the CartModel object in this way?
Or if I need to split my cart into different orders, should I approach this in a different way? Is something like having multiple carts but showing them as one something that should be done? Does this kind of modification should be done on the OOTB commercefacades extension? Is there a way to extend it somewhere in our module?
EDIT
I started to read about Multiple Carts and it seems to be what I need, but I haven't found how to save entries to a saved cart. In this link I can see how to save the cart, the method saveCart returns a CommerceSaveCartResultData object, both saveCart and the method getCartForCodeAndCurrentUser receive a CommerceSaveCartParameter which must contain a CartModel, how can I generate an instance of this object to set in a CommerceSaveCartParameter?