Commit 1797cd45 by lee

u 修改了货币计算

parent a0c4c6fe
......@@ -69,7 +69,10 @@
80FBF7E18C063DB9E8DC7502 /* libPods-iCemarose.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 450DA8BB947651E9A9B38BEB /* libPods-iCemarose.a */; };
9B0F56B81ECD3424009FC5FE /* UIViewController+AppearLog.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B0F56B71ECD3424009FC5FE /* UIViewController+AppearLog.m */; };
9B166F511ED6DBCF003E9F03 /* KWMHttpUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B166F501ED6DBCF003E9F03 /* KWMHttpUtil.m */; };
9B18C11F1EF1270A001DD59B /* BUYProductVariant+Currency.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B18C11E1EF1270A001DD59B /* BUYProductVariant+Currency.m */; };
9B53D5D71EE94739005BA6F7 /* KWMValidateUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B53D5D61EE94739005BA6F7 /* KWMValidateUtil.m */; };
9B8298E31EF22BE200743438 /* KWMCurrencyUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B8298E21EF22BE200743438 /* KWMCurrencyUtil.m */; };
9B8298E61EF237FC00743438 /* NSDecimalNumber+Currency.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B8298E51EF237FC00743438 /* NSDecimalNumber+Currency.m */; };
9BE61CFB1ECD56E70031D21E /* KWMDictioaryResult.m in Sources */ = {isa = PBXBuildFile; fileRef = 9BE61CFA1ECD56E70031D21E /* KWMDictioaryResult.m */; };
9BE61CFE1ECD66BC0031D21E /* KWMShoppingCart.m in Sources */ = {isa = PBXBuildFile; fileRef = 9BE61CFD1ECD66BC0031D21E /* KWMShoppingCart.m */; };
9BE61D011ECD71610031D21E /* KWMCartResult.m in Sources */ = {isa = PBXBuildFile; fileRef = 9BE61D001ECD71610031D21E /* KWMCartResult.m */; };
......@@ -401,9 +404,15 @@
9B0F56B71ECD3424009FC5FE /* UIViewController+AppearLog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+AppearLog.m"; sourceTree = "<group>"; };
9B166F4F1ED6DBCF003E9F03 /* KWMHttpUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KWMHttpUtil.h; sourceTree = "<group>"; };
9B166F501ED6DBCF003E9F03 /* KWMHttpUtil.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWMHttpUtil.m; sourceTree = "<group>"; };
9B18C11D1EF1270A001DD59B /* BUYProductVariant+Currency.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "BUYProductVariant+Currency.h"; sourceTree = "<group>"; };
9B18C11E1EF1270A001DD59B /* BUYProductVariant+Currency.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "BUYProductVariant+Currency.m"; sourceTree = "<group>"; };
9B53D5D51EE94739005BA6F7 /* KWMValidateUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KWMValidateUtil.h; sourceTree = "<group>"; };
9B53D5D61EE94739005BA6F7 /* KWMValidateUtil.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWMValidateUtil.m; sourceTree = "<group>"; };
9B58353B797587723B0E7515 /* Pods-iCemarose.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-iCemarose.debug.xcconfig"; path = "Pods/Target Support Files/Pods-iCemarose/Pods-iCemarose.debug.xcconfig"; sourceTree = "<group>"; };
9B8298E11EF22BE200743438 /* KWMCurrencyUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KWMCurrencyUtil.h; sourceTree = "<group>"; };
9B8298E21EF22BE200743438 /* KWMCurrencyUtil.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWMCurrencyUtil.m; sourceTree = "<group>"; };
9B8298E41EF237FC00743438 /* NSDecimalNumber+Currency.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDecimalNumber+Currency.h"; sourceTree = "<group>"; };
9B8298E51EF237FC00743438 /* NSDecimalNumber+Currency.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDecimalNumber+Currency.m"; sourceTree = "<group>"; };
9BE61CF91ECD56E70031D21E /* KWMDictionaryResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KWMDictionaryResult.h; sourceTree = "<group>"; };
9BE61CFA1ECD56E70031D21E /* KWMDictioaryResult.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWMDictioaryResult.m; sourceTree = "<group>"; };
9BE61CFC1ECD66BC0031D21E /* KWMShoppingCart.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KWMShoppingCart.h; sourceTree = "<group>"; };
......@@ -852,6 +861,8 @@
children = (
807806851D7566DD00FD2841 /* NSString+PinYin.h */,
807806861D7566DD00FD2841 /* NSString+PinYin.m */,
9B8298E41EF237FC00743438 /* NSDecimalNumber+Currency.h */,
9B8298E51EF237FC00743438 /* NSDecimalNumber+Currency.m */,
);
path = Classify;
sourceTree = "<group>";
......@@ -1113,6 +1124,8 @@
9BE61CFD1ECD66BC0031D21E /* KWMShoppingCart.m */,
C0CCB3BB1EEA589200BC2FB8 /* KWMFilter.h */,
C0CCB3BC1EEA589200BC2FB8 /* KWMFilter.m */,
9B18C11D1EF1270A001DD59B /* BUYProductVariant+Currency.h */,
9B18C11E1EF1270A001DD59B /* BUYProductVariant+Currency.m */,
);
path = Model;
sourceTree = "<group>";
......@@ -1160,6 +1173,8 @@
9B166F501ED6DBCF003E9F03 /* KWMHttpUtil.m */,
9B53D5D51EE94739005BA6F7 /* KWMValidateUtil.h */,
9B53D5D61EE94739005BA6F7 /* KWMValidateUtil.m */,
9B8298E11EF22BE200743438 /* KWMCurrencyUtil.h */,
9B8298E21EF22BE200743438 /* KWMCurrencyUtil.m */,
);
path = Util;
sourceTree = "<group>";
......@@ -1920,7 +1935,7 @@
TargetAttributes = {
C034E6891D6AEB12006EE129 = {
CreatedOnToolsVersion = 7.3.1;
DevelopmentTeam = 6HFG5LS2Y2;
DevelopmentTeam = 72Z44QQ9ZD;
ProvisioningStyle = Manual;
};
C034E6A21D6AEB13006EE129 = {
......@@ -2115,6 +2130,7 @@
C0F5868F1E24F821001248E2 /* SVerticalView.m in Sources */,
801F87BC1DD1A9B90038FA4C /* KWMNewProducts.m in Sources */,
C0CC14061D7823B0007B5986 /* KWMShopCarCell.m in Sources */,
9B8298E31EF22BE200743438 /* KWMCurrencyUtil.m in Sources */,
C034E6951D6AEB12006EE129 /* ViewController.m in Sources */,
C0DD53231EE55062002D1E0C /* KWMCarCountView.m in Sources */,
C03943C01DD1FCE900141475 /* KWMProductType.m in Sources */,
......@@ -2149,6 +2165,7 @@
C034E8421D6B10A0006EE129 /* NSArray+Extend.m in Sources */,
C034E85B1D6B10A0006EE129 /* LFRoundProgressView.m in Sources */,
80F82E611D704E34008B470B /* KWMBrandCell.m in Sources */,
9B8298E61EF237FC00743438 /* NSDecimalNumber+Currency.m in Sources */,
C034E6F51D6AF197006EE129 /* KWMPickView.m in Sources */,
C034E8651D6B10A0006EE129 /* PhotoImageView.m in Sources */,
C034E6C81D6AED1F006EE129 /* KWMUser.m in Sources */,
......@@ -2231,6 +2248,7 @@
C034E86A1D6B10A0006EE129 /* EGORefreshTableFooterView.m in Sources */,
C034E84B1D6B10A0006EE129 /* UIImage+Cut.m in Sources */,
C0219A951DF53EB200711099 /* KWMExchangeRateResult.m in Sources */,
9B18C11F1EF1270A001DD59B /* BUYProductVariant+Currency.m in Sources */,
C034E85A1D6B10A0006EE129 /* SVProgressHUD.m in Sources */,
807AF4A81DC984950000A326 /* KWMSearchResult.m in Sources */,
C0DD533B1EE55190002D1E0C /* KWMSuperLoadingView.m in Sources */,
......
......@@ -43,7 +43,9 @@
shopCartModel.size = item[@"variant_title"];
shopCartModel.product_id = item[@"product_id"];
shopCartModel.quantity = [item[@"quantity"] integerValue];
shopCartModel.price = [item[@"discounted_price"] floatValue] / 100;
// shopCartModel.price = [item[@"discounted_price"] floatValue] / 100;
shopCartModel.price = [[NSDecimalNumber decimalNumberWithString:[item[@"discounted_price"] stringValue]] decimalNumberByDividingBy:[NSDecimalNumber decimalNumberWithDecimal:@(100).decimalValue]];
shopCartModel.line_price = [[NSDecimalNumber decimalNumberWithString:[item[@"line_price"] stringValue]] decimalNumberByDividingBy:[NSDecimalNumber decimalNumberWithDecimal:@(100).decimalValue]];
shopCartModel.imageStr = [KWMImageUtil getProductImageUrlByOriginalUrl:item[@"image"] ImageSize:NormalImage];
shopCartModel.shopCartDict = item;
[datas addObject:shopCartModel];
......
//
// NSDecimalNumber+Currency.h
// iCemarose
//
// Created by lee on 2017/6/15.
// Copyright © 2017年 kollway. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSDecimalNumber (Currency)
- (NSString *) priceFormatted;
- (NSDecimalNumber *) priceValue;
- (NSString *) priceValueFormatted;
@end
@interface NSNumber (Currency)
- (NSString *) priceFormatted;
- (NSDecimalNumber *) priceValue;
- (NSString *) priceValueFormatted;
@end
//
// NSDecimalNumber+Currency.m
// iCemarose
//
// Created by lee on 2017/6/15.
// Copyright © 2017年 kollway. All rights reserved.
//
#import "NSDecimalNumber+Currency.h"
#import "KWMCurrencyUtil.h"
@implementation NSDecimalNumber (Currency)
- (NSString *) priceFormatted {
return [[KWMCurrencyUtil sharedInstance] priceFormatted:self];
}
- (NSDecimalNumber *)priceValue {
return [[KWMCurrencyUtil sharedInstance] calcPriceByCurrencyCode:self];
}
- (NSString *)priceValueFormatted {
return [[KWMCurrencyUtil sharedInstance] priceFormatted:[self priceValue]];
}
@end
@implementation NSNumber (Currency)
- (NSString *)priceFormatted {
return [[KWMCurrencyUtil sharedInstance] priceFormatted:[NSDecimalNumber decimalNumberWithString:self.stringValue]];
}
- (NSDecimalNumber *)priceValue {
return [[KWMCurrencyUtil sharedInstance] calcPriceByCurrencyCode:[NSDecimalNumber decimalNumberWithString:self.stringValue]];
}
- (NSString *)priceValueFormatted {
return [[KWMCurrencyUtil sharedInstance] priceFormatted:[self priceValue]];
}
@end
......@@ -25,7 +25,6 @@
if (finalValue > KWM_MAX_PRODUCT_COUNT) {
finalValue = KWM_MAX_PRODUCT_COUNT;
}
// shopCartItem.quantity = finalValue;
[self saveAll];
}
......@@ -122,6 +121,7 @@
result.size = shopCartModel.size;
result.quantity = shopCartModel.quantity;
result.price = shopCartModel.price;
result.line_price = shopCartModel.line_price;
result.product_id = shopCartModel.product_id.stringValue;
result.shopCartDict = shopCartModel.shopCartDict;
}
......@@ -139,6 +139,7 @@
result.brand = shopCartItem.brand;
result.size = shopCartItem.size;
result.quantity = shopCartItem.quantity;
result.line_price = shopCartItem.line_price;
result.shopCartDict = shopCartItem.shopCartDict;
result.product_id = @(shopCartItem.product_id.integerValue);
return result;
......
......@@ -23,8 +23,9 @@ NS_ASSUME_NONNULL_BEGIN
@property (nullable, nonatomic, copy) NSString *size;
@property (nullable, nonatomic, copy) NSString *product_id;
@property (nonatomic) NSInteger quantity;
@property (nonatomic) float price;
@property (nonatomic) NSDecimalNumber *price;
@property (nullable, nonatomic, retain) NSDictionary *shopCartDict;
@property (nullable, nonatomic) NSDecimalNumber *line_price;
@end
......
......@@ -16,6 +16,10 @@
@property (nullable, nonatomic, copy) NSString *size;
@property (nullable, nonatomic, strong) NSNumber *product_id;
@property (nonatomic) NSInteger quantity;
@property (nonatomic) float price;
@property (nullable, nonatomic, strong) NSDecimalNumber *price;
@property (nullable, nonatomic, strong) NSDecimalNumber *line_price;
@property (nullable, nonatomic, retain) NSDictionary *shopCartDict;
- (NSString *_Nullable) totalPrice;
@end
......@@ -7,7 +7,15 @@
//
#import "KWMShopCartModel.h"
#import "KWMCurrencyUtil.h"
@implementation KWMShopCartModel
- (NSString *)totalPrice {
if (self.line_price) {
return [[KWMCurrencyUtil sharedInstance] priceFormattedByCurrencyCode:self.line_price];
}
return [[KWMCurrencyUtil sharedInstance] priceFormatted:[self.price.priceValue decimalNumberByMultiplyingBy:[NSDecimalNumber decimalNumberWithString:@(self.quantity).stringValue]]];
}
@end
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="12141" systemVersion="16E195" minimumToolsVersion="Automatic" sourceLanguage="Objective-C" userDefinedModelVersionIdentifier="">
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="12141" systemVersion="16F73" minimumToolsVersion="Automatic" sourceLanguage="Objective-C" userDefinedModelVersionIdentifier="">
<entity name="KWMShopCartItem" representedClassName="KWMShopCartItem" syncable="YES">
<attribute name="brand" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="identifier" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="imageStr" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="line_price" optional="YES" attributeType="Decimal" defaultValueString="0.0" syncable="YES"/>
<attribute name="name" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="price" optional="YES" attributeType="Float" defaultValueString="0.0" usesScalarValueType="YES" syncable="YES"/>
<attribute name="price" optional="YES" attributeType="Decimal" defaultValueString="0.0" syncable="YES"/>
<attribute name="product_id" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="quantity" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES" syncable="YES"/>
<attribute name="shopCartDict" optional="YES" attributeType="Transformable" syncable="YES"/>
<attribute name="size" optional="YES" attributeType="String" syncable="YES"/>
</entity>
<elements>
<element name="KWMShopCartItem" positionX="-63" positionY="-18" width="128" height="180"/>
<element name="KWMShopCartItem" positionX="-63" positionY="-18" width="128" height="195"/>
</elements>
</model>
\ No newline at end of file
//
// BUYProductVariant+Currency.h
// iCemarose
//
// Created by lee on 2017/6/14.
// Copyright © 2017年 kollway. All rights reserved.
//
#import <Mobile-Buy-SDK/Buy/BUYProductVariant.h>
@interface BUYProductVariant (Currency)
- (NSDecimalNumber *) compareAtPriceValue;
- (NSString *) compareAtPriceFormatted;
- (NSDecimalNumber *) priceValue;
- (NSString *) priceFormatted;
@end
//
// BUYProductVariant+Currency.m
// iCemarose
//
// Created by lee on 2017/6/14.
// Copyright © 2017年 kollway. All rights reserved.
//
#import "BUYProductVariant+Currency.h"
#import "KWMUserDao.h"
#import <RegexKitLite/RegexKitLite.h>
#import "KWMCurrencyUtil.h"
@implementation BUYProductVariant (Currency)
- (NSString *)compareAtPriceFormatted {
return [[KWMCurrencyUtil sharedInstance] priceFormattedByCurrencyCode:self.compareAtPrice];
}
- (NSString *)priceFormatted {
return [[KWMCurrencyUtil sharedInstance] priceFormattedByCurrencyCode:self.price];
}
- (NSDecimalNumber *)compareAtPriceValue {
return [[KWMCurrencyUtil sharedInstance] calcPriceByCurrencyCode:self.compareAtPrice];
}
- (NSDecimalNumber *)priceValue {
return [[KWMCurrencyUtil sharedInstance] calcPriceByCurrencyCode:self.price];
}
@end
......@@ -26,7 +26,7 @@
- (void)saveUser:(KWMUser *)user;
- (void)saveExchangeRate:(NSNumber *)exchangeRate;
- (NSNumber *)exchangeRate;
- (NSDecimalNumber *)exchangeRate;
- (void (^)(NSURLSessionDataTask *, KWMRequestResult *))getLoginSuccessCallback:(void (^)(NSURLSessionDataTask *, KWMRequestResult *))callback;
......
......@@ -209,10 +209,15 @@ static NSString *kwmKeySavedAccountPassword = @"savedAccountPassword";
[defaults synchronize];
}
- (NSNumber *)exchangeRate {
- (NSDecimalNumber *)exchangeRate {
NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
NSString *exchageRateString = [defaults objectForKey:kwmKeyExchangeRate];
return [KWMStringUtil stringToNumber:exchageRateString];
// NSNumber *rate = [KWMStringUtil stringToNumber:exchageRateString];
// return rate;
if ([KWMStringUtil isEmpty:exchageRateString]) {
return [NSDecimalNumber decimalNumberWithString:ExchangeRateString];
}
return [NSDecimalNumber decimalNumberWithString:exchageRateString];
}
-(void)saveCollectionCache:(NSArray *)products collectionId:(NSNumber *)collectionId tags:(NSArray *)tags{
......
......@@ -196,7 +196,8 @@
compareAtPrice = @(0);
}
if( compareAtPrice.integerValue!=0 ){
NSString *oldString = [NSString stringWithFormat:@"¥%@",[KWMStringUtil getEUR2CNYstring:compareAtPrice]];
// NSString *oldString = [NSString stringWithFormat:@"¥%@",[KWMStringUtil getEUR2CNYstring:compareAtPrice]];
NSString *oldString = compareAtPrice.priceValueFormatted;
//中划线
NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:oldString attributes:attribtDic];
......@@ -205,22 +206,26 @@
self.priceLeft.constant = -30;
self.lbDiscountLeft.hidden = NO;
self.lbPriceLeft.attributedText = attribtStr;
self.lbDiscountLeft.text = [NSString stringWithFormat:@"¥%@",[KWMStringUtil getEUR2CNYstring:price]];
// self.lbDiscountLeft.text = [NSString stringWithFormat:@"¥%@",[KWMStringUtil getEUR2CNYstring:price]];
self.lbDiscountLeft.text = price.priceValueFormatted;
}else{
self.priceRight.constant = -30;
self.lbDiscountRight.hidden = NO;
self.lbPriceRight.attributedText = attribtStr;
self.lbDiscountRight.text = [NSString stringWithFormat:@"¥%@",[KWMStringUtil getEUR2CNYstring:price]];
// self.lbDiscountRight.text = [NSString stringWithFormat:@"¥%@",[KWMStringUtil getEUR2CNYstring:price]];
self.lbDiscountRight.text = price.priceValueFormatted;
}
}else{
if (isLeft) {
self.priceLeft.constant = 0;
self.lbDiscountLeft.hidden = YES;
self.lbPriceLeft.text = [NSString stringWithFormat:@"¥%@",[KWMStringUtil getEUR2CNYstring: price]];
// self.lbPriceLeft.text = [NSString stringWithFormat:@"¥%@",[KWMStringUtil getEUR2CNYstring: price]];
self.lbPriceLeft.text = price.priceValueFormatted;
}else{
self.priceRight.constant = 0;
self.lbDiscountRight.hidden = YES;
self.lbPriceRight.text = [NSString stringWithFormat:@"¥%@",[KWMStringUtil getEUR2CNYstring:price]];
// self.lbPriceRight.text = [NSString stringWithFormat:@"¥%@",[KWMStringUtil getEUR2CNYstring:price]];
self.lbPriceRight.text = price.priceValueFormatted;
}
}
}
......
......@@ -11,7 +11,7 @@
#import "UIImageView+WebCache.h"
#import "UIColor+SAMAdditions.h"
#import "KWMStringUtil.h"
#import "KWMCurrencyUtil.h"
@implementation KWMOrderCell{
BOOL isShow;
......@@ -54,7 +54,8 @@
if (order != nil) {
_order = order;
_lbOrderNum.text = [NSString stringWithFormat:@"订单 %@",order.identifier ? order.identifier.stringValue:@""];
_lbTotalPrice.text = [NSString stringWithFormat:@"%@",[KWMStringUtil getEUR2CNYstring:order.totalPrice]];
// _lbTotalPrice.text = [NSString stringWithFormat:@"%@",[KWMStringUtil getEUR2CNYstring:order.totalPrice]];
_lbTotalPrice.text = [[KWMCurrencyUtil sharedInstance] priceFormattedByCurrencyCode:order.totalPrice];
__block NSInteger fulfilledCount = 0;
[order.lineItems enumerateObjectsUsingBlock:^(BUYLineItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
......@@ -62,7 +63,6 @@
fulfilledCount += 1;
}
}];
// TODO: 加入取消订单的状态
NSString *orderStatus = order.cancelled ? @"已取消" : fulfilledCount == 0 ? @"待发货" : fulfilledCount == order.lineItems.count ? @"已发货" : @"部分发货";
self.lbOrderStatus.text = orderStatus;
}
......@@ -71,7 +71,8 @@
- (void)setLineItem:(BUYLineItem *)lineItem{
if (lineItem != nil) {
_lineItem = lineItem;
self.lbPrice.text = [NSString stringWithFormat:@"¥%@",[KWMStringUtil getEUR2CNYstring:lineItem.price]];
// self.lbPrice.text = [NSString stringWithFormat:@"¥%@",[KWMStringUtil getEUR2CNYstring:lineItem.price]];
self.lbPrice.text = [[KWMCurrencyUtil sharedInstance] priceFormattedByCurrencyCode:lineItem.price];
self.lbName.text = lineItem.title;
self.lbSize.text = [NSString stringWithFormat:@"x%@/%@",lineItem.quantity,lineItem.variantTitle];
}
......
......@@ -10,6 +10,7 @@
#import "UIImageView+WebCache.h"
#import "KWMImageUtil.h"
#import "KWMStringUtil.h"
#import "BUYProductVariant+Currency.h"
@implementation KWMCollectionCell
......@@ -39,7 +40,8 @@
NSString *priceString,*discountStr;
if (productVariant.compareAtPrice) {
priceString = [NSString stringWithFormat:@"¥%@",[KWMStringUtil getEUR2CNYstring:productVariant.compareAtPrice]];
// priceString = [NSString stringWithFormat:@"¥%@",[KWMStringUtil getEUR2CNYstring:productVariant.compareAtPrice]];
priceString = productVariant.compareAtPriceFormatted;
NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:priceString attributes:attribtDic];
self.lbPrice.attributedText = attribtStr;
......@@ -48,8 +50,8 @@
self.discountLeft.constant = -28;
self.lbDiscount.textAlignment = NSTextAlignmentCenter;
}
discountStr = [NSString stringWithFormat:@"¥%@",[KWMStringUtil getEUR2CNYstring:productVariant.price]];
// discountStr = [NSString stringWithFormat:@"¥%@",[KWMStringUtil getEUR2CNYstring:productVariant.price]];
discountStr = productVariant.priceFormatted;
self.lbDiscount.text = discountStr;
}else{
self.lbBrand.text = @"";
......
......@@ -186,9 +186,11 @@
BUYProductVariant *productVariant= product.variants.firstObject;
NSAttributedString *detailAttr = [[NSAttributedString alloc] initWithData:[self.product.htmlDescription dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
self.lbDetail.attributedText = detailAttr;
self.lbPrice.text = [KWMStringUtil getEUR2CNYstring:productVariant.price];
// self.lbPrice.text = [KWMStringUtil getEUR2CNYstring:productVariant.price];
self.lbPrice.text = productVariant.price.priceValueFormatted;
if (productVariant.compareAtPrice) {
NSString *priceString = [NSString stringWithFormat:@"¥%@",[KWMStringUtil getEUR2CNYstring:productVariant.compareAtPrice]];
// NSString *priceString = [NSString stringWithFormat:@"¥%@",[KWMStringUtil getEUR2CNYstring:productVariant.compareAtPrice]];
NSString *priceString = productVariant.compareAtPrice.priceValueFormatted;
NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:priceString attributes:attribtDic];
self.lbOldPrice.attributedText = attribtStr;
......@@ -196,12 +198,12 @@
self.lbOldPrice.hidden = YES;
}
UITapGestureRecognizer *priceTap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onClickPrice:)];
UITapGestureRecognizer *priceTap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onClickPrice:)];
UITapGestureRecognizer *priceTap3 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onClickPrice:)];
[self.lbUnit addGestureRecognizer:priceTap1];
[self.lbPrice addGestureRecognizer:priceTap2];
[self.lbOldPrice addGestureRecognizer:priceTap3];
// UITapGestureRecognizer *priceTap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onClickPrice:)];
// UITapGestureRecognizer *priceTap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onClickPrice:)];
// UITapGestureRecognizer *priceTap3 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onClickPrice:)];
// [self.lbUnit addGestureRecognizer:priceTap1];
// [self.lbPrice addGestureRecognizer:priceTap2];
// [self.lbOldPrice addGestureRecognizer:priceTap3];
self.lbUnit.userInteractionEnabled = YES;
self.lbPrice.userInteractionEnabled = YES;
self.lbOldPrice.userInteractionEnabled = YES;
......@@ -227,9 +229,11 @@
BUYProductVariant *productVariant= self.product.variants.firstObject;
if(self.isShowCNY){
self.lbUnit.text = @"¥";
self.lbPrice.text = [KWMStringUtil getEUR2CNYstring:productVariant.price];
// self.lbPrice.text = [KWMStringUtil getEUR2CNYstring:productVariant.price];
self.lbPrice.text = productVariant.price.priceValueFormatted;
if (productVariant.compareAtPrice) {
NSString *priceString = [NSString stringWithFormat:@"¥%@",[KWMStringUtil getEUR2CNYstring:productVariant.compareAtPrice]];
// NSString *priceString = [NSString stringWithFormat:@"¥%@",[KWMStringUtil getEUR2CNYstring:productVariant.compareAtPrice]];
NSString *priceString = productVariant.compareAtPrice.priceValueFormatted;
NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:priceString attributes:attribtDic];
self.lbOldPrice.attributedText = attribtStr;
......
......@@ -80,23 +80,20 @@
<color key="textColor" red="0.30588235294117649" green="0.30588235294117649" blue="0.30588235294117649" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="¥" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="wfT-JC-g9d">
<label hidden="YES" opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="¥" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="wfT-JC-g9d">
<rect key="frame" x="21" y="66" width="9" height="21"/>
<fontDescription key="fontDescription" name="PingFangSC-Regular" family="PingFang SC" pointSize="15"/>
<color key="textColor" red="0.94509803921568625" green="0.5725490196078431" blue="0.60392156862745094" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" " textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="gpT-Sg-ghu">
<rect key="frame" x="40" y="62" width="80.5" height="28"/>
<constraints>
<constraint firstAttribute="width" constant="80" id="0Pv-kq-UND"/>
</constraints>
<rect key="frame" x="20" y="62" width="27" height="28"/>
<fontDescription key="fontDescription" name="PingFangSC-Regular" family="PingFang SC" pointSize="20"/>
<color key="textColor" red="0.94509803921568625" green="0.5725490196078431" blue="0.60392156862745094" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="¥ " textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Mql-V1-hiE">
<rect key="frame" x="120.5" y="68.5" width="25.5" height="18.5"/>
<rect key="frame" x="55" y="68.5" width="25.5" height="18.5"/>
<fontDescription key="fontDescription" name="PingFangSC-Regular" family="PingFang SC" pointSize="13"/>
<color key="textColor" red="0.30588235294117649" green="0.30588235294117649" blue="0.30588235294117649" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
......@@ -141,7 +138,7 @@
</subviews>
<constraints>
<constraint firstItem="gpT-Sg-ghu" firstAttribute="bottom" secondItem="wfT-JC-g9d" secondAttribute="bottom" constant="3" id="0gt-hJ-gW7"/>
<constraint firstItem="Mql-V1-hiE" firstAttribute="leading" secondItem="gpT-Sg-ghu" secondAttribute="trailing" id="2kJ-k6-7uE"/>
<constraint firstItem="Mql-V1-hiE" firstAttribute="leading" secondItem="gpT-Sg-ghu" secondAttribute="trailing" constant="8" id="2kJ-k6-7uE"/>
<constraint firstAttribute="trailing" secondItem="DbC-Os-2e9" secondAttribute="trailing" constant="19" id="3Gy-6z-Jli"/>
<constraint firstAttribute="trailing" secondItem="s6N-a3-C4Z" secondAttribute="trailing" constant="21" id="BH6-4A-Psp"/>
<constraint firstItem="asI-Rf-ZXG" firstAttribute="centerY" secondItem="EM9-Ay-Qxk" secondAttribute="centerY" id="Bx2-7F-7xQ"/>
......@@ -157,7 +154,7 @@
<constraint firstItem="wfT-JC-g9d" firstAttribute="top" secondItem="SQm-rY-OyA" secondAttribute="bottom" constant="7.5" id="gcI-jU-lhJ"/>
<constraint firstAttribute="height" constant="130" id="nLX-8H-mni"/>
<constraint firstItem="SQm-rY-OyA" firstAttribute="leading" secondItem="iJa-Oj-Sd2" secondAttribute="leading" constant="21" id="njb-yV-RRh"/>
<constraint firstItem="gpT-Sg-ghu" firstAttribute="leading" secondItem="wfT-JC-g9d" secondAttribute="trailing" constant="10" id="o9j-pp-GRZ"/>
<constraint firstItem="gpT-Sg-ghu" firstAttribute="leading" secondItem="wfT-JC-g9d" secondAttribute="trailing" constant="-10" id="o9j-pp-GRZ"/>
<constraint firstItem="asI-Rf-ZXG" firstAttribute="centerY" secondItem="RNK-se-cgR" secondAttribute="centerY" id="pfI-QQ-uu0"/>
<constraint firstItem="RNK-se-cgR" firstAttribute="top" secondItem="gpT-Sg-ghu" secondAttribute="bottom" constant="8" id="pjQ-9v-2rS"/>
<constraint firstItem="EM9-Ay-Qxk" firstAttribute="leading" secondItem="iJa-Oj-Sd2" secondAttribute="leading" constant="21" id="rJ1-DF-mLV"/>
......
......@@ -307,7 +307,8 @@
model.name = this.product.title;
model.brand = this.product.vendor;
model.size = variant.title;
model.price = variant.price.floatValue;
// model.price = variant.price.floatValue;
model.price = variant.price;
model.product_id = this.product.identifier;
}
if (!error) {
......
......@@ -8,6 +8,7 @@
#import "KWMShippingCell.h"
#import "KWMStringUtil.h"
#import "KWMCurrencyUtil.h"
@implementation KWMShippingCell
......@@ -38,7 +39,8 @@
}
self.shippingRate = shippingRate;
self.lbTitle.text = shippingRate.title;
self.lbPrice.text = [NSString stringWithFormat:@"¥%@",[KWMStringUtil getEUR2CNYstring:shippingRate.price]];
// self.lbPrice.text = [NSString stringWithFormat:@"¥%@",[KWMStringUtil getEUR2CNYstring:shippingRate.price]];
self.lbPrice.text = [[KWMCurrencyUtil sharedInstance] priceFormattedByCurrencyCode:shippingRate.price];
}
@end
......@@ -30,8 +30,9 @@
_lbBrand.text = shopCartModel.brand;
_lbSize.text = shopCartModel.size;
_lbCount.text = [NSString stringWithFormat:@"%ld",(long)shopCartModel.quantity];
NSInteger totalPrice = shopCartModel.price*shopCartModel.quantity;
_lbPrice.text = [NSString stringWithFormat:@"¥%@",[KWMStringUtil getEUR2CNYstring:@(totalPrice)]];
// NSInteger totalPrice = shopCartModel.price*shopCartModel.quantity;
// _lbPrice.text = [NSString stringWithFormat:@"¥%@",[KWMStringUtil getEUR2CNYstring:@(totalPrice)]];
_lbPrice.text = shopCartModel.totalPrice;
NSURL *imageURL = [NSURL URLWithString: shopCartModel.imageStr];
[_ivImage sd_setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@"ic_loading"]];
}
......
......@@ -184,7 +184,8 @@
}
//总价
if(self.checkout!=nil){
self.lbTotalPrice.text = [NSString stringWithFormat:@"¥%@",[KWMStringUtil getEUR2CNYstring:self.checkout.totalPrice]];
// self.lbTotalPrice.text = [NSString stringWithFormat:@"¥%@",[KWMStringUtil getEUR2CNYstring:self.checkout.totalPrice]];
self.lbTotalPrice.text = self.checkout.totalPrice.priceValueFormatted;
}
}
......
......@@ -15,6 +15,8 @@
#import "KWMLoginVC.h"
#import "KWMLoadingView.h"
#import "UIColor+SAMAdditions.h"
#import "BUYProductVariant+Currency.h"
#import "KWMCurrencyUtil.h"
@interface KWMSelectSizeVC ()
......@@ -177,7 +179,8 @@
- (void)initBySelectSize{
_shopCartModel.size = _selectSize.title;
_shopCartModel.price = _selectSize.price.integerValue;
// _shopCartModel.price = _selectSize.price.integerValue;
_shopCartModel.price = _selectSize.price;
_shopCartModel.identifier = [NSString stringWithFormat:@"%@",_selectSize.identifier];
_shopCartModel.quantity = _count;
}
......@@ -359,9 +362,10 @@
if (defalutSize.identifier.integerValue == self.selectSize.identifier.integerValue && isDefalut) {
self.count = defalutCount;
}
double price = self.selectSize.price.doubleValue * self.count;
self.lbPrice.text = [NSString stringWithFormat: @"¥ %@", [KWMStringUtil getEUR2CNYstring:@(price)]];
// double price = self.selectSize.price.doubleValue * self.count;
NSDecimalNumber *totalPrice = [self.selectSize.priceValue decimalNumberByMultiplyingBy:[NSDecimalNumber decimalNumberWithDecimal:@(self.count).decimalValue]];
// self.lbPrice.text = [NSString stringWithFormat: @"¥ %@", [KWMStringUtil getEUR2CNYstring:@(price)]];
self.lbPrice.text = [[KWMCurrencyUtil sharedInstance] priceFormatted:totalPrice];
}else{
self.lbCount.text = @"0";
self.lbPrice.text = @"¥ 0.00";
......
......@@ -188,7 +188,7 @@
tmp.size = variant.title;
tmp.brand = model.brand;
tmp.name = model.name;
tmp.price = variant.price.floatValue;
tmp.price = variant.price;
tmp.product_id = model.product_id;
}
success(error,cart);
......@@ -253,11 +253,19 @@
//计算总价格
- (void) setTotalPrice{
NSInteger price = 0;
// NSInteger price = 0;
NSDecimalNumber *total = [NSDecimalNumber decimalNumberWithDecimal:@(0).decimalValue];
for (KWMShopCartModel *model in _shopCartList) {
price += model.price * model.quantity;
if (model.line_price) {
// price += model.line_price.priceValue.integerValue;
total = [total decimalNumberByAdding:model.line_price.priceValue];
}else{
// price += [model.price.priceValue decimalNumberByMultiplyingBy:[NSDecimalNumber decimalNumberWithString:@(model.quantity).stringValue]].integerValue;
total = [total decimalNumberByAdding:[model.price.priceValue decimalNumberByMultiplyingBy:[NSDecimalNumber decimalNumberWithString:@(model.quantity).stringValue]]];
}
}
_lbTotalPrice.text = [NSString stringWithFormat: @"¥%@",[KWMStringUtil getEUR2CNYstring:@(price)]];
// _lbTotalPrice.text = [NSString stringWithFormat: @"¥%@",[KWMStringUtil getEUR2CNYstring:@(price)]];
_lbTotalPrice.text = total.priceFormatted;
}
@end
//
// KWNCurrencyUtil.h
// iCemarose
//
// Created by lee on 2017/6/15.
// Copyright © 2017年 kollway. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface KWMCurrencyUtil : NSObject
+ (instancetype) sharedInstance;
- (NSString *)priceFormatted:(NSDecimalNumber *) price;
- (NSString *)priceFormattedByCurrencyCode:(NSDecimalNumber *) pric;
- (NSString *)fixFormatted:(NSString *) price;
- (NSDecimalNumber *) calcPriceByCurrencyCode:(NSDecimalNumber *) price;
@end
//
// KWNCurrencyUtil.m
// iCemarose
//
// Created by lee on 2017/6/15.
// Copyright © 2017年 kollway. All rights reserved.
//
#import "KWMCurrencyUtil.h"
#import "KWMUserDao.h"
@interface KWMCurrencyUtil ()
@property (nonatomic, strong) NSNumberFormatter *numberFormatter;
@end
@implementation KWMCurrencyUtil
+ (instancetype) sharedInstance {
static KWMCurrencyUtil *instance;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [[super allocWithZone:NULL] init];
});
return instance;
}
+ (instancetype)allocWithZone:(struct _NSZone *)zone {
return [self sharedInstance];
}
- (NSNumberFormatter *) numberFormatter {
if (!_numberFormatter) {
_numberFormatter = [[NSNumberFormatter alloc] init];
_numberFormatter.numberStyle = NSNumberFormatterCurrencyStyle;
}
_numberFormatter.currencyCode = [self getCurrencyCode];
return _numberFormatter;
}
- (NSString *) getCurrencyCode {
// NSString *language = [[NSLocale preferredLanguages] objectAtIndex:0];
// return [language isEqualToString:@"zh-CN"] ? @"CNY" : @"EUR"; // @"EUR"
// TODO: 这里应该写到设置中 设置中来设置CurrencyCode
return [@"zh" isEqualToString:[[NSLocale currentLocale] languageCode]] ? @"CNY" : @"EUR";
}
- (NSString *)priceFormattedByCurrencyCode:(NSDecimalNumber *) price {
// return [[[self numberFormatter] stringFromNumber:[self calcPriceByCurrencyCode:self.price]] stringByReplacingOccurrencesOfRegex:@"\\.00" withString:@""];
return [self fixFormatted:[[self numberFormatter] stringFromNumber:[self calcPriceByCurrencyCode:price]]];
}
- (NSString *)priceFormatted:(NSDecimalNumber *)price {
return [self fixFormatted:[[self numberFormatter] stringFromNumber:price]];
}
//- (NSString *)
- (NSString *)fixFormatted:(NSString *) price {
return [price stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%@00",[self numberFormatter].currencyDecimalSeparator] withString:@""];
}
- (NSDecimalNumber *) calcPriceByCurrencyCode:(NSDecimalNumber *) price {
if ([[self getCurrencyCode] isEqualToString:@"CNY"]) {
NSDecimalNumber *rate = [[KWMUserDao shareDao] exchangeRate];
price = [NSDecimalNumber decimalNumberWithString:@(ceil([[rate decimalNumberByMultiplyingBy:price] decimalNumberByMultiplyingBy:[NSDecimalNumber decimalNumberWithString:@"1.03"]].doubleValue)).stringValue];
}
return price;
}
@end
......@@ -49,7 +49,7 @@
+ (NSString *)transform:(NSString *)chinese;
//欧元转人民币
+ (NSString *)getEUR2CNYstring:(NSNumber *)price;
//+ (NSString *)getEUR2CNYstring:(NSNumber *)price;
@end
......@@ -485,9 +485,9 @@ static NSString *kEnglishNum = @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstu
return CNYstring;
}
float exchageRate = [[KWMUserDao shareDao] exchangeRate].floatValue;
if(exchageRate == 0){
exchageRate = ExchangeRate;
}
// if(exchageRate == 0){
// exchageRate = ExchangeRate;
// }
CNYstring = [NSString stringWithFormat:@"%.0f",price.floatValue * exchageRate];
// CNYstring = [NSString stringWithFormat:@"%.2f",price.floatValue];
......
......@@ -10,6 +10,7 @@
#import <Foundation/Foundation.h>
#import "KWMAPIManager.h"
#import <MagicalRecord/MagicalRecord.h>
#import "NSDecimalNumber+Currency.h"
#ifndef Header_Prefix_h
#define Header_Prefix_h
......@@ -95,7 +96,8 @@
#define BigImage 3
//默认欧元汇率,如果安装后第一次请求最新汇率数据失败,会使用该汇率显示价格
#define ExchangeRate 7.6625
//#define ExchangeRate 7.6625
#define ExchangeRateString @"7.6625"
//品牌图片url
#define Burberry @"https://cdn.shopify.com/s/files/1/1089/5284/collections/Burberry_Childrenswear_Campaign_July_2016_001.jpg?v=1473238213"
......
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