Commit d9abf67a by houweibin
parents 76309da3 c8043a7c
......@@ -72,7 +72,7 @@
- (void) loginWebSuccess:(void(^)()) success failure:(void(^)(NSError *error)) failure;
/**
* 添加商品到购物车
* 立即购买使用
*
* @param variantId <#variantId description#>
* @param quantity <#quantity description#>
......@@ -81,10 +81,9 @@
*
* @return <#return value description#>
*/
- (NSURLSessionDataTask *) addProductWithVariantId:(NSNumber *) variantId quantity:(NSInteger) quantity success:(void(^)(NSURLSessionDataTask *task,KWMRequestResult *result)) success failure:(void(^)(NSURLSessionDataTask *task,NSError *error)) failure;
- (NSURLSessionDataTask *) tmpCartWithVariantId:(NSNumber *) variantId quantity:(NSInteger) quantity success:(void(^)(NSURLSessionDataTask *task,NSString *cartCookie)) success failure:(void(^)(NSURLSessionDataTask *task,NSError *error)) failure;
/**
* 立即购买使用
* 添加商品到购物车
*
* @param variantId <#variantId description#>
* @param quantity <#quantity description#>
......@@ -93,7 +92,7 @@
*
* @return <#return value description#>
*/
- (NSURLSessionDataTask *) tmpCartWithVariantId:(NSNumber *) variantId quantity:(NSInteger) quantity success:(void(^)(NSURLSessionDataTask *task,NSString *cartCookie)) success failure:(void(^)(NSURLSessionDataTask *task,NSError *error)) failure;
- (NSURLSessionDataTask *) addProductWithVariantId:(NSNumber *) variantId quantity:(NSInteger) quantity success:(void(^)(NSURLSessionDataTask *task,KWMRequestResult *result)) success failure:(void(^)(NSURLSessionDataTask *task,NSError *error)) failure;
/**
*
*
......
......@@ -13,6 +13,7 @@
@interface KWMShoppingCart ()
@property (nonatomic, strong) KWMCartResult *result;
@property (nonatomic, assign) CGFloat version;
@end
......@@ -54,19 +55,29 @@
}
- (void)allItemsWithCallback:(ShoppingCartCallBack)callback {
CGFloat version = [[NSDate date] timeIntervalSince1970];
_version = version;
__weak typeof(self) this = self;
[[KWMAPIManager sharedManager] getCartSuccess:^(NSURLSessionDataTask *task, KWMCartResult *result) {
[[KWMShoppingCart sharedInstance] setResult:result];
callback(nil,result);
if (version == this.version) {
[[KWMShoppingCart sharedInstance] setResult:result];
callback(nil,result);
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
callback(error,nil);
}];
}
- (void)increaseProductWithVariantId:(NSNumber *)variantId quantity:(NSInteger)quantity callback:(ShoppingCartCallBack)callback {
CGFloat version = [[NSDate date] timeIntervalSince1970];
_version = version;
__weak typeof(self) this = self;
[[KWMAPIManager sharedManager] addProductWithVariantId:variantId quantity:quantity success:^(NSURLSessionDataTask *task, KWMRequestResult *result) {
[[KWMShoppingCart sharedInstance] allItemsWithCallback:^(NSError *error, KWMCartResult *cart) {
// callback(error,cart);
}];
if (version == this.version) {
[[KWMShoppingCart sharedInstance] allItemsWithCallback:^(NSError *error, KWMCartResult *cart) {
// callback(error,cart);
}];
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
// callback(error,nil);
}];
......@@ -74,9 +85,14 @@
}
- (void)changeProductWithVariantId:(NSNumber *)variantId quantity:(NSInteger)quantity callback:(ShoppingCartCallBack)callback {
CGFloat version = [[NSDate date] timeIntervalSince1970];
_version = version;
__weak typeof(self) this = self;
[[KWMAPIManager sharedManager] changeProductWithVariantId:variantId quantity:quantity success:^(NSURLSessionDataTask *task, KWMCartResult *result) {
[[KWMShoppingCart sharedInstance] setResult:result];
if (version == this.version) {
[[KWMShoppingCart sharedInstance] setResult:result];
// callback(nil,result);
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
// callback(error,nil);
}];
......@@ -84,9 +100,14 @@
}
-(void)updateProductWithVariantIds:(NSArray<NSNumber *> *)variantIds quantitties:(NSArray<NSNumber *> *)quantites callback:(ShoppingCartCallBack)callback {
CGFloat version = [[NSDate date] timeIntervalSince1970];
_version = version;
__weak typeof(self) this = self;
[[KWMAPIManager sharedManager] updateProductWithVariantIds:variantIds quantities:quantites success:^(NSURLSessionDataTask *task, KWMCartResult *result) {
[[KWMShoppingCart sharedInstance] setResult:result];
if (version == this.version) {
[[KWMShoppingCart sharedInstance] setResult:result];
// callback(nil,result);
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
// callback(error,nil);
}];
......
......@@ -53,6 +53,7 @@
[[KWMShoppingCart sharedInstance] allItemsWithCallback:^(NSError *error, KWMCartResult *cart) {
[this refresh];
}];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment