Commit 5d254302 by houweibin

1,购物车商品图片显示

parent ada3f1c7
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
shopCartModel.product_id = item[@"product_id"]; shopCartModel.product_id = item[@"product_id"];
shopCartModel.quantity = [item[@"quantity"] integerValue]; shopCartModel.quantity = [item[@"quantity"] integerValue];
shopCartModel.price = [item[@"discounted_price"] floatValue] / 100; shopCartModel.price = [item[@"discounted_price"] floatValue] / 100;
shopCartModel.imageStr = [KWMImageUtil getProductImageUrl:item[@"product_id"] ImageSize:NormalImage]; shopCartModel.imageStr = [KWMImageUtil getProductImageUrlByOriginalUrl:item[@"image"] ImageSize:NormalImage];
shopCartModel.shopCartDict = item; shopCartModel.shopCartDict = item;
[datas addObject:shopCartModel]; [datas addObject:shopCartModel];
} }
......
...@@ -51,7 +51,10 @@ ...@@ -51,7 +51,10 @@
+ (NSString *)getProductImageUrl:(id)product ImageSize:(NSInteger)ImageSize; + (NSString *)getProductImageUrl:(id)product ImageSize:(NSInteger)ImageSize;
//获取商品第(position+1)张图片 //获取商品第(position+1)张图片
+ (NSString *)getProductImageUrlByPosition:(NSNumber *)productId ImageSize:(NSInteger)ImageSize Position:(NSInteger)Position; + (NSString *)getProductImageUrlByPosition:(id)product ImageSize:(NSInteger)ImageSize Position:(NSInteger)Position;
//通过商品OriginalUrl(原图片url)获取新图片url
+ (NSString *)getProductImageUrlByOriginalUrl:(NSString *)originalImgUrl ImageSize:(NSInteger)ImageSize;
......
...@@ -194,23 +194,32 @@ ...@@ -194,23 +194,32 @@
imageArray = [self getOriginalImages2:product]; imageArray = [self getOriginalImages2:product];
} }
NSMutableArray *newImageArray = [[NSMutableArray alloc]init]; NSMutableArray *newImageArray = [[NSMutableArray alloc]init];
//https://cdn.shopify.com/s/files/1/1089/5284/products/5413_1.jpg?v==1459708223 转换为
//https://o42yton8r.qnssl.com/s/files/1/1089/5284/products/5413_1.jpg?imageView2/1/w/300/h/300/v==1459708223
if(imageArray && imageArray.count>0){ if(imageArray && imageArray.count>0){
for(NSString *imageUrl in imageArray){ for(NSString *imageUrl in imageArray){
NSRange startRange = [imageUrl rangeOfString:@"?"]; NSString *newImageUrl = [self getProductImageUrlByOriginalUrl:imageUrl ImageSize:ImageSize];
if (startRange.location != NSNotFound) { [newImageArray addObject:newImageUrl];
NSMutableString* newImageUrl=[[NSMutableString alloc]initWithString:imageUrl];
NSArray<NSString *> *imageWH = [self getImageWH:ImageSize];
NSString *size = [NSString stringWithFormat:@"imageView2/1/w/%@/h/%@/",imageWH[0],imageWH[1]];
[newImageUrl insertString:size atIndex:startRange.location+1];
[newImageArray addObject:newImageUrl];
}
} }
} }
return newImageArray; return newImageArray;
} }
+ (NSString *)getProductImageUrlByOriginalUrl:(NSString *)originalImgUrl ImageSize:(NSInteger)ImageSize{
NSMutableString *newImageUrl = [[NSMutableString alloc]initWithString:@""];;
//https://cdn.shopify.com/s/files/1/1089/5284/products/5413_1.jpg?v==1459708223 转换为
//https://o42yton8r.qnssl.com/s/files/1/1089/5284/products/5413_1.jpg?imageView2/1/w/300/h/300/v==1459708223
if(originalImgUrl){
NSRange startRange = [originalImgUrl rangeOfString:@"?"];
if (startRange.location != NSNotFound) {
newImageUrl=[[NSMutableString alloc]initWithString:originalImgUrl];
NSArray<NSString *> *imageWH = [self getImageWH:ImageSize];
NSString *size = [NSString stringWithFormat:@"imageView2/1/w/%@/h/%@/",imageWH[0],imageWH[1]];
[newImageUrl insertString:size atIndex:startRange.location+1];
}
}
return [NSString stringWithFormat:@"%@",newImageUrl];;
}
+(NSArray *)getImageWH:(NSInteger)ImageSize{ +(NSArray *)getImageWH:(NSInteger)ImageSize{
if(ImageSize == BigImage){ if(ImageSize == BigImage){
return @[@"1000", @"1000"]; return @[@"1000", @"1000"];
...@@ -239,13 +248,10 @@ ...@@ -239,13 +248,10 @@
imageUrl = imageArray.firstObject; imageUrl = imageArray.firstObject;
} }
} }
if([product isKindOfClass:[BUYProduct class]]){
BUYProduct *aaa = (BUYProduct *)product;
}
return imageUrl; return imageUrl;
} }
+ (NSString *)getProductImageUrlByPosition:(id)product ImageSize:(NSInteger)ImageSize Position:(NSInteger)Position{ + (NSString *)getProductImageUrlByPosition:(id)product ImageSize:(NSInteger)ImageSize Position:(NSInteger)Position{
NSString *imageUrl = @""; NSString *imageUrl = @"";
if(product){ if(product){
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
</dict> </dict>
</array> </array>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>2017042409</string> <string>2017053117</string>
<key>LSApplicationQueriesSchemes</key> <key>LSApplicationQueriesSchemes</key>
<array> <array>
<string>weixin</string> <string>weixin</string>
......
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