All things Shopify and commerce
Hi everyone,
This is a duplicate that posted to Shopify Apps - Not sure where the best place to put it may be.
We were able to apply cart discounts to the POS cart through our app up through yesterday. Now, that same function (which is unchanged on our end) just hangs and never completes the promise.
Does anyone else see this?
Here is a snippet of the code (sorry for the loss of indentation):
// Set cart discount function
setCartDiscount = async function (discount, cb=null) {
const r = await shopify.pos.cart.applyCartDiscount(discount);
if (typeof(cb) === 'function') {
cb(r);
} else {
return r;
}
};
// After logic determining if they are eligible, this code is called
Promise.all(
[
setCartDiscount({
title : 'Free Drink Claimed',
type : 'FixedAmount',
amount : 4.50
}),
otherFunctionsOmitted({
// Omitted
})
]
)
.then(() => {
// Omitted
});
Solved! Go to the solution
This is an accepted solution.
In case anyone else runs into this issue, I discovered the underlying problem. Basically, the AppBridge JS library changed (without entry in either the change log nor docs) from taking an object:
await applyCartDiscount({
type : 'FixedAmount',
title : 'Whatever you want it to be',
amount : 5.00
});
to having to pass the parameters in separately:
await applyCartDiscount('FixedAmount', 'Whatever you want it to be', 5.00);
Of course, this is not what the documentation says (https://shopify.dev/docs/api/app-bridge-library/apis/pos#cart-propertydetail-applycartdiscount) , nor what their examples show (https://shopify.dev/docs/api/app-bridge-library/apis/pos#example-cart).
To reiterate, the object-based code worked for a long time. Then, on 4/18/24, it suddenly stopped working. Obviously Shopify made a change and didn't put it in the change log, nor update their docs. Not that I am in any way surprised.
This is an accepted solution.
In case anyone else runs into this issue, I discovered the underlying problem. Basically, the AppBridge JS library changed (without entry in either the change log nor docs) from taking an object:
await applyCartDiscount({
type : 'FixedAmount',
title : 'Whatever you want it to be',
amount : 5.00
});
to having to pass the parameters in separately:
await applyCartDiscount('FixedAmount', 'Whatever you want it to be', 5.00);
Of course, this is not what the documentation says (https://shopify.dev/docs/api/app-bridge-library/apis/pos#cart-propertydetail-applycartdiscount) , nor what their examples show (https://shopify.dev/docs/api/app-bridge-library/apis/pos#example-cart).
To reiterate, the object-based code worked for a long time. Then, on 4/18/24, it suddenly stopped working. Obviously Shopify made a change and didn't put it in the change log, nor update their docs. Not that I am in any way surprised.
Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024The Hydrogen Visual Editor is now available to merchants in Shopify Editions | Summer '...
By JasonH Sep 2, 2024Note: Customizing your CSS requires some familiarity with CSS and HTML. Before you cust...
By JasonH Aug 12, 2024