Review the upsell extension and make the call.
import '@shopify/ui-extensions/preact';
import {render} from 'preact';
import {useState} from 'preact/hooks';
export default function extension() {
render(<Upsell />, document.body);
}
function Upsell() {
const [added, setAdded] = useState(false);
async function addSampler() {
await shopify.applyCartLinesChange({
type: 'addCartLine',
merchandiseId: 'gid://shopify/ProductVariant/44519280869629',
quantity: 1,
});
setAdded(true);
}
return (
<s-section heading="Last chance: the Single-Origin Sampler">
<s-stack gap="base">
<s-text>Add three 100g single origins to this order for $18.</s-text>
{added ? (
<s-badge tone="neutral">Added to your order</s-badge>
) : (
<s-button onClick={addSampler}>Add the sampler</s-button>
)}
</s-stack>
</s-section>
);
}