Product Reference

Good morning all,
I am looking for a way to connect the data from my “results” text element with a product from my Wix Store.

I created a VIN decoder on my page, which allows the user to enter their vehicles VIN #, and in return, the year, make and model of the vehicle is shown. What I would like to do is have the corresponding battery, from my Wix Store, show underneath the “results” text element so the user can easily see what battery fits their vehicle and give the option for them to add that product to their cart. I have been trying to figure this out for over a week now and am at my wits end. ANY suggestions are appreciated!

Here is my code:


import {getVINInfo} from 'backend/VINModule';
import wixData from 'wix-data';

$w.onReady(function () {
 //TO DO: Write Your Page Related Code Here:
 

}); 

export function button1_click (event, $w) {
 //Add your code for this event here:
    getVINInfo($w("#vininput").value)
        .then(VINInfo => {
            console.log(VINInfo)
                 $w("#results").text = VINInfo.Results[8].Value + "  " + VINInfo.Results[5].Value + "  " + VINInfo.Results[7].Value + "  " + "  " + VINInfo.Results[47].Value; 
 let results = $w("#results").text
                         wixData.filter("batteryfitment")
                            .eq("Year" + "Make" + "Model" + "Cylinders" + "Engine")
                            .find()
                            .then( (response) => {
 if(response > 0) {
 let battery = response.battery;
                                }
                                }) 
                            })
 
 
}


Kind Regards,
Brittani

Hi Brittani,

You have a challenging task here. I have a few questions and comments:

  • It sounds like there is no problem with the VIN decoder returning reliable results. Is that correct?

  • You say you want ‘to connect the data from my “results” text element with a product from my Wix Store’, but you are attempting to filter one of your collections called “batteryfitment”. You will need to link batteryfitment to the stores product collection somehow, preferabley via ID, to be able to show the corresponding battery from your Wix Store.

  • The filter statement, as constructed, will not work. The first argument should be a field name (field key) from the batteryfitment collection. However, that’s a secondary matter. According to the documentation on the filter command , the VIN decoder results are not “filterable” anyway using the filter command. It can only be used on a dataset.
    It would be good for you to show a screen shot of console.log(VINInfo) after clicking on the three dot button, so we can see how the results are constructed. Also, a screen shot showing the key fields in the batteryfitment collection would be helpful.

1 Like

@tony-brunsman Thank you so much for your feedback. Please see below for the requested screenshots :slight_smile:

Good afternoon Anthony and thank you for your response. I have attached the requested screenshots (see above). I am still unsure of what I am doing wrong and would appreciate any feedback given.

Thank you in advance,
Brittani

@tsuyoidesigns It helps to see these screen shots, but it also raises some questions and comments:

  • In the batteryfitment collection what is the battery field referencing? I see the “Group Size” values. It seems like you have to be storing that in the only other custom collection named “Products”.

  • Does the data in the VINInfo array make sense to you? Value is the make obviously, but is ValueId the model? Is there enough information in the array item to be able to identify the appropriate battery.

  • Ultimately, you will need to establish a connection between the Wix Stores products collection and your custom collection named “Products” either by storing the Wix Stores product ID in one of your collections or via reference.

@tony-brunsman
Thank you for your response. In the batteryfitment collection, the battery field references the products from my Wix store. The “group size” values are the actual products.

The data in the VINInfo array makes perfect sense, it returns the year, make and model of the vehicle from the VIN# inserted in the user input field.

How would I go about storing the Wix Stores products ID collection to my collections? I assumed referencing the products in the batteryfitment collection would solve my issue but I am at my wits end with this lol. Any feedback is greatly appreciated!

I am still not able to solve my code. Is anyone able to assist?