Author Topic: Automatically generate product name from custom fields  (Read 363 times)

Δήμητρα Ροδοστόγλου

  • Beginner
  • *
  • Posts: 5
  • A beginner
Automatically generate product name from custom fields
« 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.

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10330
  • VirtueMart Version: 3+
Re: Automatically generate product name from custom fields
« Reply #1 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.




J3.9+ VM 3.4.2
Slowest Page Speed Score (88) (Category)
Fastest Page Speed Score (94-96) (productdetails)

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 3840
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: Automatically generate product name from custom fields
« Reply #2 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