我想构建一个本地移动应用程序,使用 Intershop 的 REST API 将产品添加到购物车。那部分很容易。但是,对于结帐,我想使用标准的响应式 Web 应用程序。有什么建议可以优雅地混合这两种方法吗?
问问题
215 次
1 回答
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;
}
}
于 2016-10-21T22:27:26.587 回答