Moving the datastore from the layout to the content fixes using this on the click:
dmx-on:click="cart.upsert({sku: 'my_cool_product'},{qty: `qty + inp_qty.value.toNumber()`, sku: 'my_cool_product', product_name: 'My Cool Product'})"
Moving the datastore from the layout to the content fixes using this on the click:
dmx-on:click="cart.upsert({sku: 'my_cool_product'},{qty: `qty + inp_qty.value.toNumber()`, sku: 'my_cool_product', product_name: 'My Cool Product'})"
Ok, then it is indeed an issue with the data scope, the expression between the backticks is being evaluated later within the datastore component and the path to the input is then different.
Did you ever come up with a resolution of this, moving to content page in node is not ideal and it can’t work with PHP. This is a pretty big issue for a shopping cart
BUMP, this is a big issue on PHP, we cant use datastore with a checkout if you want to have a variable quantity, is there any solution in the pipeline?
BUMP, working in a checkout php project too.
The scope issue is difficult to change and we could argue a lot about which solution is the best. There is a simple workaround by first storing the value in a global variable. The global variable is accessibel from any scope, just make sure you use some unique name.
dmx.global.set('upsertQty', inp_qty.value.toNumber());cart.upsert({sku: 'my_cool_product'},{qty: `qty + upsertQty`, sku: 'my_cool_product', product_name: 'My Cool Product'})