Commit 5aa0904e by lee

u

parent 2d878d7a
...@@ -30,4 +30,6 @@ typedef void(^ShoppingCartCallBack) (NSError *error,KWMCartResult *cart); ...@@ -30,4 +30,6 @@ typedef void(^ShoppingCartCallBack) (NSError *error,KWMCartResult *cart);
- (void)deleteProductWithVariantId:(NSNumber *) variantId callback:(ShoppingCartCallBack) callback; - (void)deleteProductWithVariantId:(NSNumber *) variantId callback:(ShoppingCartCallBack) callback;
- (void)clearCartWithCallback:(ShoppingCartCallBack) callback;
@end @end
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#import "KWMCartResult.h" #import "KWMCartResult.h"
#import "KWMShopCartData.h" #import "KWMShopCartData.h"
#import <RegexKitLite/RegexKitLite.h> #import <RegexKitLite/RegexKitLite.h>
#import <RXCollections/RXCollection.h>
@interface KWMShoppingCart () @interface KWMShoppingCart ()
...@@ -142,7 +143,7 @@ ...@@ -142,7 +143,7 @@
// callback(error,nil); // callback(error,nil);
}]; }];
[self addTasksObject:task]; [self addTasksObject:task];
for (int i=0; i<quantites.count; i++) { for (int i=0; i<quantites.count && self.items.count; i++) {
[self changeLocalCartWithVariantId:variantIds[i] quantity:quantites[i].integerValue flag:quantites[i].integerValue ? 2 : 0]; [self changeLocalCartWithVariantId:variantIds[i] quantity:quantites[i].integerValue flag:quantites[i].integerValue ? 2 : 0];
} }
callback(nil,self.result); callback(nil,self.result);
...@@ -152,6 +153,27 @@ ...@@ -152,6 +153,27 @@
[self changeProductWithVariantId:variantId quantity:0 callback:callback]; [self changeProductWithVariantId:variantId quantity:0 callback:callback];
} }
- (void)clearCartWithCallback:(ShoppingCartCallBack)callback {
NSMutableArray *quantity = [NSMutableArray new];
NSArray *ids = [self.items rx_mapWithBlock:^id(KWMShopCartModel* each) {
[quantity addObject:@(0)];
return each.identifier;
}];
[self setResult:[KWMCartResult new]];
__weak typeof(self) this = self;
id task = [[KWMAPIManager sharedManager] updateProductWithVariantIds:ids quantities:quantity success:^(NSURLSessionDataTask *task, KWMCartResult *result) {
[this missionCompleted];
// if (version == this.version) {
[[KWMShoppingCart sharedInstance] setResult:result];
callback(nil,result);
// }
} failure:^(NSURLSessionDataTask *task, NSError *error) {
[this missionCompleted];
callback(error,nil);
}];
[self addTasksObject:task];
}
- (KWMCartResult *) changeLocalCartWithVariantId:(NSNumber *) variantId quantity:(NSInteger) quantity flag:(NSInteger) flag { - (KWMCartResult *) changeLocalCartWithVariantId:(NSNumber *) variantId quantity:(NSInteger) quantity flag:(NSInteger) flag {
NSMutableArray<KWMShopCartModel *> *items= self.items; NSMutableArray<KWMShopCartModel *> *items= self.items;
NSInteger count = self.result.item_count.integerValue; NSInteger count = self.result.item_count.integerValue;
......
...@@ -184,8 +184,9 @@ ...@@ -184,8 +184,9 @@
[self.btnBrand setTitle:product.vendor forState:UIControlStateNormal]; [self.btnBrand setTitle:product.vendor forState:UIControlStateNormal];
self.lbName.text = product.title; self.lbName.text = product.title;
BUYProductVariant *productVariant= product.variants.firstObject; BUYProductVariant *productVariant= product.variants.firstObject;
NSAttributedString *detailAttr = [[NSAttributedString alloc] initWithData:[self.product.htmlDescription dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil]; // 2017-06-30 暂时注释
self.lbDetail.attributedText = detailAttr; // 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; self.lbPrice.text = productVariant.price.priceValueFormatted;
if (productVariant.compareAtPrice) { if (productVariant.compareAtPrice) {
...@@ -222,32 +223,32 @@ ...@@ -222,32 +223,32 @@
} }
-(void)onClickPrice:(UITapGestureRecognizer *)tapGesture{ -(void)onClickPrice:(UITapGestureRecognizer *)tapGesture{
if(self.product == nil){ // if(self.product == nil){
return; // return;
} // }
self.isShowCNY = !self.isShowCNY; // self.isShowCNY = !self.isShowCNY;
BUYProductVariant *productVariant= self.product.variants.firstObject; // BUYProductVariant *productVariant= self.product.variants.firstObject;
if(self.isShowCNY){ // if(self.isShowCNY){
self.lbUnit.text = @"¥"; // self.lbUnit.text = @"¥";
// self.lbPrice.text = [KWMStringUtil getEUR2CNYstring:productVariant.price]; //// self.lbPrice.text = [KWMStringUtil getEUR2CNYstring:productVariant.price];
self.lbPrice.text = productVariant.price.priceValueFormatted; // self.lbPrice.text = productVariant.price.priceValueFormatted;
if (productVariant.compareAtPrice) { // if (productVariant.compareAtPrice) {
// NSString *priceString = [NSString stringWithFormat:@"¥%@",[KWMStringUtil getEUR2CNYstring:productVariant.compareAtPrice]]; //// NSString *priceString = [NSString stringWithFormat:@"¥%@",[KWMStringUtil getEUR2CNYstring:productVariant.compareAtPrice]];
NSString *priceString = productVariant.compareAtPrice.priceValueFormatted; // NSString *priceString = productVariant.compareAtPrice.priceValueFormatted;
NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]}; // NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:priceString attributes:attribtDic]; // NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:priceString attributes:attribtDic];
self.lbOldPrice.attributedText = attribtStr; // self.lbOldPrice.attributedText = attribtStr;
} // }
}else{ // }else{
self.lbUnit.text = @"€"; // self.lbUnit.text = @"€";
self.lbPrice.text = productVariant.price.stringValue; // self.lbPrice.text = productVariant.price.stringValue;
if (productVariant.compareAtPrice) { // if (productVariant.compareAtPrice) {
NSString *priceString = [NSString stringWithFormat:@"€%@",productVariant.compareAtPrice.stringValue]; // NSString *priceString = [NSString stringWithFormat:@"€%@",productVariant.compareAtPrice.stringValue];
NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]}; // NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:priceString attributes:attribtDic]; // NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:priceString attributes:attribtDic];
self.lbOldPrice.attributedText = attribtStr; // self.lbOldPrice.attributedText = attribtStr;
} // }
} // }
} }
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#import "KWMValidateUtil.h" #import "KWMValidateUtil.h"
#import "KWMPayUtil.h" #import "KWMPayUtil.h"
#import "KWMShopCartData.h" #import "KWMShopCartData.h"
#import "KWMShoppingCart.h"
@interface KWMBeforePayVC () @interface KWMBeforePayVC ()
@property (nonatomic) BUYCustomer *customer; @property (nonatomic) BUYCustomer *customer;
...@@ -719,8 +720,13 @@ ...@@ -719,8 +720,13 @@
-(void) clearCheckout { -(void) clearCheckout {
self.cartCookie = nil; self.cartCookie = nil;
[KWMHttpUtil deleteCookie:@"cart"]; [[KWMShoppingCart sharedInstance] clearCartWithCallback:^(NSError *error, KWMCartResult *cart) {
[[KWMShopCartData alloc] removeAllItems]; // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[KWMHttpUtil deleteCookie:@"cart"];
// });
}];
// [KWMHttpUtil deleteCookie:@"cart"];
// [[KWMShopCartData alloc] removeAllItems];
[self.userDao deleteCheckoutCache]; [self.userDao deleteCheckoutCache];
} }
......
...@@ -71,7 +71,8 @@ ...@@ -71,7 +71,8 @@
- (NSDecimalNumber *) calcPriceByCurrencyCode:(NSDecimalNumber *) price { - (NSDecimalNumber *) calcPriceByCurrencyCode:(NSDecimalNumber *) price {
if ([[self getCurrencyCode] isEqualToString:@"CNY"]) { if ([[self getCurrencyCode] isEqualToString:@"CNY"]) {
NSDecimalNumber *rate = [[KWMUserDao shareDao] exchangeRate]; NSDecimalNumber *rate = [[KWMUserDao shareDao] exchangeRate];
price = [[rate decimalNumberByMultiplyingBy:price] decimalNumberByMultiplyingBy:[NSDecimalNumber decimalNumberWithString:@"1.03"]]; // price = [[rate decimalNumberByMultiplyingBy:price] decimalNumberByMultiplyingBy:[NSDecimalNumber decimalNumberWithString:@"1.03"]];
price = [rate decimalNumberByMultiplyingBy:price];
} }
return price; return price;
} }
......
...@@ -78,7 +78,7 @@ ...@@ -78,7 +78,7 @@
#define Shopify_SHOP_DOMAIN @"cemarose.myshopify.com" #define Shopify_SHOP_DOMAIN @"cemarose.myshopify.com"
#define Shopify_API_KEY @"c2f6fae97741ea6db4cad7ae8f70fef3" #define Shopify_API_KEY @"c2f6fae97741ea6db4cad7ae8f70fef3"
#define Shopify_APP_ID @"8" #define Shopify_APP_ID @"8"
#end #endif
//软键盘输入限制 //软键盘输入限制
#define NUM @"0123456789" #define NUM @"0123456789"
......
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