Removing productid from URL

Hi

I’m using routes to change urls to:

/productid/producttypeseo/productseo

to:

/34/tee-shirt/imperial-men-tee-shirt-190g-in-gold

this works fine but I’d like to remove the productid part.

The issue is that the landing page uses repeat regions tied to the productid so I’m struggling to get the page to load content by using e.g. productseo

The elements I need to load are:

dmx-repeat:repeatcolour="productdetails.data.productquery.colours">{{colourName}}

dmx-repeat:repeatgroup="productdetails.data.productquery.groups">{{groupName}}

dmx-repeat:repeatkeywords"productdetails.data.productquery.keywords">{{keywordName}}

Is there a way to achieve this without re-working productid to productseo in the main queries?

Thanks in advance

Justin

If the productid is used to filter your database queries, then if yo remove it from the url, the queries won't receive any filter value so they won't be filtered correctly.
You can remove productid from the url, but then you need to pass some other value to filter your queries and you need to edit them to setup the new value as a filter.

Yes, this is the issue, I am using productid for the other nested repeats on that page from 3 other tables so the productid might have to stay unless I can work something else out.

if I swap the query to match productseo, this will bring the page up but it will break the groupName, keywordName and colourName as those tables only have a shared productID.

Is there a way to create a separate query that links them together?

I’m working with an existing DB

Here’s the message:

  1. message: "SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND `productID` in (?)) ORDER BY `groupName` ASC' at line 1"

  2. trace: "#0 /home/bcgmv2025/public_html/dmxConnectLib/lib/db/Connection.php(163): PDO->prepare()\n#1 /home/bcgmv2025/public_html/dmxConnectLib/modules/dbconnector.php(649): lib\\db\\Connection->execute()\n#2 /home/bcgmv2025/public_html/dmxConnectLib/modules/dbconnector.php(277): modules\\dbconnector->processSubQueries()\n#3 /home/bcgmv2025/public_html/dmxConnectLib/lib/App.php(242): modules\\dbconnector->single()\n#4 /home/bcgmv2025/public_html/dmxConnectLib/lib/App.php(213): lib\\App->execSteps()\n#5 /home/bcgmv2025/public_html/dmxConnectLib/lib/App.php(181): lib\\App->execSteps()\n#6 /home/bcgmv2025/public_html/dmxConnectLib/lib/App.php(170): lib\\App->exec()\n#7 /home/bcgmv2025/public_html/dmxConnectLib/lib/App.php(131): lib\\App->exec()\n#8 /home/bcgmv2025/public_html/dmxConnect/api/details.php(7): lib\\App->define()\n#9 {main}"

You’ll need something that’s unique to the record in there whether it’s the ID or something else.

Yes, I have unique items to use but the issue is with the nested tables.

The only common element between 4 tables is productid

I need to link productid with productseo somehow

If you only need it for a single product then first do a query on the main product table and then in a second step query the subtable using the id retrieved in the first query.

That’s what I’m aiming to do but the productid is the only thing that references in the sub-tables so I cant use the e.g. productseo reference for those

Can you not create a view that collates all the necessary columns in to a single query?

Hi all, thanks for your comments and ideas:

Just to clarify, I’m working with an existing DB

Tables as follows:

  • Products - contains all the information about the products + SEO name
  • Colours - uses productid to link to products - Foreign key
  • Groups - Uses productid - Foreign key
  • Keywords - uses productid - Foreign key

Queries

I have 4 queries on the page:

  • to pull in the single product details via the productid (single)
  • for the list of colours only contains the colour name and productid (multiple)
  • for the list of groups only contains the group name and productid (multiple)
  • for the list of keywords only contains the keywords name and the productid (multiple)

Is the suggestion that I create a new query just for the url? - I’m not sure how to do that :slight_smile:

Thanks again for your help

Justin

You don’t need to handle this on the page - it's better to do it server-side.

Filter your initial query using the producttypeseo URL parameter (assuming it’s unique). Then, use the returned productid from that query to filter the remaining queries on the server.

Finally, output the results on the page without applying any additional filters, since the data is already filtered server-side.

1 Like

Could you show the query as you had it where you get the error. It should also work with a single query where you have them as sub tables. Make sure to include the productID in the output of the query.

Solved. I started building the page queries again and took it down to a single query.

The issue was that I had my main filter set (changed to productseo), this worked of course.

Then, the issue was that I also had filters set for the e.g. colours table using the productid of the product table which caused a 500 error.

The solution was (probably obvious to more experience Wapplers), was to completely remove the filter for e.g. colours table as it couldnt find product id.

This now ran with success.

I then adjusted the nested repeats accordingly and it worked.

Big lesson for me, I thought that I needed to keep adding queries when it could all be done in one query.

Thank you to everyone that helped.

Justin

1 Like