Database query help please

Open to all! Ask other shopowners for help.
bestmate
Member
Posts: 27
Joined: Wed Mar 08, 2023 1:23 am
Phoenix Version:
Has thanked: 22 times
Been thanked: 4 times

Database query help please

Post by bestmate »

Please can someone guide me how to query the database products_options_values table to get the product_options_values_name using product_options_values_id value?

Thank you.


Join The Code Co-op to get access to your library in the Code Co-op Forum
User avatar
Kofod95
Senior Contributor
Posts: 748
Joined: Sat Feb 06, 2021 7:38 pm
Phoenix Version: 1.0.8.20
Has thanked: 99 times
Been thanked: 179 times

Re: Database query help please

Post by Kofod95 »

I would think something like

Code: Select all

SELECT products_options_values_name FROM products_options_values WHERE products_options_values_id = " . (int)$the_id_you_want_the_name_for . " AND language_id = " . (int)$_SESSION['languages_id']
Would do it. I don't remember whether the language_id is fetched differently in catalog compared to admin, but if memory serves, the above goes for admin at least.

//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
bestmate
Member
Posts: 27
Joined: Wed Mar 08, 2023 1:23 am
Phoenix Version:
Has thanked: 22 times
Been thanked: 4 times

Re: Database query help please

Post by bestmate »

Thanks very much @Kofod95 , very much appreciated.

Another question if I may. How can I pass a selectbox value/option to it using a link?
User avatar
Kofod95
Senior Contributor
Posts: 748
Joined: Sat Feb 06, 2021 7:38 pm
Phoenix Version: 1.0.8.20
Has thanked: 99 times
Been thanked: 179 times

Re: Database query help please

Post by Kofod95 »

I'm am a little unsure about what it is you want to do, but if you just want the ability to create links that will show the name of the option_value, you could populate the variable in the above query like

Code: Select all

$the_id_you_want_the_name_for = $_GET['attribute_value_id'];
and create the link like

Code: Select all

$Linker->build(page.php, ['attribute_value_id' => $the_value]);
You may need to use $GLOBALS['Linker']->build(...
$Admin->link(...
Or $GLOBALS['Admin']->link(...
depending on the context.
Also, I may be misremembering, but you could look at any nearby link in core to check for the correct syntax :)

//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
bestmate
Member
Posts: 27
Joined: Wed Mar 08, 2023 1:23 am
Phoenix Version:
Has thanked: 22 times
Been thanked: 4 times

Re: Database query help please

Post by bestmate »

Thank you again Daniel.

What I want to do is set a selectbox value using a link or JavaScript instead of clicking the selectbox. For example:

<script type="text/javascript">
$(document).ready(()=>{
$("#input_5") option[value=8]").attr('selected', 'selected');
});
</script>

Perhaps this can be done a better way or using a URL to set the value?
User avatar
Kofod95
Senior Contributor
Posts: 748
Joined: Sat Feb 06, 2021 7:38 pm
Phoenix Version: 1.0.8.20
Has thanked: 99 times
Been thanked: 179 times

Re: Database query help please

Post by Kofod95 »

For product_info or somewhere else?
Is it the same option you want to be preselected, or do you want the power to have different options preselected in different circumstances?
My approach to it would vary based on the outcome wanted :)

//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
bestmate
Member
Posts: 27
Joined: Wed Mar 08, 2023 1:23 am
Phoenix Version:
Has thanked: 22 times
Been thanked: 4 times

Re: Database query help please

Post by bestmate »

Thank you @Kofod95

Yes, this is for product_info and a different value will be passed to the selectbox each time. How would you go about this. Is using PHP an option or just JavaScript?
User avatar
burt
Core Team
Posts: 4560
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 413 times

Re: Database query help please

Post by burt »

EG: product_info.php?products_id=4%7B1%7D2

In a new install, gets you to the product_info page for "Shiny Red Apples", with the "Box Size" of "24" pre-selected.

This piece: %7B1 is the Option (here is option "1"), and this piece is the Attribute %7D2 (here is attribute "2"). If you have multiple Options, then the URL would end up longer, something like this;

product_info.php?products_id=4%7B1%7D2%7B2%7D4

Which says product_info page for "Shiny Red Apples", with the "Box Size" [%7B1] of "24" [%7D2] pre-selected and "another option" [%7B2] of "whatever" %7D4 selected.

You can see this in action, by performing the following;

1. Go to the product info page of any product with selectable option(s).
2. Select options and Add To Cart.
3. From the Cart page, click the LINK back to the product. This link would look something like the URLS above.
4. Scroll down and see that the options are pre-selected.

Now you need to think how to use this piece of core functionality to do what you need to do.
I am not here to build for you.
I am here to build with you. Let's help each other.
User avatar
Kofod95
Senior Contributor
Posts: 748
Joined: Sat Feb 06, 2021 7:38 pm
Phoenix Version: 1.0.8.20
Has thanked: 99 times
Been thanked: 179 times

Re: Database query help please

Post by Kofod95 »

@burt's answer shows the reason I asked what you wanted - core is able to preselect attributes from link-parameters, so no need to re-invent the wheel ;)

//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
bestmate
Member
Posts: 27
Joined: Wed Mar 08, 2023 1:23 am
Phoenix Version:
Has thanked: 22 times
Been thanked: 4 times

Re: Database query help please

Post by bestmate »

Hello @burt . Thanks so much for this guide. I followed the steps you outlined and it works only if a product is already in the cart and you want to click back to it.

In my case, I want to make the selection before adding item to the cart. For example:

product_info.php?products_id=781{2}8{3}4

The above will not work if I just pass it in the URL if it's not already in my cart.


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply