混合使用REST API和标准响应结账

时间:2016-10-18 08:31:00

标签: intershop

我想构建一个原生移动应用程序,使用Intershop的REST API将产品添加到购物车。那部分很容易。但是,对于结帐,我想使用标准的响应式Web应用程序。有关这两种方法如何优雅地混合的任何建议吗?

1 个答案:

答案 0 :(得分:3)

我现在通过编写一个小插件来解决它,它将通过REST API创建的篮子附加到当前会话。

    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;

        }
}