问题
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