Search code examples
sap-commerce-cloudexpress-checkout

Express Checkout Customization in Hybris


Suppose a user has 2 items in his cart. He goes to another item detail page and clicks buy now. Now, by default, all the two products also add up and go for checkout. My requirement is that when the user clicks buy now, then only that product should proceed and not merge with the other two items in the cart. If the user does not complete the order placement procedure, then it should be added to the cart with the other 2 items. But if he completes the order placement procedure, the other 2 items should stay in the cart.

This is what Flipkart does. Any suggestions in how to achieve this?


Solution

  • Usually, such tasks require a big amount of analytics to find all cases. But a simple plan is:

    1. Create a new button for "Buy now" that will call your own controller/facade/service instead of de.hybris.platform.commerceservices.order.impl.DefaultCommerceCartService#addToCart
    2. Add a new boolean property buyNow to the CartModel
    3. Your new service needs to clean the session from the previous cart. Create a new one with cart.buyNow = true
    4. redirect your customer directly to the checkout
    5. If a customer leaves the checkout or successfully places an order. Clean up all his carts with the buyNow flag. And run a cart restoration process that will return his original cart.