Commit 53469421 by houweibin

moncler品牌商品使用admin api获取

parent e01dbf27
......@@ -365,6 +365,10 @@ static NSString *idStr = @"KWMBrandCaramelCell";
if([self isUseCacheProduct:parameters page:tagetPage]){
return;
};
if([collectionId.stringValue isEqualToString:@"171614726"]){
[self getAdminProducts:parameters];
return;
}
[self.client getProductsPage:tagetPage inCollection:collectionId withTags:tags sortOrder:collectionSort completion:^(NSArray *products,NSUInteger page, BOOL reachedEnd, NSError *error){
if (!error){
[KWMPPCacheUtil saveDataToCache:parameters urlKey:CACHE_KEY_SDK_getProductsPage products:products];
......@@ -394,6 +398,53 @@ static NSString *idStr = @"KWMBrandCaramelCell";
}];
}
-(void)getAdminProducts:(NSDictionary *)parameters{
__weak KWMBrandCaramelVC *weakSelf = self;
NSInteger tagetPage = self.currentPage.integerValue + 1;
//初始化排序及筛选tag
NSString *apiPath = [[NSString alloc] initWithFormat:@"https://%@/admin/product_listings.json",Shopify_SHOP_DOMAIN];
AFHTTPSessionManager *sessionManager = [AFHTTPSessionManager manager];
[sessionManager.requestSerializer setValue:@"Basic YWRlMDgzZGU2YWJjYjljYjk0ODY5NDg1ZWUwZGQyNmE6MWYyYzVlM2I4N2YyZGJlMTkwZGEzMzU4NmMyMmY3YzQ=" forHTTPHeaderField:@"Authorization"];
[sessionManager GET:apiPath parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSArray *result = nil;
[weakSelf hideLoading];
if(responseObject){
id jsonDictionary = responseObject[@"product_listings"];
if(jsonDictionary){
@try{
NSArray *array = (NSArray *)jsonDictionary;
if(array){
BUYModelManager *modelManager = [[BUYModelManager alloc]init];
result = [modelManager buy_objectsWithEntityName:[BUYProduct entityName] JSONArray:array];
}
}
@catch (NSException *exception){
NSLog( @"exception Name: %@", exception.name);
NSLog( @"exception Reason: %@", exception.reason );
}
[KWMPPCacheUtil saveDataToCache:parameters urlKey:CACHE_KEY_SDK_getProductsPage products:result];
if(!result || result.count == 0){
weakSelf.vNoneGoods.hidden = NO;
[weakSelf.dataList removeAllObjects];
[self.tbvBrandCaramel reloadData];
weakSelf.hasNextPage = NO;
}else{
if(tagetPage == 1){
[weakSelf.dataList removeAllObjects];
}
weakSelf.hasNextPage = YES;
[weakSelf appendDataList:result setPage:tagetPage];
weakSelf.vNoneGoods.hidden = YES;
[self.tbvBrandCaramel reloadData];
}
}
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[weakSelf hideLoading];
[weakSelf showError:error];
}];
}
#pragma mark -cache
//缓存规则:第一页数据默认先从缓存拿,然后再更新,后面的根据网络判断从缓存拿数据还是从api拿数据
- (BOOL)isUseCacheProduct:(NSDictionary *)cacheKeyDictionary page:(NSUInteger)page{
......@@ -430,4 +481,5 @@ static NSString *idStr = @"KWMBrandCaramelCell";
@end
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