Commit 5938fa3b by David Muzi

merge with develop

parents 3adc2c74 83dc0a05
...@@ -269,7 +269,7 @@ CGFloat const BUYMaxProductViewHeight = 640.0; ...@@ -269,7 +269,7 @@ CGFloat const BUYMaxProductViewHeight = 640.0;
[self.navigationController setNavigationBarHidden:NO]; [self.navigationController setNavigationBarHidden:NO];
} }
if (self.product.publicURL) { if (self.URLForSharing) {
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(shareLink)]; UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(shareLink)];
NSArray *rightButtons = [@[rightButton] arrayByAddingObjectsFromArray:self.navigationItem.rightBarButtonItems]; NSArray *rightButtons = [@[rightButton] arrayByAddingObjectsFromArray:self.navigationItem.rightBarButtonItems];
self.navigationItem.rightBarButtonItems = rightButtons; self.navigationItem.rightBarButtonItems = rightButtons;
...@@ -584,7 +584,8 @@ CGFloat const BUYMaxProductViewHeight = 640.0; ...@@ -584,7 +584,8 @@ CGFloat const BUYMaxProductViewHeight = 640.0;
- (NSURL *)URLForSharing - (NSURL *)URLForSharing
{ {
return self.product.publicURL; NSString *urlString = [NSString stringWithFormat:@"%@/products/%@",self.shop.domain, self.product.handle];
return [NSURL URLWithString:urlString];
} }
- (UIImage *)ImageForSharing - (UIImage *)ImageForSharing
......
...@@ -162,7 +162,7 @@ ...@@ -162,7 +162,7 @@
{ {
[self.collectionOperation cancel]; [self.collectionOperation cancel];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES]; [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
self.collectionOperation = [self.client getProductsPage:1 inCollection:self.collection.identifier sortOrder:collectionSort completion:^(NSArray *products, NSUInteger page, BOOL reachedEnd, NSError *error) { self.collectionOperation = [self.client getProductsPage:1 withTags:nil inCollection:self.collection.identifier sortOrder:collectionSort completion:^(NSArray *products, NSUInteger page, BOOL reachedEnd, NSError *error) {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
if (error == nil && products) { if (error == nil && products) {
......
...@@ -308,4 +308,21 @@ ...@@ -308,4 +308,21 @@
}]; }];
} }
- (void)testGettingTags
{
XCTestExpectation *expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)];
[self.client getProductTagsPage:1 completion:^(NSArray *tags, NSUInteger page, BOOL end, NSError *error){
XCTAssertNil(error);
XCTAssertNotNil(tags);
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:10 handler:^(NSError *error) {
XCTAssertNil(error);
}];
}
@end @end
...@@ -184,7 +184,7 @@ NSString * const BUYFakeCustomerToken = @"dsfasdgafdg"; ...@@ -184,7 +184,7 @@ NSString * const BUYFakeCustomerToken = @"dsfasdgafdg";
- (void)testProductsInCollection - (void)testProductsInCollection
{ {
BUYRequestOperation *task = (BUYRequestOperation *)[self.client getProductsPage:1 inCollection:@1 sortOrder:BUYCollectionSortCollectionDefault completion:^(NSArray<BUYProduct *> *products, NSUInteger page, BOOL reachedEnd, NSError *error) {}]; BUYRequestOperation *task = (BUYRequestOperation *)[self.client getProductsPage:1 inCollection:@1 withTags:nil sortOrder:BUYCollectionSortCollectionDefault completion:^(NSArray<BUYProduct *> *products, NSUInteger page, BOOL reachedEnd, NSError *error) {}];
XCTAssertEqualObjects(task.originalRequest.HTTPMethod, @"GET"); XCTAssertEqualObjects(task.originalRequest.HTTPMethod, @"GET");
XCTAssertEqualObjects(task.originalRequest.URL.scheme, @"https"); XCTAssertEqualObjects(task.originalRequest.URL.scheme, @"https");
XCTAssertEqualObjects(task.originalRequest.URL.host, @"test_shop"); XCTAssertEqualObjects(task.originalRequest.URL.host, @"test_shop");
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
- (NSURL *)urlForShop; - (NSURL *)urlForShop;
- (NSURL *)urlForProductListingsWithParameters:(NSDictionary *)parameters; - (NSURL *)urlForProductListingsWithParameters:(NSDictionary *)parameters;
- (NSURL *)urlForCollectionListingsWithParameters:(NSDictionary *)parameters; - (NSURL *)urlForCollectionListingsWithParameters:(NSDictionary *)parameters;
- (NSURL *)urlForProductTagsWithParameters:(NSDictionary *)parameters;
- (NSURL *)urlForCheckouts; - (NSURL *)urlForCheckouts;
- (NSURL *)urlForCheckoutsWithToken:(NSString *)token; - (NSURL *)urlForCheckoutsWithToken:(NSString *)token;
......
...@@ -124,6 +124,11 @@ ...@@ -124,6 +124,11 @@
return [[[[self urlForApps] appendPath:@"/collection_listings"] appendExtension] appendParameters:parameters]; return [[[[self urlForApps] appendPath:@"/collection_listings"] appendExtension] appendParameters:parameters];
} }
- (NSURL *)urlForProductTagsWithParameters:(NSDictionary *)parameters
{
return [[[[self urlForApps] appendPath:@"/product_listings/tags"] appendExtension] appendParameters:parameters];;
}
#pragma mark - Checkout - #pragma mark - Checkout -
- (NSURL *)urlForCheckouts - (NSURL *)urlForCheckouts
......
...@@ -119,6 +119,16 @@ typedef void (^BUYDataCollectionsListBlock)(NSArray<BUYCollection *> * _Nullable ...@@ -119,6 +119,16 @@ typedef void (^BUYDataCollectionsListBlock)(NSArray<BUYCollection *> * _Nullable
*/ */
typedef void (^BUYDataProductListBlock)(NSArray<BUYProduct *> * _Nullable products, NSUInteger page, BOOL reachedEnd, NSError * _Nullable error); typedef void (^BUYDataProductListBlock)(NSArray<BUYProduct *> * _Nullable products, NSUInteger page, BOOL reachedEnd, NSError * _Nullable error);
/**
* Return block containing a list of tags
*
* @param tags An array of tag titles
* @param page Index of the page requested
* @param reachedEnd Boolean indicating whether additional pages exist
* @param error An optional NSError
*/
typedef void (^BUYDataTagsListBlock)(NSArray <NSString *> * _Nullable tags, NSUInteger page, BOOL reachedEnd, NSError * _Nullable error);
@interface BUYClient (Storefront) @interface BUYClient (Storefront)
/** /**
...@@ -171,6 +181,16 @@ typedef void (^BUYDataProductListBlock)(NSArray<BUYProduct *> * _Nullable produc ...@@ -171,6 +181,16 @@ typedef void (^BUYDataProductListBlock)(NSArray<BUYProduct *> * _Nullable produc
- (NSOperation *)getProductsByIds:(NSArray<NSNumber *> *)productIds completion:(BUYDataProductsBlock)block; - (NSOperation *)getProductsByIds:(NSArray<NSNumber *> *)productIds completion:(BUYDataProductsBlock)block;
/** /**
* Gets the list of tags for all products
*
* @param page Page to request. Pages start at 1.
* @param block (^BUYDataTagsListBlock)(NSArray <NSString *> * _Nullable tags, NSUInteger page, BOOL reachedEnd, NSError * _Nullable error)
*
* @return The associated NSOperation
*/
- (NSOperation *)getProductTagsPage:(NSUInteger)page completion:(BUYDataTagsListBlock)block;
/**
* Fetches collections based off page * Fetches collections based off page
* *
* @param page Index of the page requested * @param page Index of the page requested
...@@ -197,12 +217,13 @@ typedef void (^BUYDataProductListBlock)(NSArray<BUYProduct *> * _Nullable produc ...@@ -197,12 +217,13 @@ typedef void (^BUYDataProductListBlock)(NSArray<BUYProduct *> * _Nullable produc
* *
* @param page Index of the page requested * @param page Index of the page requested
* @param collectionId The `collectionId` found in the BUYCollection object to fetch the products from * @param collectionId The `collectionId` found in the BUYCollection object to fetch the products from
* @param tags An array of tags which each product must contain
* @param sortOrder The sort order that overrides the default collection sort order * @param sortOrder The sort order that overrides the default collection sort order
* @param block (NSArray *products, NSUInteger page, BOOL reachedEnd, NSError *error) * @param block (NSArray *products, NSUInteger page, BOOL reachedEnd, NSError *error)
* *
* @return the associated BUYRequestOperation * @return the associated BUYRequestOperation
*/ */
- (NSOperation *)getProductsPage:(NSUInteger)page inCollection:(NSNumber *)collectionId sortOrder:(BUYCollectionSort)sortOrder completion:(BUYDataProductListBlock)block; - (NSOperation *)getProductsPage:(NSUInteger)page inCollection:(nullable NSNumber *)collectionId withTags:(nullable NSArray <NSString *> *)tags sortOrder:(BUYCollectionSort)sortOrder completion:(BUYDataProductListBlock)block;
@end @end
......
...@@ -124,6 +124,23 @@ static NSString * const BUYCollectionsKey = @"collection_listings"; ...@@ -124,6 +124,23 @@ static NSString * const BUYCollectionsKey = @"collection_listings";
}]; }];
} }
- (NSOperation *)getProductTagsPage:(NSUInteger)page completion:(BUYDataTagsListBlock)block
{
NSURL *url = [self urlForProductTagsWithParameters:@{
@"limit" : @(self.pageSize),
@"page" : @(page),
}];
return [self getRequestForURL:url completionHandler:^(NSDictionary *json, NSHTTPURLResponse *response, NSError *error) {
NSArray *tags = nil;
if (json && !error) {
tags = [json[@"tags"] valueForKey:@"title"];
}
block(tags, [self hasReachedEndOfPage:tags], page, error);
}];
}
- (NSOperation *)getCollectionsPage:(NSUInteger)page completion:(BUYDataCollectionsListBlock)block - (NSOperation *)getCollectionsPage:(NSUInteger)page completion:(BUYDataCollectionsListBlock)block
{ {
NSURL *url = [self urlForCollectionListingsWithParameters:@{ NSURL *url = [self urlForCollectionListingsWithParameters:@{
...@@ -143,19 +160,26 @@ static NSString * const BUYCollectionsKey = @"collection_listings"; ...@@ -143,19 +160,26 @@ static NSString * const BUYCollectionsKey = @"collection_listings";
- (NSOperation *)getProductsPage:(NSUInteger)page inCollection:(NSNumber *)collectionId completion:(BUYDataProductListBlock)block - (NSOperation *)getProductsPage:(NSUInteger)page inCollection:(NSNumber *)collectionId completion:(BUYDataProductListBlock)block
{ {
return [self getProductsPage:page inCollection:collectionId sortOrder:BUYCollectionSortCollectionDefault completion:block]; return [self getProductsPage:page inCollection:collectionId withTags:nil sortOrder:BUYCollectionSortCollectionDefault completion:block];
} }
- (NSOperation *)getProductsPage:(NSUInteger)page inCollection:(NSNumber *)collectionId sortOrder:(BUYCollectionSort)sortOrder completion:(BUYDataProductListBlock)block - (NSOperation *)getProductsPage:(NSUInteger)page inCollection:(nullable NSNumber *)collectionId withTags:(nullable NSArray <NSString *> *)tags sortOrder:(BUYCollectionSort)sortOrder completion:(BUYDataProductListBlock)block
{ {
BUYAssert(collectionId, @"Failed to get products page. Invalid collectionID."); NSMutableDictionary *params = @{
@"limit" : @(self.pageSize),
@"page" : @(page),
@"sort_by" : [BUYCollection sortOrderParameterForCollectionSort:sortOrder]
}.mutableCopy;
NSURL *url = [self urlForProductListingsWithParameters:@{ if (tags) {
@"collection_id" : collectionId, params[@"tags"] = [tags componentsJoinedByString:@","];
@"limit" : @(self.pageSize), }
@"page" : @(page),
@"sort_by" : [BUYCollection sortOrderParameterForCollectionSort:sortOrder] if (collectionId) {
}]; params[@"collection_id"] = collectionId;
}
NSURL *url = [self urlForProductListingsWithParameters:params];
return [self getRequestForURL:url completionHandler:^(NSDictionary *json, NSHTTPURLResponse *response, NSError *error) { return [self getRequestForURL:url completionHandler:^(NSDictionary *json, NSHTTPURLResponse *response, NSError *error) {
......
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