Solved

POS App Bridge - applyCartDiscount stopped working 4/18/24

wriffle
Excursionist
12 2 3

Hi everyone,

 

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

});

Accepted Solution (1)

wriffle
Excursionist
12 2 3

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.

View solution in original post

Reply 1 (1)

wriffle
Excursionist
12 2 3

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.