Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
shopify_iossdk
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cemarose
shopify_iossdk
Commits
4764ec5f
Commit
4764ec5f
authored
9 years ago
by
Brent Gulanowski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor and fix issue with button title.
parent
75bf8f17
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
97 deletions
+39
-97
ProductViewController.h
... SDK Advanced Sample/Product View/ProductViewController.h
+0
-9
ProductViewController.m
... SDK Advanced Sample/Product View/ProductViewController.m
+39
-88
No files found.
Mobile Buy SDK Sample Apps/Sample App Advanced/Mobile Buy SDK Advanced Sample/Product View/ProductViewController.h
View file @
4764ec5f
...
@@ -56,15 +56,6 @@
...
@@ -56,15 +56,6 @@
-
(
instancetype
)
initWithClient
:(
BUYClient
*
)
client
cart
:(
BUYCart
*
)
cart
;
-
(
instancetype
)
initWithClient
:(
BUYClient
*
)
client
cart
:(
BUYCart
*
)
cart
;
/**
/**
* Loads the product details
*
* @param productId the product ID for the item to display
* @param completion a block to be called on completion of the loading of the product details. Will be called on the main thread.
* Upon success, the view controller should be presented modally
*/
-
(
void
)
loadProduct
:(
NSString
*
)
productId
completion
:(
void
(
^
)(
BOOL
success
,
NSError
*
error
))
completion
;
/**
* Alternative method when setting the product (and optionally, shop) directly on the view controller
* Alternative method when setting the product (and optionally, shop) directly on the view controller
*
*
* @param product the product to display
* @param product the product to display
...
...
This diff is collapsed.
Click to expand it.
Mobile Buy SDK Sample Apps/Sample App Advanced/Mobile Buy SDK Advanced Sample/Product View/ProductViewController.m
View file @
4764ec5f
...
@@ -64,10 +64,8 @@ CGFloat const BUYMaxProductViewHeight = 640.0;
...
@@ -64,10 +64,8 @@ CGFloat const BUYMaxProductViewHeight = 640.0;
@property
(
nonatomic
,
assign
)
BOOL
shouldEnableVariantSelection
;
@property
(
nonatomic
,
assign
)
BOOL
shouldEnableVariantSelection
;
@property
(
nonatomic
,
assign
)
BOOL
shouldShowDescription
;
@property
(
nonatomic
,
assign
)
BOOL
shouldShowDescription
;
@property
(
nonatomic
,
strong
)
BUYProduct
*
product
;
@property
(
nonatomic
,
strong
)
BUYProduct
*
product
;
@property
(
nonatomic
,
assign
)
BOOL
isLoading
;
@property
(
nonatomic
,
strong
)
NSNumberFormatter
*
currencyFormatter
;
@property
(
nonatomic
,
strong
)
NSNumberFormatter
*
currencyFormatter
;
@property
(
nonatomic
,
weak
)
BUYCart
*
cart
;
@property
(
nonatomic
,
weak
)
BUYCart
*
cart
;
@property
(
nonatomic
,
assign
)
BOOL
isLoadingShop
;
// views
// views
@property
(
nonatomic
,
strong
)
ProductView
*
productView
;
@property
(
nonatomic
,
strong
)
ProductView
*
productView
;
...
@@ -154,37 +152,6 @@ CGFloat const BUYMaxProductViewHeight = 640.0;
...
@@ -154,37 +152,6 @@ CGFloat const BUYMaxProductViewHeight = 640.0;
self
.
view
.
backgroundColor
=
[
UIColor
whiteColor
];
self
.
view
.
backgroundColor
=
[
UIColor
whiteColor
];
}
}
-
(
ProductView
*
)
productView
{
if
(
_productView
==
nil
&&
self
.
product
!=
nil
&&
self
.
shop
!=
nil
)
{
_productView
=
[[
ProductView
alloc
]
initWithFrame
:
CGRectMake
(
0
,
0
,
self
.
preferredContentSize
.
width
,
self
.
preferredContentSize
.
height
)
product
:
self
.
product
shouldShowApplePaySetup
:
self
.
shouldShowApplePaySetup
];
_productView
.
translatesAutoresizingMaskIntoConstraints
=
NO
;
_productView
.
hidden
=
YES
;
[
self
.
view
addSubview
:
_productView
];
[
self
.
view
addConstraints
:[
NSLayoutConstraint
constraintsWithVisualFormat
:
@"V:|[_productView]|"
options
:
0
metrics
:
nil
views
:
NSDictionaryOfVariableBindings
(
_productView
)]];
[
self
.
view
addConstraints
:[
NSLayoutConstraint
constraintsWithVisualFormat
:
@"H:|[_productView]|"
options
:
0
metrics
:
nil
views
:
NSDictionaryOfVariableBindings
(
_productView
)]];
_productView
.
tableView
.
delegate
=
self
;
_productView
.
tableView
.
dataSource
=
self
;
[
_productView
.
productViewFooter
setApplePayAvailable
:
self
.
shouldShowApplePayButton
requiresSetup
:
self
.
shouldShowApplePaySetup
];
[
_productView
.
productViewFooter
.
paymentButton
addTarget
:
self
action
:
@selector
(
checkoutWithApplePay
)
forControlEvents
:
UIControlEventTouchUpInside
];
if
(
self
.
cart
)
{
[
_productView
.
productViewFooter
.
actionButton
setTitle
:
NSLocalizedString
(
@"Add to Cart"
,
nil
)
forState
:
UIControlStateNormal
];
[
_productView
.
productViewFooter
.
actionButton
addTarget
:
self
action
:
@selector
(
addSelectedVariantToCart
)
forControlEvents
:
UIControlEventTouchUpInside
];
}
else
{
[
_productView
.
productViewFooter
.
actionButton
addTarget
:
self
action
:
@selector
(
checkoutWithShopify
)
forControlEvents
:
UIControlEventTouchUpInside
];
}
_productView
.
productViewHeader
.
collectionView
.
delegate
=
self
;
_productView
.
productViewHeader
.
collectionView
.
dataSource
=
self
;
_productView
.
layoutMargins
=
UIEdgeInsetsMake
(
self
.
productView
.
layoutMargins
.
top
,
self
.
productView
.
layoutMargins
.
left
,
self
.
bottomLayoutGuide
.
length
,
self
.
productView
.
layoutMargins
.
right
);
}
return
_productView
;
}
-
(
CGSize
)
preferredContentSize
-
(
CGSize
)
preferredContentSize
{
{
return
CGSizeMake
(
MIN
(
BUYMaxProductViewWidth
,
self
.
view
.
bounds
.
size
.
width
),
return
CGSizeMake
(
MIN
(
BUYMaxProductViewWidth
,
self
.
view
.
bounds
.
size
.
width
),
...
@@ -246,55 +213,15 @@ CGFloat const BUYMaxProductViewHeight = 640.0;
...
@@ -246,55 +213,15 @@ CGFloat const BUYMaxProductViewHeight = 640.0;
return
presentationController
;
return
presentationController
;
}
}
-
(
void
)
load
Product
:
(
NSString
*
)
productId
completion
:
(
void
(
^
)(
BOOL
success
,
NSError
*
error
))
completion
-
(
void
)
load
WithProduct
:
(
BUYProduct
*
)
product
completion
:
(
void
(
^
)(
BOOL
success
,
NSError
*
error
))
completion
{
{
if
(
productId
==
nil
)
{
self
.
product
=
product
;
if
(
completion
)
{
completion
(
NO
,
[
NSError
errorWithDomain
:
BUYShopifyError
code
:
BUYShopifyError_NoProductSpecified
userInfo
:
nil
]);
}
}
else
{
self
.
isLoading
=
YES
;
[
self
getShopWithCallback
:
^
(
BOOL
success
,
NSError
*
error
)
{
if
(
success
)
{
self
.
productId
=
productId
;
[
self
.
client
getProductById
:
productId
completion
:
^
(
BUYProduct
*
product
,
NSError
*
error
)
{
dispatch_async
(
dispatch_get_main_queue
(),
^
{
if
(
error
)
{
if
(
completion
)
{
completion
(
NO
,
error
);
}
}
else
{
self
.
product
=
product
;
if
(
completion
)
{
completion
(
YES
,
nil
);
}
}
});
}];
}
else
{
self
.
isLoading
=
NO
;
if
(
completion
)
{
completion
(
success
,
error
);
}
}
}];
}
}
-
(
void
)
loadWithProduct
:
(
BUYProduct
*
)
product
completion
:
(
void
(
^
)(
BOOL
success
,
NSError
*
error
))
completion
;
{
if
(
product
==
nil
)
{
if
(
product
==
nil
)
{
completion
(
NO
,
[
NSError
errorWithDomain
:
BUYShopifyError
code
:
BUYShopifyError_NoProductSpecified
userInfo
:
nil
]);
completion
(
NO
,
[
NSError
errorWithDomain
:
BUYShopifyError
code
:
BUYShopifyError_NoProductSpecified
userInfo
:
nil
]);
}
else
{
}
else
{
self
.
isLoading
=
YES
;
if
(
self
.
shop
==
nil
)
{
if
(
self
.
shop
==
nil
)
{
[
self
getShopWithCallback
:
^
(
BOOL
success
,
NSError
*
error
)
{
[
self
getShopWithCallback
:
^
(
BOOL
success
,
NSError
*
error
)
{
if
(
success
)
{
self
.
product
=
product
;
}
if
(
completion
)
{
if
(
completion
)
{
completion
(
success
,
error
);
completion
(
success
,
error
);
}
}
...
@@ -313,37 +240,30 @@ CGFloat const BUYMaxProductViewHeight = 640.0;
...
@@ -313,37 +240,30 @@ CGFloat const BUYMaxProductViewHeight = 640.0;
-
(
void
)
getShopWithCallback
:
(
void
(
^
)(
BOOL
,
NSError
*
))
block
-
(
void
)
getShopWithCallback
:
(
void
(
^
)(
BOOL
,
NSError
*
))
block
{
{
// fetch shop details for the currency and country codes
// fetch shop details for the currency and country codes
self
.
isLoadingShop
=
YES
;
[
self
.
client
getShop
:
^
(
BUYShop
*
shop
,
NSError
*
error
)
{
[
self
.
client
getShop
:
^
(
BUYShop
*
shop
,
NSError
*
error
)
{
if
(
error
==
nil
)
{
if
(
error
==
nil
)
{
self
.
shop
=
shop
;
self
.
shop
=
shop
;
[
self
createProductView
];
}
}
else
{
else
{
if
([
self
.
delegate
respondsToSelector
:
@selector
(
controllerFailedToStartApplePayProcess
:)])
{
if
([
self
.
delegate
respondsToSelector
:
@selector
(
controllerFailedToStartApplePayProcess
:)])
{
[
self
.
delegate
controllerFailedToStartApplePayProcess
:
self
];
[
self
.
delegate
controllerFailedToStartApplePayProcess
:
self
];
}
}
}
}
self
.
isLoadingShop
=
NO
;
if
(
block
)
block
((
error
==
nil
),
error
);
if
(
block
)
block
((
error
==
nil
),
error
);
}];
}];
}
}
-
(
void
)
setProduct
:
(
BUYProduct
*
)
product
-
(
void
)
setProduct
:
(
BUYProduct
*
)
product
{
{
self
.
isLoading
=
NO
;
_product
=
product
;
_product
=
product
;
self
.
navigationItem
.
title
=
_product
.
title
;
self
.
selectedProductVariant
=
[
_product
.
variants
firstObject
];
self
.
selectedProductVariant
=
[
_product
.
variants
firstObject
];
self
.
shouldShowVariantSelector
=
[
_product
isDefaultVariant
]
==
NO
;
self
.
shouldShowVariantSelector
=
[
_product
isDefaultVariant
]
==
NO
;
self
.
shouldEnableVariantSelection
=
self
.
shouldShowVariantSelector
&&
[
_product
.
variants
count
]
>
1
;
self
.
shouldEnableVariantSelection
=
self
.
shouldShowVariantSelector
&&
[
_product
.
variants
count
]
>
1
;
self
.
shouldShowDescription
=
([
_product
.
htmlDescription
length
]
==
0
)
==
NO
;
self
.
shouldShowDescription
=
([
_product
.
htmlDescription
length
]
==
0
)
==
NO
;
self
.
productView
.
hidden
=
NO
;
[
self
setupNavigationBarAppearance
];
[
self
.
activityIndicatorView
stopAnimating
];
[
self
setNeedsStatusBarAppearanceUpdate
];
[
self
setNeedsStatusBarAppearanceUpdate
];
if
(
self
.
presentingViewController
)
{
if
(
self
.
presentingViewController
)
{
[
self
.
navigationController
setNavigationBarHidden
:
NO
];
[
self
.
navigationController
setNavigationBarHidden
:
NO
];
...
@@ -362,8 +282,39 @@ CGFloat const BUYMaxProductViewHeight = 640.0;
...
@@ -362,8 +282,39 @@ CGFloat const BUYMaxProductViewHeight = 640.0;
self
.
currencyFormatter
=
[[
NSNumberFormatter
alloc
]
init
];
self
.
currencyFormatter
=
[[
NSNumberFormatter
alloc
]
init
];
self
.
currencyFormatter
.
numberStyle
=
NSNumberFormatterCurrencyStyle
;
self
.
currencyFormatter
.
numberStyle
=
NSNumberFormatterCurrencyStyle
;
self
.
currencyFormatter
.
currencyCode
=
shop
.
currency
;
self
.
currencyFormatter
.
currencyCode
=
shop
.
currency
;
[
self
.
productView
.
productViewFooter
setApplePayAvailable
:
self
.
shouldShowApplePaySetup
requiresSetup
:
self
.
shouldShowApplePaySetup
];
}
[
self
.
productView
.
tableView
reloadSections
:[
NSIndexSet
indexSetWithIndex
:
0
]
withRowAnimation
:
UITableViewRowAnimationNone
];
-
(
void
)
createProductView
{
_productView
=
[[
ProductView
alloc
]
initWithFrame
:
CGRectMake
(
0
,
0
,
self
.
preferredContentSize
.
width
,
self
.
preferredContentSize
.
height
)
product
:
self
.
product
shouldShowApplePaySetup
:
self
.
shouldShowApplePaySetup
];
_productView
.
translatesAutoresizingMaskIntoConstraints
=
NO
;
[
self
.
view
addSubview
:
_productView
];
[
self
.
view
addConstraints
:[
NSLayoutConstraint
constraintsWithVisualFormat
:
@"V:|[_productView]|"
options
:
0
metrics
:
nil
views
:
NSDictionaryOfVariableBindings
(
_productView
)]];
[
self
.
view
addConstraints
:[
NSLayoutConstraint
constraintsWithVisualFormat
:
@"H:|[_productView]|"
options
:
0
metrics
:
nil
views
:
NSDictionaryOfVariableBindings
(
_productView
)]];
_productView
.
tableView
.
delegate
=
self
;
_productView
.
tableView
.
dataSource
=
self
;
[
_productView
.
productViewFooter
setApplePayAvailable
:
self
.
shouldShowApplePayButton
requiresSetup
:
self
.
shouldShowApplePaySetup
];
[
_productView
.
productViewFooter
.
paymentButton
addTarget
:
self
action
:
@selector
(
checkoutWithApplePay
)
forControlEvents
:
UIControlEventTouchUpInside
];
if
(
self
.
cart
)
{
[
_productView
.
productViewFooter
.
actionButton
setTitle
:
NSLocalizedString
(
@"Add to Cart"
,
nil
)
forState
:
UIControlStateNormal
];
[
_productView
.
productViewFooter
.
actionButton
addTarget
:
self
action
:
@selector
(
addSelectedVariantToCart
)
forControlEvents
:
UIControlEventTouchUpInside
];
}
else
{
[
_productView
.
productViewFooter
.
actionButton
setTitle
:
NSLocalizedString
(
@"Check Out"
,
nil
)
forState
:
UIControlStateNormal
];
[
_productView
.
productViewFooter
.
actionButton
addTarget
:
self
action
:
@selector
(
checkoutWithShopify
)
forControlEvents
:
UIControlEventTouchUpInside
];
}
_productView
.
productViewHeader
.
collectionView
.
delegate
=
self
;
_productView
.
productViewHeader
.
collectionView
.
dataSource
=
self
;
_productView
.
layoutMargins
=
UIEdgeInsetsMake
(
self
.
productView
.
layoutMargins
.
top
,
self
.
productView
.
layoutMargins
.
left
,
self
.
bottomLayoutGuide
.
length
,
self
.
productView
.
layoutMargins
.
right
);
[
_productView
.
productViewFooter
setApplePayAvailable
:
self
.
shouldShowApplePaySetup
requiresSetup
:
self
.
shouldShowApplePaySetup
];
[
_productView
.
tableView
reloadSections
:[
NSIndexSet
indexSetWithIndex
:
0
]
withRowAnimation
:
UITableViewRowAnimationNone
];
self
.
navigationItem
.
title
=
_product
.
title
;
[
self
setupNavigationBarAppearance
];
}
}
#pragma mark - Table view data source
#pragma mark - Table view data source
...
@@ -549,9 +500,9 @@ CGFloat const BUYMaxProductViewHeight = 640.0;
...
@@ -549,9 +500,9 @@ CGFloat const BUYMaxProductViewHeight = 640.0;
-
(
UIStatusBarStyle
)
preferredStatusBarStyle
-
(
UIStatusBarStyle
)
preferredStatusBarStyle
{
{
if
(
self
.
navigationController
.
navigationBar
.
barStyle
==
UIBarStyleBlack
||
([
self
navigationBarThresholdReached
]
==
NO
&&
self
.
isLoading
==
NO
&&
self
.
productView
.
productViewHeader
))
{
if
(
self
.
navigationController
.
navigationBar
.
barStyle
==
UIBarStyleBlack
||
([
self
navigationBarThresholdReached
]
==
NO
&&
self
.
productView
.
productViewHeader
))
{
return
UIStatusBarStyleLightContent
;
return
UIStatusBarStyleLightContent
;
}
else
if
(
self
.
isLoading
==
YES
&&
self
.
navigationController
.
navigationBar
.
barStyle
==
UIBarStyleBlack
&&
self
.
productView
.
productViewHeader
)
{
}
else
if
(
self
.
navigationController
.
navigationBar
.
barStyle
==
UIBarStyleBlack
&&
self
.
productView
.
productViewHeader
)
{
return
UIStatusBarStyleLightContent
;
return
UIStatusBarStyleLightContent
;
}
else
{
}
else
{
return
UIStatusBarStyleDefault
;
return
UIStatusBarStyleDefault
;
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment