Skip to main content
Topic: Generate Reference (Read 1196 times) previous topic - next topic

Generate Reference

Hello guys,

Maybe someone could give me a little help.

I've this tables

category
id_category
name
code_category

subcategory
id_subcategory
id_category
name
code_subcategory

product
id_product
id_category
id_subcategory
name
code_product


When I'm creating a new product, what I do is that I select a category, then a subcategory (filtered from categories), then give it a name.

What I'd like to do is to have an autogenerated product code with like this (category code + subcategory code + autoincrement number), them pass it to the database

Any Idea about how to achieve this?

Many thanks

Re: Generate Reference

Reply #1
@xela05‍ please use the action before add to write the code for generating your code and pass the value to $modeldata['fieldname']. E.g

Code: [Select]
$modeldata['code_product'] = "GRD001";

 

Re: Generate Reference

Reply #2
Thanks for the answer, my problem is, how do I retrieve the category and subcategory code that I selected on the dropdown?

Re: Generate Reference

Reply #3
@xela05‍ by doing a query for category and subcategory using the id_category and id_subcategory to get category and subcategory code.
Note: There are code snippets in the Page Events configuration you can modify and use.