Mixing REST API usage and Standard Responsive Checkout

こ雲淡風輕ζ 提交于 2019-12-11 05:07:41

问题


I want to build a native mobile app the adds products to the cart using Intershop's REST API. That part is easy. However, for the checkout I would like to use the standard responsive web application. Any suggestions how these two approaches can be mixed elegantly?


回答1:


I solved it now by writing a little pipelet, that attaches the basket created via REST API to the current session.

    public class AttachBasketToSession extends Pipelet
    {
        @Inject
        CurrentApplicationBOProvider currentApplicationBOprovider;

        @Override
        public int execute(PipelineDictionary aPipelineDictionary) throws PipeletExecutionException
        {
            String basketUUID = aPipelineDictionary.get("BasketUUID");
            String userID = aPipelineDictionary.get("UserID");
            StorefrontSession session = aPipelineDictionary.get("CurrentSession");

            ApplicationBO applicationBO = currentApplicationBOprovider.get();
            BasketBORepository basketBORepository = applicationBO.getRepository("BasketBORepository");
            UserBORepository userBORepository = applicationBO.getRepository("UserBORepository");

            BasketBO basketBO = basketBORepository.getBasketBO(basketUUID);
            UserBO userBO = userBORepository.getUserBOByID(userID);

            // Set the current user as owner of the new basket
            basketBO.setUserBO(userBO);

            // Assign the basket to the session
            Map<String, String> basketUUIDs = (Map)session.getObject("BasketUUIDs");
            for (String key : basketUUIDs.keySet())
            {
                basketUUIDs.put(key, basketBO.getID());
                break; // Assume there is only one basket attached to the session

            }
            session.putObject("BasketUUIDs", basketUUIDs);

            return PIPELET_NEXT;

        }
}


来源:https://stackoverflow.com/questions/40103287/mixing-rest-api-usage-and-standard-responsive-checkout

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!