VirtueMart Forum

VirtueMart 2 + 3 + 4 => Product creation => Topic started by: Dimi on December 17, 2018, 14:55:59 PM

Title: Automatically generate product name from custom fields
Post by: Dimi on December 17, 2018, 14:55:59 PM
Hello,
We are developing an eshop with cars and each product has a few custom fields (Brand, Modal, Year etc). The clients wants to add the custom fields to each product and the product name to be automatically generated by these fields.

I've found the product.php file in administrator -> components -> com_virtuemart -> controlers
and tried to change the value in line 59 like this:
$data['product_name'] = vRequest::get('field');
or
$data['product_name'] = $data['field']

When I make one of these changes, the product name becomes 'Array'. I suppose I have to get the array values and echo them in the $data['product_name'] but I don't know how.

Any help would be much appreciated.
Thank you.
Title: Re: Automatically generate product name from custom fields
Post by: PRO on December 18, 2018, 00:28:57 AM
This is best done with a plugin.

1st Way
Have all 3 (Brand, Modal, Year etc)   as parameters.
Then, use javascript to fill in product name on backend.

Inside the function    plgVmOnProductEdit  , just add the jQuery

With this way you have to be in the backend and manually save.

2nd Way
If you want to be able to upload products, csv etc.
Have all 3 (Brand, Modal, Year etc)   as product plugin parameters.
Then, you can change the name on the frontend via the parameters.




Title: Re: Automatically generate product name from custom fields
Post by: Studio 42 on December 18, 2018, 01:24:16 AM
Why not dynamic change the name in the front-end.
The brand is mf_name, the year can be an existing date field
Modal ? you mean model ?
A problem is if you use customfields to set name, first time using Brand Modal Year, the name is for eg
Fordt fiesta 1990
On save again
Fordt fiesta 1990 Fordt fiesta 1990
On save again
Fordt fiesta 1990 Fordt fiesta 1990 Fordt fiesta 1990
...
So this solution is not suitable for your needs