CreateOrderFromCartStrategy

This strategy is responsible for taking a cart and making a real order from it.

public interface CreateOrderFromCartStrategy
{
/**
 * Validates the cart using {@link CartValidator} and performs cart to order cloning.
 *
 * @param cart
 *           - the target {@link CartModel}
 * @throws InvalidCartException
 *            according to {@link CartValidator} implementation.
 * @return an unsaved and not calculated {@link OrderModel} instance.
 */
OrderModel createOrderFromCart(CartModel cart) throws InvalidCartException;
}

This process usually differs in every project. It means that you can define your own logic. The default implementation additionally validates the cart by using injected CartValidator. One can define his or her own validator in order to prevent from creating orders from carts not fulfilling your business requirements.

Here is the spring configuration of the default strategy:

<alias alias="createOrderFromCartStrategy" name="defaultCreateOrderFromCartStrategy"/>
<bean id="defaultCreateOrderFromCartStrategy" 
			class="de.hybris.platform.order.strategies.impl.DefaultCreateOrderFromCartStrategy" 
			>
	<property name="cartValidator" ref="cartValidator"/>
	<property name="cloneAbstractOrderStrategy" ref ="cloneAbstractOrderStrategy"/>
</bean>

As you can see, it uses the validator mentioned earlier and the cloning strategy to clone the cart into a new order.

If you wish to exchange the order placement strategy in the framework with your own implementation (or extension of DefaultCreateOrderFromCartStrategy), you can provide an implementation of the de.hybris.platform.order.strategies.CreateOrderFromCartStrategy and configure it in your spring configuration. The following example presents the case where a customized strategy extends the default one.

public class MyPlaceOrderStrategy extends DefaultCreateOrderFromCartStrategy implements CreateOrderFromCartStrategy
{
   ...
}
<alias alias="createOrderFromCartStrategy" name="myCreateOrderFromCartStrategy"/>
<bean id="myCreateOrderFromCartStrategy" class="de.hybris.platform.order.strategies.impl.MyPlaceOrderStrategy"
                   parent="defaultCreateOrderFromCartStrategy">
          <!-- inject whatever you need to use in your implementation -->
</bean>