Commit 5d254302 by houweibin

1,购物车商品图片显示

parent ada3f1c7
......@@ -44,7 +44,7 @@
shopCartModel.product_id = item[@"product_id"];
shopCartModel.quantity = [item[@"quantity"] integerValue];
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;
[datas addObject:shopCartModel];
}
......
......@@ -51,7 +51,10 @@
+ (NSString *)getProductImageUrl:(id)product ImageSize:(NSInteger)ImageSize;
//获取商品第(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 @@
imageArray = [self getOriginalImages2:product];
}
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){
for(NSString *imageUrl in imageArray){
NSRange startRange = [imageUrl rangeOfString:@"?"];
if (startRange.location != NSNotFound) {
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];
}
NSString *newImageUrl = [self getProductImageUrlByOriginalUrl:imageUrl ImageSize:ImageSize];
[newImageArray addObject:newImageUrl];
}
}
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{
if(ImageSize == BigImage){
return @[@"1000", @"1000"];
......@@ -239,13 +248,10 @@
imageUrl = imageArray.firstObject;
}
}
if([product isKindOfClass:[BUYProduct class]]){
BUYProduct *aaa = (BUYProduct *)product;
}
return imageUrl;
}
+ (NSString *)getProductImageUrlByPosition:(id)product ImageSize:(NSInteger)ImageSize Position:(NSInteger)Position{
NSString *imageUrl = @"";
if(product){
......
......@@ -32,7 +32,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>2017042409</string>
<string>2017053117</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<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