Range data type and e-commerce

Options

Hi

and thanks in advance for people that can help/

I'm coming from bubble and have an app that does the following :

as a user, i can search product, select a product and according to an input quantity i can get the price of the product.

On the back, i have a table with a data type "range" similar to :

product 1 : (0-50) : price = 10

product 1 : (51-100) : price = 8

product : (101-200) : price = 6

So when the user enter the quantity, i have a search and then the right price is displayed.

Question is : is this possible to create this kind of process on xano ?

Second question :

On the bubble app, i have 3 table :

project

project details

products


so people can use project details as a basket on ecommerce : (select one product, add qty, add it to the basket, ..) then create a whole project that includes each lines of project details


Same question, is this doable ? do you have any good ressources to share ?


many thanks

Tagged:

Best Answer

  • brian
    brian Administrator

    ADMIN

    Answer ✓
    Options

    Hey @alter345 we've created a Snippet you can use to solve for pricing based on quantity.


    The approach we took was similar to your data structure:

    TABLE: product

    • id
    • name

    TABLE: price

    • qty_low
    • qty_high
    • price

    We created two functions in this snippet:

    GET /product_price

    By providing as inputs the product_id and quantity, we search for the right price. If the quantity is larger than the highest qty_high in the price table, then we use the price for the highest qty_high for that product.

    GET /create_product

    This enables you to create a new product with as many price ranges based on quantity as you'd like. You use a JSON object to specify the qty_low and the price, then this function creates the price ranges for you.

    There's a thorough video walk-through on the post above, please do reply there with any questions, suggestions, or concerns. Thanks!

Answers

  • Chris Coleman
    Chris Coleman Administrator

    ADMIN

    Options

    Hey there! What you're describing is definitely possible in Xano. There is a question of database architecture here, or to put it more simply: how do we know the modification of the price based on quantity?

    Assuming that this is a standard multiplier, let's say that each product receives a 10% discount for every 10 items ordered. In Xano, you can use Conditional If/Then statements (located under Data Manipulation) to determine the final price.

    If quantity is greater than 10, price = (item price x 0.9) x quantity

    If quantity is greater than 20, price = (item price x 0.8) x quantity

    etc...


    For your second question, it sounds like this can be accomplished in Xano by having an Object field, which you can think of as a table within a table. This object can then contain a table reference to your Products table, and a field for quantity.

  • alter345
    Options

    Thank you Chris for your feedback

    thing is, its not a standard multiplier : attached you will find a screen of my product prices on bubble

    when user fill out the quantity input and the product, bubble is doing a search on this table according to the product selected, then send back the price (see quantity range)

    not sure data manipulation can this type of thing ?

    Ok for the second question, i ll try thanks





  • alter345
    alter345 Member
    edited December 2022
    Options

    One more thing : i have more than 400 product with different range et pricing, see attached to understand. Im not sure its doable on xano in fact

    thanks !


  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options

    Hey @alter345 the multiplier can be dynamic just like the price. Since it sounds like these are both stored in your database table, you would get this information from the table and use it for the calculation. And 400 products with different price ranges would definitely be doable 😊

  • alter345
    Options

    @Michael, thank your for your feedback, ill try this morning and let you know.

  • alter345
    Options

    All right thanks again for your help

    i created a table with the range and created the attached range that is looked up when querry record.

    last issue i got on this one is that now, i have an error, when running this "need a scalar value" which im not sure to understand, since im using decimal for the the different fields. My guess is that i am returning an object and cannot get the only value im interested in (the price according to the range)

    so i tried after reading your forum to use set or get and use ".prix" but does not work

    when im running this with an input that is not in the range, it works ...

    See attached details and thanks !


  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options

    There's a couple things to look out for here.

    First, when mapping your data to your total_ht field, you want to make sure you are mapping a single (scalar) value. I see you're pulling the variable from a Query ALL Records... It is likely that your return type is a list (even if it's a list of one). You can change this to "single" on the output tab under return.

    Secondly, you want to use dot notation or the GET filter to pull the prix field from the variable. SET would not be the correct filter to use in this case, at it sets a key-value pairing within an object.

  • alter345
    Options

    Thanks Michael, i got it using first / get

    I think im starting to see the potential of xano ;) I still need to work a bit more though

    thank s!


  • alter345
    Options

    Hi @brian thanks i ll take a look !