Problems with database query

Thanks for this tutorial @Teodor!

I am getting an error unfortunately on the db query part:
Undefined binding(s) detected when compiling SELECT. Undefined column(s): [products.id] query: select “id”, “product_name” as “title”, “product_sales_price” as “amount” from “products” where “products”.“id” in (?, ?, ?)

Here’s my query:
image

The ‘id’ used in flatten is correct, that’s the variable name of the data store’s product id field.

By the way, I got all these values stored in the data store too:

title (mandatory) - The name of the product
amount (mandatory) - The price of the product
currency (optional) - The currency. If not provided it defaults to usd
quantity (optional) - The quantity that should be added to the cart. If not provided, it defaults to 1

Can’t I just add those variables to the $_POST_LineItems array and send these values to the SC API directly instead of querying the products db table?

Thanks for your help in advance!

Share your server model please.

NodeJS with Postgres db.

In my tests it simply works with NodeJS and Postgres. Seeing the error it looks like the lineItems collection perhaps has an undefined entry. Disable the query step and output the expression you are using in the condition with a setValue step.

Hi @patrick,

I disabled the db query step, but which expression exactly should be output by the Set Value step? I don’t get it. Thanks for letting me know in advance.

The $_POST.lineItems.flatten('id') expression, I want to know what the exact value is that the query condition gets.

Okay, I see.
I did set that value now, but I don’t see the value in the developer’s console:

Well just disable the stripe steps and leave the setvalue so it can output the value …

Did disable the other steps already:
image

However still I don’t see the value in the console. This is all I get after cart_checkout runs:

Check the response from the server action not the console…

You can check the response in the network tab of devtools

Okay, sorry.

This is the response:

1. query_expression: [null]
  1. 0: null

It’s clearly empty, but why is a mystery to me.

My data store is in the layout file, not on the content page, could that be the cause?

This is without fatten of the collection by id:
image
So the missing id must be the issue.

There is an id stored in the data store however:
image

So for some reason it’s not passed to the LineItems array. Any idea why?

Did you update to the latest Wappler version? It includes an update for stripe because the initial version did filter out invalid lineItem properties and that is probably what is happening.

I’m on 3.9.2 :slight_smile:

Maybe removing and adding the Stripe element to the checkout page again will help?

You can try, otherwise delete the dmxAppConnect/dmxStripe folder and then save your page, it should copy then the latest files.

This fixed it!! :slight_smile:

Apparently my eagerness to implement this directly when Teodor published the tutorial while I was still on 3.9.1 was the reason it failed.

Thanks for your help both @Teodor and @patrick! :+1: