Posts

Showing posts from September, 2012

Creating and adding elements to a list in JSTL

There are plenty of places in WebSphere Commerce out-of-the-box code where we can see code to iterate over a list in JSTL. But I feel that code to create and add items to list in JSTL are rare and hence lot of developers (atleast beginners) do not know how to do that. I recently came across and used this code to create and add items to an arraylist in JSP using JSTL. And I thought I need to note it down somewhere so I can refer in future. Sample code below: <wcf:useBean var="sampleList" classname="java.util.ArrayList"/> ... <c:set var="sampleVar" value="val"/> <wcf:set target="${sampleList}" value="${sampleVar}"/> Once you created the list, you can iterate through and process it as required. <c:forEach items="${sampleList}" var="eachVal"> <c:out value="${eachVal}" /> </c:forEach> Hope this help someone. Feel free to share t...

Fetching PIs (Payment Instructions) for an order - IBM WebSphere Commerce

Payment instructions of an order is stored in PPCPAYINST database table. This post is about the usage of QueryPIsCmd task command which can be used to fetch all the payment instructions for an order. The default implementation of this command is QueryPIsCmdImpl. Below is a sample code snippet to fetch already added PIs for an order. QueryPIsCmd queryPICmd = (QueryPIsCmd) CommandFactory.createCommand("com.ibm.commerce.edp.commands.QueryPIsCmd", storeId); queryPICmd.setCommandContext(commandContext); queryPICmd.setOrderId(new Long(orderId)); queryPICmd.execute(); ArrayList pis = queryPICmd.getPIs(); Hope this help someone. Feel free to share this page with your friends and colleagues. Thanks..!

Applied promotions of an order - IBM WebSphere Commerce

In this post we will see how we can get the name and other details of promotions already applied to an order from a controller command. These details are stored in the PX_PROMOARG table in XML format. So for this task we need to fetch the PromotionArgument object for the order from the PX_PROMOARG table. This is achieved using PromotionArgumentSessionBeanPersistenceManager, this class provides a load() method which accepts OrderKey using which we can load the PromotionArgument for the order. From the PromotionArgument we can get the list of PromotionExecutionRecords. Below is sample code to get all the promotions applied to an order and print the name and description of the promotions. OrderKey ordKey = new OrderKey(new Long(orderId)); PromotionArgumentSessionBeanPersistenceManager promoManager = new PromotionArgumentSessionBeanPersistenceManager(); PromotionArgument promArg = promoManager.load(ordKey); Iterator prmoExeRecds = promArg.getPromotionExecutionRecords(); ...

Fetching cookie value in controller command - IBM WebSphere Commerce

As WebSphere Commerce developers we may sometimes work on scenarios where we need to read a particular cookie value in controller command. Usually lot of developers use cookies as a simple technique to store some value only for a session and when not required to be saved in the database for future use. Recently, I have came across a business requirement where I have to add a cookie from the front-end (using Javascript) and write some logic in the back-end using the cookie value. Below is the code I have used to iterate over the list of cookies and fetch the value of the required one in a controller command. String cookieName = "MyCookieName"; HttpServletRequest httpServletReq = ((HttpControllerRequestObject) (((ViewCommandContext) getCommandContext()).getRequest())) .getHttpRequest(); Cookie[] cookies = httpServletReq.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { if (cookieName.equals(cookie.ge...