-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create settings option to test vaulted state with dummy data
- Loading branch information
1 parent
bed3e67
commit f8c7ff5
Showing
4 changed files
with
106 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
Samples/MobileBuyIntegration/MobileBuyIntegration/AppConfiguration.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
MIT License | ||
|
||
Copyright 2023 - Present, Shopify Inc. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
import ShopifyCheckout | ||
|
||
public struct AppConfiguration { | ||
public var testVaultedState: Bool = false | ||
} | ||
|
||
public var appConfiguration = AppConfiguration() { | ||
didSet { | ||
CartManager.shared.resetCart() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,10 +92,7 @@ class CartManager { | |
} | ||
|
||
private func performCartCreate(items: [GraphQL.ID] = [], handler: @escaping CartResultHandler) { | ||
let input = Storefront.CartInput.create( | ||
lines: Input(orNull: items.map({ Storefront.CartLineInput.create(merchandiseId: $0) })) | ||
) | ||
|
||
let input = (appConfiguration.testVaultedState) ? vaultedStateCart(items) : defaultCart(items) | ||
let mutation = Storefront.buildMutation { $0 | ||
.cartCreate(input: input) { $0 | ||
.cart { $0.cartManagerFragment() } | ||
|
@@ -110,6 +107,37 @@ class CartManager { | |
} | ||
} | ||
} | ||
|
||
private func defaultCart(_ items: [GraphQL.ID]) -> Storefront.CartInput { | ||
return Storefront.CartInput.create( | ||
lines: Input(orNull: items.map({ Storefront.CartLineInput.create(merchandiseId: $0) })) | ||
) | ||
} | ||
|
||
private func vaultedStateCart(_ items: [GraphQL.ID] = []) -> Storefront.CartInput { | ||
let deliveryAddress = Storefront.MailingAddressInput.create( | ||
address1: Input(orNull: "1st Street Southeast"), | ||
address2: Input(orNull: ""), | ||
city: Input(orNull: "Cagalry"), | ||
company: Input(orNull: ""), | ||
country: Input(orNull: "CA"), | ||
firstName: Input(orNull: "Test"), | ||
lastName: Input(orNull: "McTest"), | ||
phone: Input(orNull: ""), | ||
province: Input(orNull: "AB"), | ||
zip: Input(orNull: "T1X 0L3")) | ||
|
||
let deliveryAddressPreferences = [Storefront.DeliveryAddressInput.create(deliveryAddress: Input(orNull: deliveryAddress))] | ||
|
||
return Storefront.CartInput.create( | ||
attributes: Input(orNull: [Storefront.AttributeInput(key: "isBuyWithPrimeIntent", value: "true")]), | ||
lines: Input(orNull: items.map({ Storefront.CartLineInput.create(merchandiseId: $0) })), | ||
buyerIdentity: Input(orNull: Storefront.CartBuyerIdentityInput.create( | ||
email: Input(orNull: "[email protected]"), | ||
deliveryAddressPreferences: Input(orNull: deliveryAddressPreferences) | ||
)) | ||
) | ||
} | ||
} | ||
|
||
extension Storefront.CartQuery { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters