How to pass email and address to checkout?
Opened this issue · 1 comments
julianCast commented
var client = ShopifyBuy.buildClient({
domain: 'myshop.myshopify.com',
storefrontAccessToken: '12345'
})
As you can see below, client.checkout contains updateEmail and updateShippingAddress.
How can I get checkoutId so I can use those functions or there is an easier function to do this ? Thanks!
If I hardcoded use the checkout.id, no changes are shown in the checkout.
client.checkout.updateEmail(checkoutId, 'test@gmail.com').then(c => {
console.log(c) // This is shown in the console but the email won't change
})
julianCast commented
I think the library (buy-button.js) is not prepared to allow an update, so this is my workaround.
MY COMPONENT
const cart = UIShopify.components.cart[0]
cart.updater.updateConfig({
options: {
email:email
shippingAddress: shippingAddress
}
})
buy-button.js BEFORE FIX
_proto.onCheckout = function onCheckout() {
this._userEvent('openCheckout');
this.props.tracker.track('Open cart checkout', {});
this.checkout.open(this.model.webUrl);
}
buy-button.js AFTER FIX
_proto.onCheckout = function onCheckout()
{
this._userEvent('openCheckout');
this.props.tracker.track('Open cart checkout', {});
let items = this.lineItemCache.map(i => { return { variantId: i.variant.id, quantity: i.quantity } });
var input = {
lineItems: items,
shippingAddress: this.config.shippingAddress,
email: this.config.email
}
var checkoutWindow = window.open('', 'checkout', this.checkout.params);
this.props.client.checkout.create(input).then(function (checkout)
{
checkoutWindow.location = checkout.webUrl;
});
}