一个逻辑清晰的购物车模型

2017-03-28 16:01:17 +08:00
 Jarvi

GitHub: https://github.com/lll1024/JVShopcart

效果图

说明

这是一个具备常规功能并方便改造的购物车模型 一共包含五个模块:

使用

首先将工程里边的 JVShopcart 文件夹拖入你的项目 然后就是开源库 Vendor 文件夹根据需求处理 Model 是一定会改的 但是购物车的 Model 大同小异 其他的改动不会太大

关于JVShopcartViewController,由于其遵循 JVShopcartFormatDelegate 协议,而协议里边的方法都是用@required修饰的,所以必须要实现它;下面依次介绍这些方法:

- (void)shopcartFormatRequestProductListDidSuccessWithArray:(NSMutableArray *)dataArray;
- (void)shopcartFormatAccountForTotalPrice:(float)totalPrice
                                totalCount:(NSInteger)totalCount
                             isAllSelected:(BOOL)isAllSelected;
- (void)shopcartFormatSettleForSelectedProducts:(NSArray *)selectedProducts;
- (void)shopcartFormatHasDeleteAllProducts;

关于JVShopcartFormat,这个类主要负责网络请求与逻辑处理以及结果的回调。下面依次介绍这些方法:

- (void)requestShopcartProductList;
- (void)selectProductAtIndexPath:(NSIndexPath *)indexPath isSelected:(BOOL)isSelected;
- (void)selectBrandAtSection:(NSInteger)section isSelected:(BOOL)isSelected;
- (void)changeCountAtIndexPath:(NSIndexPath *)indexPath count:(NSInteger)count;
- (void)deleteProductAtIndexPath:(NSIndexPath *)indexPath;
- (void)starProductAtIndexPath:(NSIndexPath *)indexPath;
- (void)selectAllProductWithStatus:(BOOL)isSelected;
- (void)settleSelectedProducts;

有几个点需要注意:

以上如有帮助欢迎 star

2421 次点击
所在节点    分享创造
3 条回复
gen900
2017-03-28 17:47:38 +08:00
这个组件好,要早几年发布我也不用这么辛苦做购物车了,确实很花功夫。
gen900
2017-03-28 17:50:20 +08:00
如果能支持 最小/最大 购买数量就更好了。或者增加个属相修改的 delegate ,(bool) qualityChanging, didQualityChanged
Jarvi
2017-03-28 18:02:03 +08:00
@gen900 最大购买量是依赖库存的( ProductModel 里边 productStock 参数) 当“+”变灰色就表示不可点状态也就无法添加了 最小购买量当然是 1 了 商品数量的改变是 JVShopcartFormat 的- (void)changeCountAtIndexPath:(NSIndexPath *)indexPath count:(NSInteger)count 负责处理 处理完之后会统一回调这个方法
- (void)shopcartFormatAccountForTotalPrice:(float)totalPrice
totalCount:(NSInteger)totalCount
isAllSelected:(BOOL)isAllSelected;

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/350939

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX