A space to discuss online store customization, theme development, and Liquid templating.
Hello,
I have created the select list successfully using the checkout extension.
But when I change the option it is not changing on the front. please check:- https://d.pr/v/cUTzWM
It is happing because I use the applyCartLinesChange method inside the on-change method.
onChange: (value) => { const attributes = [ { key: DELIVERY_ATTRIBUTE, value: value } ]; applyCartLinesChange({ type: 'updateCartLine', id: target.current.lines[0].id, attributes: attributes }).then() },
Solved! Go to the solution
This is an accepted solution.
Hey, your code needs to reflect the updated value back onto the select component:
onChange: (value) => {
const attributes = [
{
key: "Store",
value: "pramod test",
},
];
applyCartLinesChange({
type: "updateCartLine",
id: target.current.lines[0].id,
attributes: attributes,
});
select.updateProps({ value }); // <-- this
},
To learn more visit the Shopify Help Center or the Community Blog.
import {extend, Select, Grid, View, GridItem, Text, Heading, Divider, BlockSpacer} from "@shopify/checkout-ui-extensions";
extend("Checkout::CartLineDetails::RenderAfter", (root, {target, applyCartLinesChange, appMetafields}) => {
const select = root.createComponent(Select, {
label: 'DeliveryType',
value: '1',
onChange: (value) => {
console.log(value);
const attributes = [
{
key: 'Store',
value: 'pramod test'
}
];
applyCartLinesChange({
type: 'updateCartLine',
id: target.current.lines[0].id,
attributes: attributes
}).then(console.log)
},
options: [
{
value: '1',
label: 'Pickup',
},
{
value: '2',
label: 'Ship',
},
],
});
root.appendChild(select);
});
full sample code
Hello Shopify team,
Again this issue occurs. any update on this?
This is an accepted solution.
Hey, your code needs to reflect the updated value back onto the select component:
onChange: (value) => {
const attributes = [
{
key: "Store",
value: "pramod test",
},
];
applyCartLinesChange({
type: "updateCartLine",
id: target.current.lines[0].id,
attributes: attributes,
});
select.updateProps({ value }); // <-- this
},
To learn more visit the Shopify Help Center or the Community Blog.
@mishareyzlin,
Thanks for the solution. its working perfectly.
Have one question, how can I find updated functions example like this.if possible can you please share documentation link to check updated examples for each component.
Hey, I’m glad to hear that the suggested fix worked for you!
@devPramod wrote:
@mishareyzlin,
Thanks for the solution. its working perfectly.
Have one question, how can I find updated functions example like this.if possible can you please share documentation link to check updated examples for each component.
At the moment, your best bet will be:
We are gradually improving our documentation, we have recently updated several sections of the Standard API docs (such as Storefront API access or client-side validation example and quite some more). We’ll hopefully soon cover the gap for pure JS based component API docs as well.
To learn more visit the Shopify Help Center or the Community Blog.