WCS学习笔记(第十一天) - 创建MyOrderItemAddCmdImpl实现重写加入购物车逻辑
2013-10-15 11:21
344 查看
1. 创建MyOrderItemAddCmdImpl:
a. 右键
WebSphereCommerceServerExtensionsLogic >Java Resources >src
, 选择New >Package
b. 在 File name 项中输入com.ibm.commerce.sample.commands
, 点击
Finish
c. 右键
com.ibm.commerce.sample.commands
, 选择 New >Class
d. 在 File name 项中输入 MyOrderItemAddCmdImpl , 点击Browse 输入 OrderItemAddCmdImpl
,点击 Ok , 点击 Add
输入 OrderItemAddCmd 点击 OK , 点击
Finish , 代码如下:
参考: http://pic.dhe.ibm.com/infocenter/wchelp/v7r0m0/topic/com.ibm.commerce.developer.tutorial.doc/tutorial/ttd22.htm
a. 右键
WebSphereCommerceServerExtensionsLogic >Java Resources >src
, 选择New >Package
b. 在 File name 项中输入com.ibm.commerce.sample.commands
, 点击
Finish
c. 右键
com.ibm.commerce.sample.commands
, 选择 New >Class
d. 在 File name 项中输入 MyOrderItemAddCmdImpl , 点击Browse 输入 OrderItemAddCmdImpl
,点击 Ok , 点击 Add
输入 OrderItemAddCmd 点击 OK , 点击
Finish , 代码如下:
package com.ibm.commerce.sample.commands; import com.ibm.commerce.exception.ECApplicationException; import com.ibm.commerce.exception.ECException; import com.ibm.commerce.exception.ECSystemException; import com.ibm.commerce.order.objects.OrderAccessBean; import com.ibm.commerce.orderitems.commands.OrderItemAddCmd; import com.ibm.commerce.orderitems.commands.OrderItemAddCmdImpl; import com.ibm.commerce.ras.ECMessage; import com.ibm.commerce.sample.messages.MyNewMessages; public class MyOrderItemAddCmdImpl extends OrderItemAddCmdImpl implements OrderItemAddCmd { public void performExecute() throws ECException { // Get a list of order ids String[] orderIds = getOrderId(); // Check to make sure that an id exists at all // if order ID exists then get number of items in the order // else if no order ID exists then execute normal code if (orderIds != null && orderIds.length > 0) { // An exception should be thrown when trying to add a sixth item // to the shopping cart. This code runs before an item is added and // throws an exception if there are 5 or more items in the cart. if (itemsInOrder(orderIds[0]) >= 5) { throw new ECApplicationException( MyNewMessages._ERR_TOO_MANY_ITEMS, this.getClass().getName(), "performExecute"); } //else perform normal flow } super.performExecute(); } //get number of items in the order protected int itemsInOrder(String orderId) throws ECException { try { OrderAccessBean order = new OrderAccessBean(); order.setInitKey_orderId(orderId); order.refreshCopyHelper(); return order.getOrderItems().length; } catch (javax.ejb.FinderException e) { throw new ECSystemException( ECMessage._ERR_FINDER_EXCEPTION, this.getClass().getName(), "itemsInOrder"); } catch (javax.naming.NamingException e) { throw new ECSystemException( ECMessage._ERR_NAMING_EXCEPTION, this.getClass().getName(), "itemsInOrder"); } catch (java.rmi.RemoteException e) { throw new ECSystemException( ECMessage._ERR_REMOTE_EXCEPTION, this.getClass().getName(), "itemsInOrder"); } catch (javax.ejb.CreateException e) { throw new ECSystemException( ECMessage._ERR_CREATE_EXCEPTION, this.getClass().getName(), "itemsInOrder"); } } }
参考: http://pic.dhe.ibm.com/infocenter/wchelp/v7r0m0/topic/com.ibm.commerce.developer.tutorial.doc/tutorial/ttd22.htm
相关文章推荐
- WCS学习笔记(第十二天) - 修改注册表命令关联MyOrderItemAddCmdImpl
- 使用DataList实现 加入购物车,编辑,删除,更新,取消功能。要求连一个产品表。
- 创建一个CPoint类,代表平面直角坐标系中的点,创建构造函数和运算符重载函数, 运算符重载为类重载(非友元重载),可以实现计算两个点之间的距离。可以根据需要 加入自己的成员变量或成员函数
- WCS学习笔记(第四天) - 使用data bean从MyNewControllerCmd 向 MyNewView传递信息
- 原创:实现ehcache动态创建cache,以及超期判断的具体逻辑
- Unity3D利用Photon实现实时联网对战(三)创建和加入房间
- Effective C# Item20:明辨接口实现和虚方法重写
- 购物车实现逻辑【详解】
- android 往dialog中加入listview,并实现listview中item的点击事件
- php 实现简单加入购物车
- 使用DataList实现 加入购物车,编辑,删除,更新,取消功能
- 重写console.log 实现自己的逻辑
- Android 购物车页面和逻辑实现
- Android 双RecyclerView嵌套实现购物车逻辑
- js实现商品抛物线加入购物车特效
- js实现商品抛物线加入购物车特效
- 自定义TabBar条,实现重写TabBar的TabBarItem,然后在中间额外加一个按钮
- jQuery仿天猫实现超炫的加入购物车
- 购物车实现逻辑【详解】
- php 实现简单加入购物车(1)